/***************************************************************************

  BionxControl
  Copyright © 2025 christoph holzheuer
  christoph.holzheuer@gmail.com

  Using:

  mhs_can_drv.c
  © 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany
  Klaus Demlehner, klaus@mhs-elektronik.de
  @see www.mhs-elektronik.de

  Based on Bionx data type descriptions from:

  BigXionFlasher USB V 0.2.4 rev. 97
  © 2011-2013 by Thomas Koenig <info@bigxionflasher.org>
  @see www.bigxionflasher.org

  Bionx Bike Info
  © 2018 Thorsten Schmidt (tschmidt@ts-soft.de)
  @see www.ts-soft.de

  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.
  @see https://github.com/bikemike/bionx-bikeinfo

 ***************************************************************************/


#ifndef BC_H
#define BC_H

#include <cstdint>
#include <QDebug>
#include <QObject> // Nötig für Q_GADGET/Q_ENUM Makros

//uint8_t;


/**
 * @brief Simple exception  class
 */

class BCException : public std::runtime_error
{

public:

  BCException( const QString& what, const QString& param="" );
  BCException( const QString& what, int errCode );

  // das ist unsinn: exception werden nicht zwangsläufig im
  // gui thread gefangen, das popup kann aber nur dort
  // angezeigt werden.
  //void popup() const;
};

namespace bc
{
  [[maybe_unused]] constexpr static double UNLIMITED_SPEED_VALUE                                    = 70; // Km/h
  //  UNLIMITED_MIN_SPEED_VALUE                                = 30; // Km/h
  [[maybe_unused]] constexpr static double UNLIMITED_THROTTLE_SPEED_VALUE                           = 70; // Km/h

  [[maybe_unused]] constexpr static double SPEED_FACTOR                                             = 0.1;
  [[maybe_unused]] constexpr static double DISTANCE_FACTOR                                          = 0.1;
  [[maybe_unused]] constexpr static double SENESORGAIN_FACTOR                                       = 0.1;
  [[maybe_unused]] constexpr static double ASSIST_FACTOR                                            = 1.5625;
  [[maybe_unused]] constexpr static double VOLTAGE_FACTOR                                           = 0.001;
  [[maybe_unused]] constexpr static double CURRENT_FACTOR                                           = 0.001;
  [[maybe_unused]] constexpr static double NORMALIZED_VOLTAGE_OFFSET                                = 20.8333;
  [[maybe_unused]] constexpr static double NORMALIZED_VOLTAGE_FAKTOR                                = 0.416667;

  // misc
  //#define cbc::Version "CanBusControl 0.0.01 / 02.07.2022"
  [[maybe_unused]] constexpr static const char* Version    = "BionxControl 0.1.00 / 08.11.2022 © 2022 chris@sourceworx.org";

  [[maybe_unused]] constexpr static const char* OrgName    = "source::worx";
  [[maybe_unused]] constexpr static const char* DomainName = "sourceworx.org";
  [[maybe_unused]] constexpr static const char* AppName    = "BionxControl";


  // timer
  void delay_seconds( uint32_t );
  void delay_millis( uint32_t );
  void delay_micros( uint32_t );
  void processEventsFor(int milliseconds);

  QString formatInt( int count, int len );
} // namespace bc

// abbreviations:
//   SOC = State Of Charge
//   LMD = Last Measured Discharge
//   NIP = ?

/*

Needed ?
#include <type_traits>

template <typename E>
constexpr auto to_u(E e) noexcept {
    return static_cast<std::underlying_type_t<E>>(e);
}

// constants.h
#pragma once
#include <QLatin1StringView>


*/

struct BC
{
  Q_GADGET // Aktiviert das Meta-System für diese Klasse ohne QObject-Overhead

public:

  enum class OpID : uint8_t
  {
    ReadValue,
    WriteValue,
  };
  Q_ENUM(OpID)

  // __fix! flags draus machen ?
  enum class State : uint8_t
  {
    Invalid,
    Locked,
    Failed,
    InSync,
    OK
  };
  Q_ENUM(State)

  enum class ID : uint8_t
  {
    //{%Region Console}

    Invalid                                         = 0x0,
    ID_Pimp                                         = 0xF1, // dummy id to identify the tuning page


    ID_Console_Master                               = 0x08, // (Can Id In Master Mode)
    ID_Console_Slave                                = 0x48, // (Can Id In Slave Mode)
    //  ID_Console_Response                                      = 0x58,
    ID_Bib                                          = 0x58,

    // Reg 0..79 Unused

    Cons_Stat_Dist_Hi                               = 0x50, // [Factor:0.1]
    Cons_Stat_Dist_Lo                               = 0x51,
    Cons_Stat_Avgspeed_Hi                           = 0x52, // [Factor:0.1]
    Cons_Stat_Avgspeed_Lo                           = 0x53,

    // Reg 84..99 Unused

    Cons_Stat_Odo_Hihi                              = 0x64, // Odometer [Unit:Km, Faktor:0.1]
    Cons_Stat_Odo_Hilo                              = 0x65, // !!! Reverse Byte Order On Writing !!!
    Cons_Stat_Odomoter_Lohi                         = 0x66,
    Cons_Stat_Odo_Lolo                              = 0x67,

    Cons_Preference_Nip_Hihi                        = 0x68, // -
    Cons_Preference_Nip_Hilo                        = 0x69,
    Cons_Preference_Nip_Lohi                        = 0x6a,
    Cons_Preference_Nip_Lolo                        = 0x6b,
    Cons_Throttle_Calibrated                        = 0x6c, // Throttle Calibration Performed
    Cons_Stat_Chrono_Second                         = 0x6d, // Trip Time Seconds
    Cons_Stat_Chrono_Minute                         = 0x6e, // Trip Time Minutes
    Cons_Stat_Chrono_Hour                           = 0x6f, // Trip Time Hours
    Cons_Preference_Lcd_Contrast                    = 0x70, // Lcd Contrast
    Cons_Sn_Location                                = 0x71, // Location
    Cons_Sn_Year                                    = 0x72, // Mfd Year
    Cons_Sn_Month                                   = 0x73, // Mfd Month
    Cons_Sn_Day                                     = 0x74, // Mfd Day

    Cons_Sn_Pn_Hi                                   = 0x75, // Product Number
    Cons_Sn_Pn_Lo                                   = 0x76,
    Cons_Sn_Item_Hi                                 = 0x77, // Serial Number
    Cons_Sn_Item_Lo                                 = 0x78,

    // Reg 121 Unused

