/**
 * Copyright (C) 2026 Ralf Burger
 * ralf@RalfBurger.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

#include "pid_registry.h"

// -- Skalierungstabelle ----------------------------------------
// 0 = x1   (ganzzahlig, grosser Bereich: RPM, km, min)
// 1 = x10  (1 Dezimalstelle: Temp, kPa)
// 2 = x100 (2 Dezimalstellen: Volt, %, Lambda)
// Kodierung Sender:   int16 = (float x Faktor)
// Dekodierung Empf.:  float = int16 / Faktor
const uint8_t PID_SCALE[MAX_PIDS] = {
  // 0:RPM  1:Speed  2:Temp  3:IAT  4:MAP  5:Load  6:TPS  7:Cap
     0,     0,       1,      1,     1,     2,      2,     0,
  // 8:Tank  9:Verbr  10:MAF  11:Baro  12:AbsTPS  13:RelTPS  14:Gas  15:Schub
     2,      2,       2,      1,       2,          2,         2,      2,
  // 16:Cap20  17:Cap40
     0,        0,
  // 18:O2v  19:O2v  20:O2v  21:O2v  22:O2wb  23:O2wb  24:Lambda  25:UmbL
     2,      2,      2,      2,      2,       2,       2,          1,
  // 26:Kruem  27:Zuend  28:ECUvolt  29:Oeltemp  30:Einsprdruck  31:KWT2
     1,        1,        2,          1,           2,              1,
  // 32:Cap60  33:MIL  34:DistMIL  35:Warm  36:DistReset  37:ZeitMIL  38:ZeitReset
     0,        0,      0,          0,       0,            0,           0,
  // 39:Typ  40:VIN  41:Kalib  42:ECUname  43..47: reserviert
     0,      0,      0,        0,          0, 0, 0, 0, 0
};

// -- PID-Metadaten ---------------------------------------------
// Index muss identisch zu PidIdx-Enum sein!
const PidInfo PID_INFO[MAX_PIDS] = {
  /* 0  PID_RPM            */ {"010C", "RPM",              "1/min", 0},
  /* 1  PID_SPEED          */ {"010D", "Speed",            "km/h",  0},
  /* 2  PID_TEMP           */ {"0105", "Kuehlmittel",      "C",     0},
  /* 3  PID_IAT            */ {"010F", "Ansaugluft",       "C",     0},
  /* 4  PID_MAP            */ {"010B", "MAP",              "kPa",   0},
  /* 5  PID_LOAD           */ {"0104", "Motorlast",        "%",     1},
  /* 6  PID_TPS            */ {"0111", "TPS",              "%",     1},
  /* 7  PID_CAP00          */ {"0100", "Cap00",            "",      0},
  /* 8  PID_TANK           */ {"012F", "Tankfuellstand",   "%",     1},
  /* 9  PID_VERBRAUCH      */ {"015E", "Verbrauch",        "L/h",   2},
  /* 10 PID_MAF            */ {"0110", "MAF",              "g/s",   2},
  /* 11 PID_BARO           */ {"0133", "Baro",             "kPa",   0},
  /* 12 PID_ABSTPS         */ {"0143", "AbsTPS",           "%",     1},
  /* 13 PID_RELTPS         */ {"0145", "RelTPS",           "%",     1},
  /* 14 PID_GASPEDAL       */ {"0149", "Gaspedal",         "%",     1},
  /* 15 PID_SCHUBVENTIL    */ {"014C", "Schubventil",      "%",     1},
  /* 16 PID_CAP20          */ {"0120", "Cap20",            "",      0},
  /* 17 PID_CAP40          */ {"0140", "Cap40",            "",      0},
  /* 18 PID_O2_B1S1_V      */ {"0114", "O2_B1S1_V",        "V",    3},
  /* 19 PID_O2_B1S2_V      */ {"0115", "O2_B1S2_V",        "V",    3},
  /* 20 PID_O2_B1S3_V      */ {"0116", "O2_B1S3_V",        "V",    3},
  /* 21 PID_O2_B1S4_V      */ {"0117", "O2_B1S4_V",        "V",    3},
  /* 22 PID_O2_B1S1_WB     */ {"0124", "O2_B1S1_WB",       "lam",  3},
  /* 23 PID_O2_B1S2_WB     */ {"0125", "O2_B1S2_WB",       "lam",  3},
  /* 24 PID_LAMBDA         */ {"0144", "Lambda",           "lam",   3},
  /* 25 PID_UMGEBUNGSLUFT  */ {"0146", "Umgebungsluft",    "C",     0},
  /* 26 PID_KRUEMMERDRUCK  */ {"014B", "Kruemmerdruck",    "kPa",   0},
  /* 27 PID_ZUENDWINKEL    */ {"010E", "Zuendwinkel",      "KW",    1},
  /* 28 PID_ECU_SPANNUNG   */ {"0142", "ECU_Spannung",     "V",     2},
  /* 29 PID_OELTEMP        */ {"015C", "Oeltemp",          "C",     0},
  /* 30 PID_EINSPRITZDRUCK */ {"015D", "Einspritzdruck",   "kPa",   1},
  /* 31 PID_KUEHLMITTEL2   */ {"0167", "Kuehlmittel2",     "C",     1},
  /* 32 PID_CAP60          */ {"0160", "Cap60",            "",      0},
  /* 33 PID_MIL_STATUS     */ {"0101", "MIL_Status",       "",      0},
  /* 34 PID_DIST_MIL       */ {"0121", "Dist_MIL_an",      "km",    0},
  /* 35 PID_WARMLAUF       */ {"0130", "Warmlaufzyklen",   "",      0},
  /* 36 PID_DIST_RESET     */ {"0131", "Dist_Reset",       "km",    0},
  /* 37 PID_ZEIT_MIL       */ {"014D", "Zeit_MIL_an",      "min",   0},
  /* 38 PID_ZEIT_RESET     */ {"014E", "Zeit_Reset",       "min",   0},
  /* 39 PID_KRAFTSTOFFTYP  */ {"0151", "Kraftstofftyp",   "",      0},
  /* 40 PID_VIN            */ {"0902", "VIN",              "",      0},
  /* 41 PID_KALIBID        */ {"0904", "KalibID",          "",      0},
  /* 42 PID_ECU_NAME       */ {"090A", "ECU_Name",         "",      0},
  /* 43..47 reserviert     */ {"","","",0}, {"","","",0}, {"","","",0},
                              {"","","",0}, {"","","",0},
};

const int PID_INFO_COUNT = PID_COUNT_USED;