    Cons_Assist_Gauge_Joint                         = 0x7a, // Gauge Joint [Range:0..11]
    Cons_Throttle_Min_Hi                            = 0x7b, // Throttle Min Actor Value
    Cons_Throttle_Min_Lo                            = 0x7c,
    Cons_Throttle_Max_Hi                            = 0x7d, // Throttle Max Actor Value
    Cons_Throttle_Max_Lo                            = 0x7e,

    // Reg 127 Unused

    Cons_Preference_Light_On_At_Start               = 0x80, // Lightonatstart Indicate If The Accessory Shall Be Enabled When Turning The Bike On. 0-No, 1-Yes

    Cons_Geometry_Circ_Hi                           = 0x81, // Circumference Of The Rear Wheel [Mm]
    Cons_Geometry_Circ_Lo                           = 0x82,

    Cons_Assist_Maxspeed_Flag                       = 0x83, // Indicates That There Is An Upper Speed Limit Where The Motor Is Allowed To Assist
    Cons_Assist_Maxspeed_Hi                         = 0x84, // Maximum Speed For Which The Motor Can Assist. This Is Irrelevant If Maxspeedflag Is Not Set [Unit:Km/H, Range:1..??, Factor:0.1] (Code 3773)
    Cons_Assist_Maxspeed_Lo                         = 0x85,

    Cons_Throttle_Maxspeed_Flag                     = 0x86, // Throttle Max Speed Flag
    Cons_Throttle_Maxspeed_Hi                       = 0x87, // Throttle Max Speed Msb [Unit:Km/H, Factor:0.1] Code 3775
    Cons_Throttle_Maxspeed_Lo                       = 0x88,
    Cons_Assist_Minspeed_Flag                       = 0x89, // Min Speed Flag
    Cons_Assist_Minspeed                            = 0x8a, // Min Speed Code 3776

    Cons_Assist_Brake_Level                         = 0x8b, // Brake Rekuperation Level [Unit:%, Range:0..64, Factor:1.5625] Code 2002
    Cons_Preference_Trip_To_Empty_Flag              = 0x8c, // 0:Hide, 1:Show Remaining Time/Dist Pc2003 (No Effect Anymore?)
    Cons_Preference_Display_Units                   = 0x8d, // Indicates Unit System To Use When Displaying Units. 0-English, 1-Metric
    Cons_Throttle_Enable_Onstrain                   = 0x8e, // Allow Throttle Over Maxspeed If Strain Gauge Signal Detected

    // Reg 143..159 Unused

    Cons_Assist_Brake_Flag                          = 0xa0, // Brage Sensor Enable, 0: Brake Sensor Off, 1: Sensor On  Code 2006
    Cons_Assist_Brake_Polarity                      = 0xa1, // Brake Sensor Type:   0: No (Normal Open), 1: Nc (Normal Closed), 2:0-5 (Analog 0..5v), 3:5-0 (Analog 5..0v) Code 2006
    Cons_Assist_Gauge_Filter                        = 0xa2, // Torque Sensor Speed  [Range:0..8 (1..4 Recommended)] Code 1234

    Cons_Rev_Sw                                     = 0xa3, // Software Version

    Cons_Assist_Gauge_Gain                          = 0xa4, // Sensor Gain [Range:0.1..4.0, Factor:0.1] Code 0007
    Cons_Assist_Gain_A                              = 0xa5, // Torque Sensor Extra Gain [Range:0.1..4.0, Factor:0.1] Code 0008a
    Cons_Assist_Gain_B                              = 0xa6, // Torque Sensor Extra Gain Max Speed [Unit:Km/H, Range:0.0..25.0, Factor:0.1] Code 0008b
    Cons_Sn_Type                                    = 0xa7, // Type Of Console: 0-Eps, 1-Ride+, 2-Boost.
    Cons_Preference_Region                          = 0xa8, // Region
    Cons_Preference_Configbit_0                     = 0xa9, // Configbit0
    Cons_Throttle_Enable_Boost_Display              = 0xaa, // Display The "Boost" Message Or Pictogram When It Activates
    Cons_Assist_Autoregen_Flag                      = 0xab, // Autoregen Flag

    // Reg 172 Unused                                             // Regenenabled, Yet Unused

    Cons_Rev_Sub                                    = 0xad, // Software Subversion
    Cons_Preference_Light_Button_Mode               = 0xae, // Indicate The Operation Of Console Button "Light/Power". 0-Click Turns Bike Off, Hold Toggles Accessory, 1-Click Toggle Accessory, Hold Turns Bike Off
    Cons_Preference_Expertmode                      = 0xaf, // Expertmode Add New Display Mode For Expert Mode (Unitl Hw 15)

    Cons_Assist_Level_1                             = 0xb0, // Assist Level 1 [Unit:%, Factor:1,5625]
    Cons_Assist_Level_2                             = 0xb1, // Assist Level 2 [Unit:%, Factor:1,5625]
    Cons_Assist_Level_3                             = 0xb2, // Assist Level 3 [Unit:%, Factor:1,5625]
    Cons_Assist_Level_4                             = 0xb3, // Assist Level 4 [Unit:%, Factor:1,5625]
    Cons_Assist_Initlevel                           = 0xb4, // Initial Assist Level [Range:0..4]

    Cons_Preference_Codes_Hihi                      = 0xb5, // Codes Lsb 0-(3771, 2005)Wheel Circumference, 1-(3772)Diagnostic Mode, 2-(3773)Max Speed, 3-(3774)Overvoltage Protection, 4-(3775)Max Throttle Speed, 5-(3776)Minimum Assist Speed, 6-(1976)Motor Direction, 7-(5000)Deprecated, 8-(2001)Metric Vs Imperial, 9-(2002)Regen Value, 10-(2003)Remaining Distance, 11-(2004)Clock Time, 12-(2006)Brake Switch Config, 13-(2007)Throttle Polarity, 14-(2008)Accessory Voltage, 15-(0041)Slave Console, 16-(1234)Filter, 17-(1970)Light Sensor, 18-(0007)Gauge Gain, 19-(0008)Assistance Gain, 20-(0009)Gauge Joint, 21-(0911)Deprecated, 22-(0001)Console Info, 23-(0002)Battery Info, 24-(0003)Motor Info, 25-(6000)Battery Statistics, 26-(0006)Speed Gain, 27-Alarm, 28-Time
    Cons_Preference_Codes_Hilo                      = 0xb6,
    Cons_Preference_Codes_Lohi                      = 0xb7,
    Cons_Preference_Codes_Lolo                      = 0xb8,
    Cons_Preference_Codesrw_Hihi                    = 0xb9, // Codesrw Lsb Same Bit As Console.Preference.Codes Except For: 28-Mountain Mode
    Cons_Preference_Codesrw_Hilo                    = 0xba,
    Cons_Preference_Codesrw_Lohi                    = 0xbb,
    Cons_Preference_Codesrw_Lolo                    = 0xbc,
    Cons_Sn_Oem_Hi                                  = 0xbd, // Oem
    Cons_Sn_Oem_Lo                                  = 0xbe,
    Cons_Preference_Throttle_Mode                   = 0xbf, // Throttlemode Configure The Throttle For The Menu Change Mode (Until Hw 15)
    Cons_Assist_Speedgain                           = 0xc0, // [ Factor:0,1 ]
    Cons_Sn_Product_Hi                              = 0xc1, // Product
    Cons_Sn_Product_Lo                              = 0xc2,
    Cons_Throttle_Boost_Triggerlevel                = 0xc3, // Boost Trigger Level [Unit:%, Range:1.5..50, Factor:1.5625] Code 3779
    Cons_Preference_Flip_Side                       = 0xc4, // Indicates On What Side Of The Handlebar Is Located The Console. 0-Right, 1-Left Code 2009
    Cons_Config_Testmode                            = 0xc5, // Writing A 1 To This Register Allows Setting The Console In Test Mode To Test The Lcd And Buttons
    Cons_Config_Testmode_Hw14                       = 0xc3, // Reg C3 With Hw14

    Cons_Assist_Mountain_Cap                        = 0xc6, // Maximum Set Point To Send To Motor When In Mountain Mode. 0-Disabled [Unit:%, Range:0..100, Faktor:1.5625]
    Cons_Config_Last_Mode                           = 0xc7, // Writing 255 Will Disable The Last Mode On Display Power On, 0 Will Enable The Last Mode On Display Power On

    Console_Config_Last_Mode_On                     = 0x00,
    Console_Config_Last_Mode_Off                    = 0xff,

    // Reg 200..207 Unused

    Cons_Rev_Hw                                     = 0xd0, // Hardware Version
    Cons_Status_Slave                               = 0xd1, // Writing A 1 To This Register Allows Going Imemdiatly In Slave Mode, Cannot Be Set To 0

    Cons_Throttle_Raw_Hi                            = 0xd2, // Throttle Raw Position
    Cons_Throttle_Raw_Lo                            = 0xd3,
    Cons_Throttle_Position                          = 0xd4, // Throttle Position [Factor:1.5625]

    // Reg 213 Unused                                             // Outdated, Formerly Used By Pref. Language
    // Reg 214 Unused                                             // And Boat Related. Now No Data From Regs.

    Cons_Assist_Level_Rekuperation_3                = 0xd7, // 215 Reku Level 3 [Unit:%, Factor:1,5625]
    Cons_Assist_Level_Rekuperation_4                = 0xd8, // 216 Reku Level 4 [Unit:%, Factor:1,5625]
    Cons_Config_Service_Timestamp_Hi                = 0xd9, // Day, In Battery-Relative Value, From Which Console Displays "Service". 0 To Disable The Feature
    Cons_Config_Service_Zimestamp_Lo                = 0xda,
    Cons_Config_Service_Distance_Hi                 = 0xdb, // Odometer Value, From Which Console Displays "Service". 0 To Disable The Feature
    Cons_Config_Service_Distance_Lo                 = 0xdc,

    // Reg 211 Unused

    Cons_Assist_Level_Rekuperation_1                = 0xde, // Reku Level 1 [Unit:%, Factor:1,5625]
    Cons_Assist_Level_Rekuperation_2                = 0xdf, // Reku Level 2 [Unit:%, Factor:1,5625]

    // Reg 224..255 Unused

    //{%Endregion Console}

    //{%Region Battery}
    ID_Battery                                      = 0x10,

    //  ID_Battery_Response                                      = 0x08,
    Reg_Battery_Config_Allow_Buckcharging_On_Bike   = 0x12, // Specifies If The Battery Can Recharge In Buck Mode Even On A Bike. Make Sure It Is Impossible To Have An Accessory Output Before Setting This To 1. 0: Disallow, 1: Allow
    Reg_Battery_Status_Charger_Manager_Status       = 0x13, // Gives State Of Charging Mef: 0-Off, 1-Stand-By, 2-Charger, 3-Accessory, 4-Vdcin Sense, 5-Overtemp, 6-Charge Done, 7-Buck Failed
    Reg_Battery_Config_Wake_On_Powervoltage         = 0x14, // Specifies If The Battery Should Wake Up Automatically When A Voltage Is Present On The Vpower. A Value Of 0 Disables The Feature

    Reg_Battery_Config_Sla_Constant_A               = 0x15, // ++++ Boat Related (Soc Estimator)
    Reg_Battery_Config_Sla_Constant_B               = 0x16, // ++++ Boat Related (Soc Estimator)
    Reg_Battery_Config_Sla_Constant_C               = 0x15, // ++++ Boat Related (Soc Estimator)

    Reg_Battery_Rev_Sub                             = 0x18, // Software Subversion

    Reg_Battery_Config_Sla_Constant_D               = 0x15, // ++++ Boat Related (Soc Estimator)

    Reg_Battery_Rtc_Last_Valid_Timestamp_Hihi       = 0x19, // Indicates Last Valid Battery Time. This Read-Only Register Is Set To Rtc.Time When Written And Then Refresh Each 34 Minutes
    Reg_Battery_Rtc_Last_Valid_Timestamp_Hilo       = 0x1a,
    Reg_Battery_Rtc_Last_Valid_Timestamp_Lohi       = 0x1b,
    Reg_Battery_Rtc_Last_Valid_Timestamp_Lolo       = 0x1c,

    Reg_Battery_Status_Flags_Hi                     = 0x1d, // Alert Status Bits: 0-Vctrl (Code 20), 1-Precharge (Code 21 And 67), 2-Relay (Code 22), 3-Bms (Code 23), 4-Dcdc (Code 28), 6-Gg Out Of Range Temperature, 7-Battery Pack Out Of Range Temperature, 8-Balancer Overvolt (Code 62), 9-Balancer Undervolt (Code 61), 10-Pack Problem (Code 63), 11-Accessory Overcurrent (Code 60), 12-Electronic Fuse (Code 66), 13-Balancer Plug Not Connected, 14- +5v Short(Lached)

    Reg_Battery_Status_Cellpack_Current_Hi          = 0x1e, // Reading Battery Current By A Shunt Resistor. No Delay, No Calibration Compared To Battery.Gg.Ai [Unit:A, Factor:0.001]
    Reg_Battery_Status_Cellpack_Current_Lo          = 0x1f, // !!! Signed !!!

    Reg_Battery_Config_Power_Voltage_Enable         = 0x21, // - ??? Enable/Disable Vpower ???

    Reg_Battery_Config_Accessory_Enabled            = 0x22, // -

    Reg_Battery_Config_Shutdown                     = 0x25, // Write 1 To Shutdwon System

    Reg_Battery_Config_Control_Voltage_Enable       = 0x26, // Enable/Disable Vcontrol

    Reg_Battery_Config_Accessory_Voltage            = 0x28, // - Until Hw 52 [Unit:V, Factor:6]
    //   Since Hw 60 [Unit:V, Factor:0.1]

    Reg_Battery_Config_Cap_Sense_Mode               = 0x29, // Controls The Mode Of Operation Of The Soc Level Indicator. 0: Inactive, 1: Touch Detect When The Battery Is Off, 2: Touch Detect When Off And Soc Indication When Battery Is On. 3: Red And Blue Colors . 4: 5levels Soc

    Reg_Battery_Config_Communication_Mode           = 0x2a, // Determines How The Battery Communicates. To Change The Value, We Must First Write 0xaa To This Register And Then Write 1 To Switch To I2c Or 2 To Switch To Can
    Battery_Config_Communication_Mode_Key           = 0xaa,

    Reg_Battery_Status_Estimated_Soc                = 0x30, // Return An Estimated Value Of Soc Based On Battery Voltage. Only Works With Liion Battery [Unit:%]

    Reg_Battery_Status_Battery_Voltage_Normalized   = 0x32, // Battery Voltage Normalized With 3.7v/Cell. Status.Vbattinternal It Used In Rev 104 And Less Otherwise Status.Vbatt [Unit:V, Factor:0.416667, Offset:20.8333]
    Reg_Battery_Stat_Battery_Avgvoltage_Normalized  = 0x33, // Average Battery Voltage Read During 50s Based On Battery.Status.Vbatt, In Percentage Of Its Nominal Voltage [Unit:V, Factor:0.416667, Offset:20.8333]

    Reg_Battery_Config_Shipmode                     = 0x37, // Determines If The Battery Is To Go In Ship Mode (Only External Power Can Wake It) Upon Its Next Shutdown. We Need To First Write 0xaa And Then The Desired Value To Set The Value. 0-Normal Mode, 1-Ship Mode
    Battery_Config_Shipmode_Key                     = 0xaa,

    Reg_Battery_Rev_Hw                              = 0x3b, // Hardware Version
    Reg_Battery_Rev_Sw                              = 0x3c, // Software Version

    Reg_Battery_Config_Type                         = 0x3d, // -

    Reg_Battery_Rev_Bom                             = 0x41, // Identification Of Printed Circuit Board Bill Of Material Version. 1: All Smc6.2 And Smc#6.3r1. 8: Smc#6.3r4

    Reg_Battery_Config_Taillamp_Intensity           = 0x43, // Controls The Intensity Of The Tail Lamp. 0: Off. 1-100%: On
    Reg_Battery_Config_Accessory_Mounted            = 0x44, // -
    Reg_Battery_Config_Battint_Voltage_Enable       = 0x45, // Enable/Disable Vbattint
    Reg_Battery_Config_Diag                         = 0x46, // -
    Reg_Battery_Config_Force_Done                   = 0x47, // ++++ Setting This Register To 0x45 Will Force Soc To 100%
    Battery_Config_Force_Done                       = 0x45,

    Reg_Battery_Stat_Resets_Hi                      = 0x48, // Reset Counter
    Reg_Battery_Stat_Resets_Lo                      = 0x49,

    Reg_Battery_Status_Internal_Battery_Voltage_Hi  = 0x4a, // Reading Of Vbattinternal [Unit:V, Factor:0.001]
    Reg_Battery_Status_Internal_Battery_Voltage_Lo  = 0x4b,

    Reg_Battery_Status_Console_Voltage_Hi           = 0x4c, // Reading Of Vconsole (Voltage Applied To Console) [Unit:V, Factor:0.001]
    Reg_Battery_Status_Console_Voltage_Lo           = 0x4d,

    Reg_Battery_Status_12v_Voltage_Hi               = 0x4e, // Reading Of Internal 12v [Unit:V, Factor:0.001]
    Reg_Battery_Status_12v_Voltage_Lo               = 0x4f,

    Reg_Battery_Config_Nominal_Battery_Voltage      = 0x50, // Battery System Nominal Voltage

    Reg_Battery_Timer_Power_Hi                      = 0x51, // Time Before The Power Output Shuts Down [Unit:S]
    Reg_Battery_Timer_Power_Lo                      = 0x52,
    Reg_Battery_Timer_Accessory_Hi                  = 0x53, // Time Before The Accessory Voltage Shuts Down [Unit:S]
    Reg_Battery_Timer_Accessory_Lo                  = 0x54,
    Reg_Battery_Timer_Precharge                     = 0x55, // Time Allowed To Precharge The Motor, Before Enabling Full Power [Unit:S]
    Reg_Battery_Timer_Shutdown_Hi                   = 0x56, // Time Of Inactivity Before The System Shuts Down [Unit:S]
    Reg_Battery_Timer_Shutdown_Lo                   = 0x57,

    Reg_Battery_Sn_Location                         = 0x5b, // Location

    Reg_Battery_Status_Accessory_Voltage_Hi         = 0x5e, // Reading Of Vaccessory [Unit:V, Factor:0.001]
    Reg_Battery_Status_Accessory_Voltage_Lo         = 0x5f,

    Reg_Battery_Status_Charge_Level                 = 0x61, // Batterylevel [Unit:%, Factor:6.6667]
    Reg_Battery_Cellmon_Balancer_Enabled            = 0x65, //

    Reg_Battery_Status_Temperature_Sensor_1         = 0x66, // [Unit:C]
    Reg_Battery_Status_Temperature_Sensor_2         = 0x67, // !!! Signed !!!
    Reg_Battery_Status_Temperature_Sensor_3         = 0x68,
    Reg_Battery_Status_Temperature_Sensor_4         = 0x69,

    Reg_Battery_Sn_Cellpack_Hi                      = 0x6a, // Serial Number Cellpack
    Reg_Battery_Sn_Cellpack_Lo                      = 0x6b,

    Reg_Battery_Cellmon_Channel_Address             = 0x6c, // Gateway To Cell Monitor, Write Address Here
    Reg_Battery_Cellmon_Channeldata_Hi              = 0x6d, // And Read 16 Bit Voltages Here
    Reg_Battery_Cellmon_Channeldata_Lo              = 0x6e, // And Here

    Reg_Battery_Cellmon_Calibration_Data_Lo         = 0x6f, // Cell Calibration Data, Select Cell Via Reg_Battery_Cellmon_Channel Register
    // Since Hw 60, Sw 103 16 Bit Values Are Provided, See Reg_Battery_Calibration_Data_Hi Below
    Reg_Battery_Protect_Unlock                      = 0x71,
    Battery_Protect_Lock_Key                        = 0x00,
    Battery_Protect_Unlock_Key                      = 0xaa,

    Reg_Battery_Sn_Year                             = 0x72, // Mfd. Year
    Reg_Battery_Sn_Month                            = 0x73, // Mfd. Month
    Reg_Battery_Sn_Day                              = 0x74, // Mfd Day

    Reg_Battery_Sn_Pn_Hi                            = 0x75, // Part Number
    Reg_Battery_Sn_Pn_Lo                            = 0x76,
    Reg_Battery_Sn_Item_Hi                          = 0x77, // Serial Number
    Reg_Battery_Sn_Item_Lo                          = 0x78,

    Reg_Battery_Cellmon_Calibration_Data_Hi         = 0x7c, // Refer Reg_Battery_Calibration_Data_Lo Above

    Reg_Battery_Status_Poweron_Reset_Count          = 0x7d, // Return How Many Time Main Microcontroller Hardly Reset

    Reg_Battery_Config_Autoswitch_Communication     = 0x7e, // ++++ Allow To Switch Communication Mode Without Shutdown. Write 0xaa, Then 0x01. Comm. Mode Switches. Communicate With Desired Comm. Mode Before 5s (100ms Min) To Validate. Write 0 To Desactivate
    Battery_Config_Autoswitch_Communication_Key     = 0xaa,

    Reg_Battery_Brigde_Charger_Addr                 = 0x85, // Gateway To Charger, Write Address Here (Needs Unlocking)
    Reg_Battery_Brigde_Charger_Data                 = 0x86, // And Read Data Here

    Reg_Battery_Status_Leds                         = 0x87, // -

    Reg_Battery_Stat_Chargetime_Mean_Hi             = 0x8a, // -
    Reg_Battery_Stat_Chargetime_Mean_Lo             = 0x8b, // -
    Reg_Battery_Stat_Chargetime_Worst_Hi            = 0x8c, // -
    Reg_Battery_Stat_Chargetime_Worst_Lo            = 0x8d, // -

    Reg_Battery_Stat_Battery_Cycles_Hi              = 0x8e, // - Battery Charge Cycles
    Reg_Battery_Stat_Battery_Cycles_Lo              = 0x8f, // -

    Reg_Battery_Stat_Rtc_Resync                     = 0x90, // -
    Reg_Battery_Stat_Lmd_Adapt                      = 0x91, // -

    Reg_Battery_Stat_Battery_Full_Cycles_Hi         = 0x92, // - Battery Full Charge Cycles
    Reg_Battery_Stat_Battery_Full_Cycles_Lo         = 0x93, // -

    Reg_Battery_Stat_Power_Cycles_Hi                = 0x96, // Power On Cycles
    Reg_Battery_Stat_Power_Cycles_Lo                = 0x97, // -

    Reg_Battery_Stat_Battery_Max_Voltage            = 0x98, // Maximum Voltage Ever Seen By The Battery, In Percentage Of Its Nominal Voltage [Unit:%, Factor:0.416667, Offset:20.8333]
    Reg_Battery_Stat_Battery_Min_Voltage            = 0x99, // Minimum Voltage Ever Seen By The Battery, In Percentage Of Its Nominal Voltage [Unit:%, Factor:0.416667, Offset:20.8333]

    Reg_Battery_Status_Dcin_Voltage_Hi              = 0x9a, // Reading Of External Power Supply Voltage [Unit:V, Factor:0.001]
    Reg_Battery_Status_Dcin_Voltage_Lo              = 0x9b,

    Reg_Battery_Stat_Temperature_Max                = 0x9c, // - !!! Signed !!!
    Reg_Battery_Stat_Temperature_Min                = 0x9d, // - !!! Signed !!!

    Reg_Battery_Stat_Control_Voltage_Shorts         = 0x9e, // Until Hw 52, Now Via I2c Bridge

    Reg_Battery_Stat_Watchdog_Reset_Count           = 0x9f, // Return How Many Time Watchdog Reset Trigged
    Reg_Battery_Status_Reset_Wdt                    = 0x9f, // - Same As Above?

    Reg_Battery_Rtc_Ctrl                            = 0xa0, // -

    Reg_Battery_Rtc_Time_Hihi                       = 0xa1, // Indicates Current Battery Time In Seconds. Its Value Is Normally Relative To Assembly Time
    Reg_Battery_Rtc_Time_Hilo                       = 0xa2,
    Reg_Battery_Rtc_Time_Lohi                       = 0xa3,
    Reg_Battery_Rtc_Time_Lolo                       = 0xa4,

    Reg_Battery_Rtc_Status                          = 0xa5, // Describes The Status Of The Rtc: 0-In Sync, 1-Write Ok, 2-Read Ok, 3-Update Time, 4-Update Ctrl, 5-Osc Ok, 7-Rtc Detected

    Reg_Battery_Status_Battery_Voltage_Hi           = 0xa6, // Reading Of Vbatt. Return Same Value As Vcell13 [Unit:V, Factor:0.001]
    Reg_Battery_Status_Battery_Voltage_Lo           = 0xa7,

    Reg_Battery_Status_Power_Voltage_Hi             = 0xaa, // Reading Of Vpower ("High" Voltage Applied To Motor) [Unit:V, Factor:0.001]
    Reg_Battery_Status_Power_Voltage_Lo             = 0xab,

    Reg_Battery_Status_Control_Voltage_Hi           = 0xac, // Reading Of Vcontrol (Control Voltage Applied To Motor) [Unit:V, Factor:0.001]
    Reg_Battery_Status_Control_Voltage_Lo           = 0xad,

    Reg_Battery_Config_Pack_Serial                  = 0xae, // No Of Cells In Serial
    Reg_Battery_Config_Pack_Parallel                = 0xaf, // No Of Cells In Parallel

    Reg_Battery_Gasgage_Dmfsd                       = 0xb5, // Digital Magnitude Filter And Self Discharge Rate

    Reg_Battery_Config_Ilmd                         = 0xb9, // - [Unit:Ah, Factor:0.54835]

    Reg_Battery_Gasgage_Soc                         = 0xbc, // - [Unit:%]

    Reg_Battery_Gasgage_Ai_Hi                       = 0xd3, // - [Unit:A, Factor:0.002141]
    Reg_Battery_Gasgage_Ai_Lo                       = 0xd4,

    Reg_Battery_Stat_Lmd_Hi                         = 0xd5, // - [Unit:Ah, Factor:0.002142]
    Reg_Battery_Stat_Lmd_Lo                         = 0xd6,
    Reg_Battery_Gasgage_Lmd_Hi                      = 0xd5, // - [Unit:Ah, Factor:0.002142]
    Reg_Battery_Gasgage_Lmd_Lo                      = 0xd6,

    Reg_Battery_Config_Nac_Raddr_Hi                 = 0xdb, // -
    Reg_Battery_Config_Nac_Raddr_Lo                 = 0xdc,

    Reg_Battery_Gasgage_Status_Flags                = 0xde, // -

    Reg_Battery_Gasgage_Voltage_Hi                  = 0xdf, // - [Unit:V, Factor:0.008]
    Reg_Battery_Gasgage_Voltage_Lo                  = 0xe0,

    Reg_Battery_Gasgage_Temperatur_Hi               = 0xe1, // - [Unit:C, Factor:0.25, Offset:-273]
    Reg_Battery_Gasgage_Temperatur_Lo               = 0xe2,

    Reg_Battery_Stat_Ggjr_Calib                     = 0xec, // -

    Reg_Battery_Gasgage_Voltage_Divider             = 0xed, // Gas Gage External Divider Value. Indicates How The Voltage Is Divided Before Reaching The Gg. For Example, If The Battery Voltage Is 30v And This Register Is 10, The Gg Will Have 3v At Its Input [Factor:0.1]

    Reg_Battery_Config_Nac_Hi                       = 0xe5, // -
    Reg_Battery_Config_Nac_Lo                       = 0xe6,

    Reg_Battery_Protect_Mode                        = 0xe7, // -
    Reg_Battery_Protect_Control                     = 0xe8, // -

    Reg_Battery_Status_Flags_Lo                     = 0xf0, // Alert Status Bits: 0-Vctrl (Code 20), 1-Precharge (Code 21 And 67), 2-Relay (Code 22), 3-Bms (Code 23), 4-Dcdc (Code 28), 6-Gg Out Of Range Temperature, 7-Battery Pack Out Of Range Temperature, 8-Balancer Overvolt (Code 62), 9-Balancer Undervolt (Code 61), 10-Pack Problem (Code 63), 11-Accessory Overcurrent (Code 60), 12-Electronic Fuse (Code 66), 13-Balancer Plug Not Connected, 14- +5v Short(Lached)

    Reg_Battery_Rtc_Last_Charge_Timestamp_Hihi      = 0xf2, // Written On Boot-Up And Shutdown, This Register Indicates When Last Minimum 10% Charge Was Completed
    Reg_Battery_Rtc_Last_Charge_Timestamp_Hilo      = 0xf3,
    Reg_Battery_Rtc_Last_Charge_Timestamp_Lohi      = 0xf4,
    Reg_Battery_Rtc_Last_Charge_Timestamp_Lolo      = 0xf5,

    Reg_Battery_Stat_Charge_Times_Channel           = 0xf6, // Indicates Which Charge Statistic Should Be Accessed When Accessing Chargedata. Value Can Be Any Value Between 1 And 9, 1 Being For 10% Stat And 9 For 90% Stat
    Reg_Battery_Stat_Charge_Times_Data_Hi           = 0xf7,
    Reg_Battery_Stat_Charge_Times_Data_Lo           = 0xf8,

    Reg_Battery_Config_Max_Charge_Hi                = 0xf9, // Maximum Regen. Current On Vpower [Unit:A, Factor:0.001]
    Reg_Battery_Config_Max_Charge_Lo                = 0xfa,

    Reg_Battery_Config_Max_Discharge_Hi             = 0xfb, // Maximum Drawn Current On Vpower [Unit:A, Factor:0.001]
    Reg_Battery_Config_Max_Discharge_Lo             = 0xfc,

    Reg_Battery_Config_Cellcapacity_Hi              = 0xfd, // - [Unit:Ah, Factor:0.001]
    Reg_Battery_Config_Cellcapacity_Lo              = 0xfe,


    Reg_Battery_Bridge_I2c_Regaddr_Device           = 0x58, // Gateway To I2c Registers, Write Device (Highbyte) Here,
    Reg_Battery_Bridge_I2c_Regaddr_Register         = 0x70, // Register (Lowbyte) Here
    Reg_Battery_Bridge_I2c_Register_Data            = 0x60, // And Read Data Here


    // Battery Cell Monitor Registers
    Reg_Cellmon_Channel_Voltage_1                   = 0x01, // [Unit:V, Factor:0.001]
    // ...
    Reg_Cellmon_Channel_Voltage_13                  = 0x0d, // [Unit:V, Factor:0.001]

    Reg_Cellmon_Cell_Voltage_1                      = 0x81, // [Unit:V, Factor:0.001]
    // ...                                                        // !!! Signed !!!
    Reg_Cellmon_Cell_Voltage_13                     = 0x8d, // [Unit:V, Factor:0.001]

    Reg_Cellmon_Status_Bomid_Voltage                = 0xc8, // Raw Voltage Of The Resistor Divider Used To Identify The Revision Of The Bom
    Reg_Cellmon_Status_Packid_Voltage               = 0xc9, // Raw Voltage Of The Resistor Divider Used To Identify The Cell Pack
    Reg_Cellmon_Status_3v3_Voltage                  = 0xca, // Internal Voltage Of The 3.3v Derived From The Internal 5v [Unit:V, Factor:0.001]
    Reg_Cellmon_Status_5v_Voltage                   = 0xcb, // Internal Voltage Of The 5(5.5)V Derived From The Internal 12v [Unit:V, Factor:0.001]

    Reg_Cellmon_Calibration_1                       = 0x01, // [Unit:%, Factor:0.03] !!! Signed !!!
    // ...                                                        // !!! Signed !!!
    Reg_Cellmon_Calibration_13                      = 0x0d, // [Unit:%, Factor:0.03]

    Reg_Charger_Status_Flags_Hi                     = 0x02, // -
    Reg_Charger_Status_Flags_Lo                     = 0x03, // -

    Reg_Charger_Mode                                = 0x10, // Indicates The Mode Of The On-Board Charger. 0-Low Power, 1-Idle, 2-Charging, 3-Accessory Output, 5-Calibration, 99-Fault

    Reg_Charger_Final_Voltage_Hi                    = 0x12, // Set Final Charge Voltage [Unit:V, Factor:0.01]
    Reg_Charger_Final_Voltage_Lo                    = 0x13,

    Reg_Charger_Current_Hi                          = 0x14, // Set Charge Current [Unit:A, Factor:0.001]
    Reg_Charger_Current_Lo                          = 0x15,

    Reg_Charger_Voltage_Calibration_Hi              = 0x42, // Multiplier Applied On Charger Voltage Reading For Its Calibration
    Reg_Charger_Voltage_Calibration_Lo              = 0x43,

    Reg_Charger_Current_Calibration_Hi              = 0x46, // Multiplier Applied On Charger Current Reading For Its Calibration
    Reg_Charger_Current_Calibration_Lo              = 0x47,

    Reg_Charger_Rev_Charger                         = 0x56, // -

    //{%Endregion}

    //  {%Region Motor}
    ID_Motor                                        = 0x20,
    //  ID_Motor_Response                                        = 0x08,
    Motor_Assist_Level                              = 0x09, // [Unit:%, Range:-100..100, Factor:1.5625] !!! Signed !!!

    Motor_Assist_Walk_Level                         = 0x0a, // Top Level When Assisting In Walk Mode [Unit:%, Factor:1.5625]
    Motor_Assist_Walk_Speed_Decrease_Start          = 0x0b, // Speed From Which The Motor Starts Diminishing Its Assistance When Using The "Walk Mode" [Unit:Km/H, Factor:0.1]
    Motor_Assist_Walk_Speed_Decrease_End            = 0x0c, // Speed At Which The Motor Gives No More Assistance When Using The "Walk Mode" [Unit:Km/H, Factor:0.1]
    Motor_Assist_Walk_Level_Max                     = 0x0d, // Top Level When Assisting In Walk Mode [Unit:%, Factor:1.5625]

    Motor_Status_Speed                              = 0x11, // - [Unit:Rpm, Factor:9.091]
    Motor_Status_Power_Meter                        = 0x14, // - [Unit:%, Factor:1.5625]

    Motor_Status_Temperature                        = 0x16, // - [Unit:C]

    Motor_Rev_Hw                                    = 0x19, // Hardware Version
    Motor_Rev_Sw                                    = 0x20, // Software Version

    Motor_Torque_Gauge_Value                        = 0x21, // - [Unit:%, Range:0?..100, Factor:1.5625]

    Motor_Rev_Sub                                   = 0x22, // Software Subversion

    Motor_Config_Communication_Mode_Lo              = 0x36, // - 8 Bit Until Sw 83

    Motor_Assist_Lowspeed_Ramp_Flag                 = 0x40, // Enables A Lower Speed Ramp. 0: Ramp Disabled, 1: Ramp Enabled

    Motor_Assist_Direction                          = 0x42, // -
    Motor_Sn_Stator_Type                            = 0x43, // -
    Motor_Geometry_Circ_Hi                          = 0x44,
    Motor_Geometry_Circ_Lo                          = 0x45,

    Motor_Torque_Gauge_Polarity                     = 0x46, // -

    Motor_Status_Main                               = 0x47, // Indicates The Current Main Status Of The Motor. 0-Running, 1-Nocommand, 2-Startup, 3-I2cshutoff, 4-Antibackwardshort, 5-Alarmregen, 6-Alarmshort, 7-Overspeedi, 8-Overspeedv, 9-V12uvp, 10-V12ovp, 11-Vpwruvp, 12-Vpwrovp, 13-Ocprotect, 14-Badstatorpn, 15-Hallerror

    Motor_Sn_Item_Hi                                = 0x60, // Serial Number
    Motor_Sn_Item_Lo                                = 0x61,
    Motor_Sn_Pn_Hi                                  = 0x62, // Partnumber
    Motor_Sn_Pn_Lo                                  = 0x63,
    Motor_Sn_Year                                   = 0x64, // Mfd. Year
    Motor_Sn_Month                                  = 0x65, // Mfd. Month
    Motor_Sn_Day                                    = 0x66, // Mfd. Day

    Motor_Sn_Oem_Hi                                 = 0x67, // Oem
    Motor_Sn_Oem_Lo                                 = 0x68,
    Motor_Sn_Product_Hi                             = 0x69, // Product
    Motor_Sn_Product_Lo                             = 0x6a,
    Motor_Sn_Location                               = 0x6b, // Location

    Motor_Torque_Gauge_Type                         = 0x6c, // -

    Motor_Assist_Stator_Pn_Hi                       = 0x6d, // -
    Motor_Assist_Stator_Pn_Lo                       = 0x6e, //

    Motor_Status_Power_Voltage_Hi                   = 0x70, // - [Unit:V, Factor:0.001]
    Motor_Status_Power_Voltage_Lo                   = 0x71,

    Motor_Status_12v_Voltage_Hi                     = 0x72, // - [Unit:V, Factor:0.001]
    Motor_Status_12v_Voltage_Lo                     = 0x73,

    Motor_Status_5v_Voltage_Hi                      = 0x74, // - [Unit:V, Factor:0.001]
    Motor_Status_5v_Voltage_Lo                      = 0x75,

    Motor_Stat_Max_Power_Voltage_Hi                 = 0x80, // - [Unit:V, Factor:0.001]
    Motor_Stat_Max_Power_Voltage_Lo                 = 0x81,

    Motor_Stat_Max_Temperature_Hi                   = 0x82, // -
    Motor_Stat_Max_Temperature_Lo                   = 0x83,

    Motor_Stat_Odo_Hi                               =  0x84, // - [Unit:Km]
    Motor_Stat_Odo_Lo                               = 0x85,

    Motor_Stat_Chrono_Hours_Hi                      = 0x86, // - [Unit:H]
    Motor_Stat_Chrono_Hours_Lo                      = 0x87,

    Motor_Stat_Chrono_Seconds_Hi                    = 0x88, // - [Unit:S]
    Motor_Stat_Chrono_Seconds_Lo                    = 0x89,

    Motor_Preference_Region                         = 0x8a, // -

    Motor_Assist_Maxspeed                           = 0x8b, // - [Unit:Km/H]
    Motor_Assist_Dynamic_Flag                       = 0x8c, // - [Range:0..1]

    Motor_Config_Pwm_Limit_Enable                   = 0x8d, // -

    Motor_Status_Codes                              = 0x92, // Indicates Conditions Currently Detected By Motor. Bit 0-Sensor Saturation
    Motor_Status_Codes_Latch                        = 0x93, // Indicates Conditions Detected By Motor Since Its Last Power Up. See Bit Description Of Status.Codes


    Motor_Protect_Unlock                            = 0xa5, // Unlock Register, Write Unlock_Key Here Before Setting Protected Registers
    Motor_Protect_Unlock_Key                        = 0xaa,
    Motor_Protect_Lock_Key                          = 0x00,

    Motor_Stat_Hall_Dchs_Hi                         = 0xb0, // -
    Motor_Stat_Hall_Dchs_Lo                         = 0xb1,

    Motor_Stat_Hall_Trans_Hi                        = 0xb2, // -
    Motor_Stat_Hall_Trans_Lo                        = 0xb3,

    Motor_Stat_Hall_Ring_Hi                         = 0xb4, // -
    Motor_Stat_Hall_Ring_Lo                         = 0xb5,

    Motor_Stat_Hall_Lost_Hi                         = 0xb6, // -
    Motor_Stat_Hall_Lost_Lo                         = 0xb7,

    Motor_Torque_Gauge_Noise_Hi                     = 0xc4, // - [Unit:%, Range:0..100, Factor:0.0015259]
    Motor_Torque_Gauge_Noise_Lo                     = 0xc5,

    Motor_Torque_Gauge_Delay_Hi                     = 0xc6, // - [Unit:S, Range:0..?, Factor:0.001]
    Motor_Torque_Gauge_Delay_Lo                     = 0xc7,

    Motor_Torque_Gauge_Speed                        = 0xc8, // - [Unit:Rpm, Range:0..?, Factor:9.091]

    Motor_Torque_Gauge_Voltage_Hi                   = 0xc9, // - [Unit:V, Range:0..5, Factor:0.000076295, Offset:5]
    Motor_Torque_Gauge_Voltage_Lo                   = 0xca,

    Motor_Torque_Gauge_Reference_Hi                 = 0xcb, // - [Unit:V, Range:0..5, Factor:0.000076295, Offset:5]
    Motor_Torque_Gauge_Reference_Lo                 = 0xcc,

    Motor_Config_Communication_Mode_Hi              = 0xcd, // Sets The Communication Mode. 0 For Can And 0xca01 For I2c

    Motor_Torque_Gauge_Gain                         = 0xce, // - [Unit:%, Range:0..398, Factor:1.5625]

    Motor_Torque_Gauge_Max_Voltage                  = 0xe0, // Maximum Voltage Allowed For The Sensor. When The Sensor Detect A Voltage Over This Value For Motor.Torque.Gaugemaxvoltagedelay, It Assumes An Electrical Failure And Cuts Assistance [Unit:V, Range:0..5, Factor:0.019608]
    Motor_Torque_Gauge_Max_Voltage_Delay            = 0xe1, // Time After Which A Voltage Over Motor.Torque.Gaugemaxvoltage Is Assumed To Be An Electrical Failure, Cutting Assistance [Unit:S, Range:0..25.5, Factor:0.1]

    Motor_Assist_Level_Offslope_Hi                  = 0xd0, // Speed At Which The Assist Level Set In The Motor Decreases When The Console Stops Sending Requests (When It Is Removed For Example) [Unit:%/S, Factor:3.05]
    Motor_Assist_Level_Offslope_Lo                  = 0xd1,

    Motor_Assist_Regen_Inflex                       = 0xd2, // Speed From Which Regen Is Not Attenuated [Unit:Rpm, Range:5..?, Factor:9.091]

    Motor_Assist_Maxspeed_Derate_Delta              = 0xd3, // Speed Before Maxspeed To Start Derating [Unit:Rpm, Factor:9.091]
    //{%Endregion}


    //{%Region Sensor}
    ID_Sensor                                       = 0x68,
    Reg_Sensor_Config_Gauge_Gain_Hi                 = 0x10,
    Reg_Sensor_Config_Gauge_Gain_Lo                 = 0x11,

    Reg_Sensor_Config_Ramp_Up_Steps_Hi              = 0x12,
    Reg_Sensor_Config_Ramp_Up_Steps_Lo              = 0x13,

    Reg_Sensor_Config_Decay_Delay_Hi                = 0x14,
    Reg_Sensor_Config_Decay_Delay_Lo                = 0x15,

    Reg_Sensor_Config_Decay_Steps_Hi                = 0x16,
    Reg_Sensor_Config_Decay_Steps_Lo                = 0x17,

    Reg_Sensor_Config_Speed_Threshold_Hi            = 0x18,
    Reg_Sensor_Config_Speed_Threshold_Lo            = 0x19,

    Reg_Sensor_Config_Ramp_Active_Over_Threshold    = 0x1a,

    Reg_Sensor_Status_Torque_Voltage                = 0x1b, // Torque Sensor Voltage

    Reg_Sensor_Status_Cadence                       = 0x1c, // Number Of Turns Per Minutes Made With The Pedals

    Reg_Sensor_Status_Output_Voltage                = 0x1d, // Voltage Output To The Motor's Gauge Sensor

    Reg_Sensor_Status_Pulse_Counter                 = 0x1e, // Pulse Counter. Increases When Back Pedaling And Decreases When Forward Pedaling

    Reg_Sensor_Config_Input_Offset                  = 0x40, // Permit To Offset The Input Value Of The Torque Sensor From +1.64 To -1.65v

    Reg_Sensor_Sn_Location                          = 0x71, // Location

    Reg_Sensor_Sn_Year                              = 0x72, // Mfd. Year
    Reg_Sensor_Sn_Month                             = 0x73, // Mfd. Month
    Reg_Sensor_Sn_Day                               = 0x74, // Mfd. Day

    Reg_Sensor_Sn_Pn_Hi                             = 0x75, // Partnumber
    Reg_Sensor_Sn_Pn_Lo                             = 0x76,

    Reg_Sensor_Sn_Item_Hi                           = 0x77, // Serial Number
    Reg_Sensor_Sn_Item_Lo                           = 0x78,

    Reg_Sensor_Rev_Hw                               = 0x80, // Hardware Version
    Reg_Sensor_Rev_Sw                               = 0x81, // Software Version

    Reg_Sensor_Config_Mode                          = 0x82, // 0-Thune, 1-Fag

    Reg_Sensor_Rev_Sub                              = 0x83 // Software Subversion

  };
  Q_ENUM(ID)

}; // struct BionxID

struct BCDevice
{
  Q_GADGET

public:

  enum class ID : uint8_t
  {
    Invalid        = 0,
    Console        = static_cast<uint8_t>( BC::ID::ID_Console_Slave ),
    Console_Master = uint8_t( BC::ID::ID_Console_Master),
    Battery        = uint8_t( BC::ID::ID_Battery),
    Motor          = uint8_t( BC::ID::ID_Motor ),
    BIB            = uint8_t( BC::ID::ID_Bib ),
    Sensor         = uint8_t( BC::ID::ID_Sensor ),
    Pimp           = uint8_t( BC::ID::ID_Pimp )
  };
  Q_ENUM(ID)
};

using namespace Qt::Literals::StringLiterals; // Für _L1

namespace BCTags
{
  inline constexpr auto Device   = "Device"_L1;
  inline constexpr auto ID       = "ID"_L1;
  inline constexpr auto Label    = "Label"_L1;
  inline constexpr auto Default  = "Default"_L1;
  inline constexpr auto Current  = "Current"_L1;
  inline constexpr auto Enabled  = "Enabled"_L1;
  inline constexpr auto UnitType = "UnitType"_L1;
  inline constexpr auto Min      = "Min"_L1;
  inline constexpr auto Max      = "Max"_L1;
  inline constexpr auto Factor   = "Factor"_L1;

}

#endif // BC_H
