LCOV - code coverage report
Current view: top level - AP_PiccoloCAN/piccolo_protocol - ECUPackets.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 1221 0.0 %
Date: 2026-09-09 11:02:08 Functions: 0 104 0.0 %

          Line data    Source code
       1             : // ECUPackets.c was generated by ProtoGen version 3.2.a
       2             : 
       3             : /*
       4             :  * Copyright Currawong Engineering Pty Ltd
       5             :  * www.currawongeng.com
       6             :  * all rights reserved
       7             :  */
       8             :  
       9             : 
      10             : #include "ECUPackets.h"
      11             : #include "fielddecode.h"
      12             : #include "fieldencode.h"
      13             : #include "scaleddecode.h"
      14             : #include "scaledencode.h"
      15             : 
      16             : /*!
      17             :  * \brief Create the ECU_ThrottleCommand packet
      18             :  *
      19             :  * The throttle command packet sets the throttle position setpoint. The ECU
      20             :  * will adjust the throttle position based on this command.
      21             :  * \param _pg_pkt points to the packet which will be created by this function
      22             :  * \param throttleCommand is Commanded throttle position in percent
      23             :  */
      24           0 : void encodeECU_ThrottleCommandPacket(void* _pg_pkt, float throttleCommand)
      25             : {
      26           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
      27           0 :     int _pg_byteindex = 0;
      28             : 
      29             :     // Commanded throttle position in percent
      30             :     // Range of throttleCommand is 0.0f to 100.0f.
      31           0 :     float32ScaledTo2UnsignedBeBytes(throttleCommand, _pg_data, &_pg_byteindex, 0.0f, 655.35f);
      32             : 
      33             :     // complete the process of creating the packet
      34           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_ThrottleCommandPacketID());
      35             : 
      36           0 : }// encodeECU_ThrottleCommandPacket
      37             : 
      38             : /*!
      39             :  * \brief Decode the ECU_ThrottleCommand packet
      40             :  *
      41             :  * The throttle command packet sets the throttle position setpoint. The ECU
      42             :  * will adjust the throttle position based on this command.
      43             :  * \param _pg_pkt points to the packet being decoded by this function
      44             :  * \param throttleCommand receives Commanded throttle position in percent
      45             :  * \return 0 is returned if the packet ID or size is wrong, else 1
      46             :  */
      47           0 : int decodeECU_ThrottleCommandPacket(const void* _pg_pkt, float* throttleCommand)
      48             : {
      49           0 :     int _pg_byteindex = 0;
      50           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
      51           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
      52             : 
      53             :     // Verify the packet identifier
      54           0 :     if(getECUPacketID(_pg_pkt) != getECU_ThrottleCommandPacketID())
      55           0 :         return 0;
      56             : 
      57           0 :     if(_pg_numbytes < getECU_ThrottleCommandMinDataLength())
      58           0 :         return 0;
      59             : 
      60             :     // Commanded throttle position in percent
      61             :     // Range of throttleCommand is 0.0f to 100.0f.
      62           0 :     (*throttleCommand) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/655.35f);
      63             : 
      64           0 :     return 1;
      65             : 
      66             : }// decodeECU_ThrottleCommandPacket
      67             : 
      68             : /*!
      69             :  * \brief Create the ECU_RPMCommand packet
      70             :  *
      71             :  * The RPM command is used to send a target to the RPM governor on the ECU.
      72             :  * Based on this command, the ECU will use a feedback loop to maintain the
      73             :  * commanded engine speed by adjusting the throttle servo accordingly. If a
      74             :  * valid RPM command is received by the ECU, it will automatically enter RPM
      75             :  * control mode, and adjust the throttle position to match the desired RPM.
      76             :  * Sending a throttle command will cause the ECU to stop the RPM loop and enter
      77             :  * open-loop throttle control mode.
      78             :  * \param _pg_pkt points to the packet which will be created by this function
      79             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
      80             :  */
      81           0 : void encodeECU_RPMCommandPacketStructure(void* _pg_pkt, const ECU_RPMCommand_t* _pg_user)
      82             : {
      83           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
      84           0 :     int _pg_byteindex = 0;
      85             : 
      86             : 
      87             :     // RPM command in units of 50 RPM
      88             :     // Range of rpmCmdHigh is 0 to 255.
      89           0 :     uint8ToBytes(_pg_user->rpmCmdHigh, _pg_data, &_pg_byteindex);
      90             : 
      91             :     // Low part of RPM command from 0 to 49
      92             :     // Range of rpmCmdLow is 0 to 255.
      93           0 :     uint8ToBytes(_pg_user->rpmCmdLow, _pg_data, &_pg_byteindex);
      94             : 
      95             :     // Reconstruct the RPM command
      96           0 :     _pg_data[0] = (uint8_t)((_pg_user->rpmCmd)/50); _pg_data[1] = (uint8_t)((_pg_user->rpmCmd) - _pg_data[0]*50);
      97             : 
      98             :     // complete the process of creating the packet
      99           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_RPMCommandPacketID());
     100             : 
     101           0 : }// encodeECU_RPMCommandPacketStructure
     102             : 
     103             : /*!
     104             :  * \brief Decode the ECU_RPMCommand packet
     105             :  *
     106             :  * The RPM command is used to send a target to the RPM governor on the ECU.
     107             :  * Based on this command, the ECU will use a feedback loop to maintain the
     108             :  * commanded engine speed by adjusting the throttle servo accordingly. If a
     109             :  * valid RPM command is received by the ECU, it will automatically enter RPM
     110             :  * control mode, and adjust the throttle position to match the desired RPM.
     111             :  * Sending a throttle command will cause the ECU to stop the RPM loop and enter
     112             :  * open-loop throttle control mode.
     113             :  * \param _pg_pkt points to the packet being decoded by this function
     114             :  * \param _pg_user receives the data decoded from the packet
     115             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     116             :  */
     117           0 : int decodeECU_RPMCommandPacketStructure(const void* _pg_pkt, ECU_RPMCommand_t* _pg_user)
     118             : {
     119             :     int _pg_numbytes;
     120           0 :     int _pg_byteindex = 0;
     121             :     const uint8_t* _pg_data;
     122             : 
     123             :     // Verify the packet identifier
     124           0 :     if(getECUPacketID(_pg_pkt) != getECU_RPMCommandPacketID())
     125           0 :         return 0;
     126             : 
     127             :     // Verify the packet size
     128           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
     129           0 :     if(_pg_numbytes < getECU_RPMCommandMinDataLength())
     130           0 :         return 0;
     131             : 
     132             :     // The raw data from the packet
     133           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
     134             : 
     135             :     // RPM command in units of 50 RPM
     136             :     // Range of rpmCmdHigh is 0 to 255.
     137           0 :     _pg_user->rpmCmdHigh = uint8FromBytes(_pg_data, &_pg_byteindex);
     138             : 
     139             :     // Low part of RPM command from 0 to 49
     140             :     // Range of rpmCmdLow is 0 to 255.
     141           0 :     _pg_user->rpmCmdLow = uint8FromBytes(_pg_data, &_pg_byteindex);
     142             : 
     143             :     // Reconstruct the RPM command
     144           0 :     _pg_user->rpmCmd = (uint16_t)(_pg_user->rpmCmdHigh*50 + _pg_user->rpmCmdLow);
     145             : 
     146           0 :     return 1;
     147             : 
     148             : }// decodeECU_RPMCommandPacketStructure
     149             : 
     150             : /*!
     151             :  * \brief Encode a ECU_ecuStatusBits_t into a byte array
     152             :  *
     153             : 
     154             :  * \param _pg_data points to the byte array to add encoded data to
     155             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     156             :  * \param _pg_user is the data to encode in the byte array
     157             :  */
     158           0 : void encodeECU_ecuStatusBits_t(uint8_t* _pg_data, int* _pg_bytecount, const ECU_ecuStatusBits_t* _pg_user)
     159             : {
     160           0 :     int _pg_byteindex = *_pg_bytecount;
     161             : 
     162             :     // 1 if driver 8 is on
     163           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->driverPin8 == true) ? 1 : 0) << 7;
     164             : 
     165             :     // 1 if driver 7 is on
     166           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->driverPin7 == true) ? 1 : 0) << 6;
     167             : 
     168             :     // 1 if driver 2 is on
     169           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->driverPin2 == true) ? 1 : 0) << 5;
     170             : 
     171             :     // 1 if driver 1 is on
     172           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->driverPin1 == true) ? 1 : 0) << 4;
     173             : 
     174             :     // 1 if the throttle curve is on.
     175           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->throttleCurveOn == true) ? 1 : 0) << 3;
     176             : 
     177             :     // 1 if autronic, else auxiliary.
     178           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->rs232mode == true) ? 1 : 0) << 2;
     179             : 
     180             :     // 1 if any errors are set - refer to [error packet](#PKT_ECU_ERROR_MSG)
     181           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->errorIndicator == true) ? 1 : 0) << 1;
     182             : 
     183             :     // Global enable based on physical input
     184           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->enabled == true) ? 1 : 0);
     185           0 :     _pg_byteindex += 1; // close bit field
     186             : 
     187           0 :     *_pg_bytecount = _pg_byteindex;
     188             : 
     189           0 : }// encodeECU_ecuStatusBits_t
     190             : 
     191             : /*!
     192             :  * \brief Decode a ECU_ecuStatusBits_t from a byte array
     193             :  *
     194             : 
     195             :  * \param _pg_data points to the byte array to decoded data from
     196             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     197             :  * \param _pg_user is the data to decode from the byte array
     198             :  * \return 1 if the data are decoded, else 0.
     199             :  */
     200           0 : int decodeECU_ecuStatusBits_t(const uint8_t* _pg_data, int* _pg_bytecount, ECU_ecuStatusBits_t* _pg_user)
     201             : {
     202           0 :     int _pg_byteindex = *_pg_bytecount;
     203             : 
     204             :     // 1 if driver 8 is on
     205           0 :     _pg_user->driverPin8 = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
     206             : 
     207             :     // 1 if driver 7 is on
     208           0 :     _pg_user->driverPin7 = (((_pg_data[_pg_byteindex] >> 6) & 0x1)) ? true : false;
     209             : 
     210             :     // 1 if driver 2 is on
     211           0 :     _pg_user->driverPin2 = (((_pg_data[_pg_byteindex] >> 5) & 0x1)) ? true : false;
     212             : 
     213             :     // 1 if driver 1 is on
     214           0 :     _pg_user->driverPin1 = (((_pg_data[_pg_byteindex] >> 4) & 0x1)) ? true : false;
     215             : 
     216             :     // 1 if the throttle curve is on.
     217           0 :     _pg_user->throttleCurveOn = (((_pg_data[_pg_byteindex] >> 3) & 0x1)) ? true : false;
     218             : 
     219             :     // 1 if autronic, else auxiliary.
     220           0 :     _pg_user->rs232mode = (((_pg_data[_pg_byteindex] >> 2) & 0x1)) ? true : false;
     221             : 
     222             :     // 1 if any errors are set - refer to [error packet](#PKT_ECU_ERROR_MSG)
     223           0 :     _pg_user->errorIndicator = (((_pg_data[_pg_byteindex] >> 1) & 0x1)) ? true : false;
     224             : 
     225             :     // Global enable based on physical input
     226           0 :     _pg_user->enabled = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
     227           0 :     _pg_byteindex += 1; // close bit field
     228             : 
     229           0 :     *_pg_bytecount = _pg_byteindex;
     230             : 
     231           0 :     return 1;
     232             : 
     233             : }// decodeECU_ecuStatusBits_t
     234             : 
     235             : /*!
     236             :  * \brief Create the ECU_TelemetryFast packet
     237             :  *
     238             :  * Fast telemetry contains high priority telemetry data and is transmitted at a
     239             :  * user configurable period between 50ms (20Hz) and 10s. By default, the fast
     240             :  * telemetry message is transmitted at 10Hz (every 100ms)
     241             :  * \param _pg_pkt points to the packet which will be created by this function
     242             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     243             :  */
     244           0 : void encodeECU_TelemetryFastPacketStructure(void* _pg_pkt, const ECU_TelemetryFast_t* _pg_user)
     245             : {
     246           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
     247           0 :     int _pg_byteindex = 0;
     248             : 
     249             :     // Throttle signal (0 to 100%)
     250             :     // Range of throttle is 0.0f to 100.0f.
     251           0 :     float32ScaledTo1UnsignedBytes(_pg_user->throttle, _pg_data, &_pg_byteindex, 0.0f, 2.55f);
     252             : 
     253             :     // Engine speed in revolutions per minute
     254             :     // Range of rpm is 0 to 65535.
     255           0 :     uint16ToBeBytes(_pg_user->rpm, _pg_data, &_pg_byteindex);
     256             : 
     257             :     // Fuel used in grams
     258             :     // Range of fuelUsed is 0 to 4294967295.
     259           0 :     uint32ToBeBytes(_pg_user->fuelUsed, _pg_data, &_pg_byteindex);
     260             : 
     261           0 :     encodeECU_ecuStatusBits_t(_pg_data, &_pg_byteindex, &_pg_user->ecuStatusBits);
     262             : 
     263             :     // complete the process of creating the packet
     264           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_TelemetryFastPacketID());
     265             : 
     266           0 : }// encodeECU_TelemetryFastPacketStructure
     267             : 
     268             : /*!
     269             :  * \brief Decode the ECU_TelemetryFast packet
     270             :  *
     271             :  * Fast telemetry contains high priority telemetry data and is transmitted at a
     272             :  * user configurable period between 50ms (20Hz) and 10s. By default, the fast
     273             :  * telemetry message is transmitted at 10Hz (every 100ms)
     274             :  * \param _pg_pkt points to the packet being decoded by this function
     275             :  * \param _pg_user receives the data decoded from the packet
     276             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     277             :  */
     278           0 : int decodeECU_TelemetryFastPacketStructure(const void* _pg_pkt, ECU_TelemetryFast_t* _pg_user)
     279             : {
     280             :     int _pg_numbytes;
     281           0 :     int _pg_byteindex = 0;
     282             :     const uint8_t* _pg_data;
     283             : 
     284             :     // Verify the packet identifier
     285           0 :     if(getECUPacketID(_pg_pkt) != getECU_TelemetryFastPacketID())
     286           0 :         return 0;
     287             : 
     288             :     // Verify the packet size
     289           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
     290           0 :     if(_pg_numbytes < getECU_TelemetryFastMinDataLength())
     291           0 :         return 0;
     292             : 
     293             :     // The raw data from the packet
     294           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
     295             : 
     296             :     // Throttle signal (0 to 100%)
     297             :     // Range of throttle is 0.0f to 100.0f.
     298           0 :     _pg_user->throttle = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/2.55f);
     299             : 
     300             :     // Engine speed in revolutions per minute
     301             :     // Range of rpm is 0 to 65535.
     302           0 :     _pg_user->rpm = uint16FromBeBytes(_pg_data, &_pg_byteindex);
     303             : 
     304             :     // Fuel used in grams
     305             :     // Range of fuelUsed is 0 to 4294967295.
     306           0 :     _pg_user->fuelUsed = uint32FromBeBytes(_pg_data, &_pg_byteindex);
     307             : 
     308           0 :     if(decodeECU_ecuStatusBits_t(_pg_data, &_pg_byteindex, &_pg_user->ecuStatusBits) == 0)
     309           0 :         return 0;
     310             : 
     311           0 :     return 1;
     312             : 
     313             : }// decodeECU_TelemetryFastPacketStructure
     314             : 
     315             : /*!
     316             :  * \brief Create the ECU_TelemetryFast packet
     317             :  *
     318             :  * Fast telemetry contains high priority telemetry data and is transmitted at a
     319             :  * user configurable period between 50ms (20Hz) and 10s. By default, the fast
     320             :  * telemetry message is transmitted at 10Hz (every 100ms)
     321             :  * \param _pg_pkt points to the packet which will be created by this function
     322             :  * \param throttle is Throttle signal (0 to 100%)
     323             :  * \param rpm is Engine speed in revolutions per minute
     324             :  * \param fuelUsed is Fuel used in grams
     325             :  * \param ecuStatusBits is 
     326             :  */
     327           0 : void encodeECU_TelemetryFastPacket(void* _pg_pkt, float throttle, uint16_t rpm, uint32_t fuelUsed, const ECU_ecuStatusBits_t* ecuStatusBits)
     328             : {
     329           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
     330           0 :     int _pg_byteindex = 0;
     331             : 
     332             :     // Throttle signal (0 to 100%)
     333             :     // Range of throttle is 0.0f to 100.0f.
     334           0 :     float32ScaledTo1UnsignedBytes(throttle, _pg_data, &_pg_byteindex, 0.0f, 2.55f);
     335             : 
     336             :     // Engine speed in revolutions per minute
     337             :     // Range of rpm is 0 to 65535.
     338           0 :     uint16ToBeBytes(rpm, _pg_data, &_pg_byteindex);
     339             : 
     340             :     // Fuel used in grams
     341             :     // Range of fuelUsed is 0 to 4294967295.
     342           0 :     uint32ToBeBytes(fuelUsed, _pg_data, &_pg_byteindex);
     343             : 
     344           0 :     encodeECU_ecuStatusBits_t(_pg_data, &_pg_byteindex, ecuStatusBits);
     345             : 
     346             :     // complete the process of creating the packet
     347           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_TelemetryFastPacketID());
     348             : 
     349           0 : }// encodeECU_TelemetryFastPacket
     350             : 
     351             : /*!
     352             :  * \brief Decode the ECU_TelemetryFast packet
     353             :  *
     354             :  * Fast telemetry contains high priority telemetry data and is transmitted at a
     355             :  * user configurable period between 50ms (20Hz) and 10s. By default, the fast
     356             :  * telemetry message is transmitted at 10Hz (every 100ms)
     357             :  * \param _pg_pkt points to the packet being decoded by this function
     358             :  * \param throttle receives Throttle signal (0 to 100%)
     359             :  * \param rpm receives Engine speed in revolutions per minute
     360             :  * \param fuelUsed receives Fuel used in grams
     361             :  * \param ecuStatusBits receives 
     362             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     363             :  */
     364           0 : int decodeECU_TelemetryFastPacket(const void* _pg_pkt, float* throttle, uint16_t* rpm, uint32_t* fuelUsed, ECU_ecuStatusBits_t* ecuStatusBits)
     365             : {
     366           0 :     int _pg_byteindex = 0;
     367           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
     368           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
     369             : 
     370             :     // Verify the packet identifier
     371           0 :     if(getECUPacketID(_pg_pkt) != getECU_TelemetryFastPacketID())
     372           0 :         return 0;
     373             : 
     374           0 :     if(_pg_numbytes < getECU_TelemetryFastMinDataLength())
     375           0 :         return 0;
     376             : 
     377             :     // Throttle signal (0 to 100%)
     378             :     // Range of throttle is 0.0f to 100.0f.
     379           0 :     (*throttle) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/2.55f);
     380             : 
     381             :     // Engine speed in revolutions per minute
     382             :     // Range of rpm is 0 to 65535.
     383           0 :     (*rpm) = uint16FromBeBytes(_pg_data, &_pg_byteindex);
     384             : 
     385             :     // Fuel used in grams
     386             :     // Range of fuelUsed is 0 to 4294967295.
     387           0 :     (*fuelUsed) = uint32FromBeBytes(_pg_data, &_pg_byteindex);
     388             : 
     389           0 :     if(decodeECU_ecuStatusBits_t(_pg_data, &_pg_byteindex, ecuStatusBits) == 0)
     390           0 :         return 0;
     391             : 
     392           0 :     return 1;
     393             : 
     394             : }// decodeECU_TelemetryFastPacket
     395             : 
     396             : /*!
     397             :  * \brief Create the ECU_TelemetrySlow0 packet
     398             :  *
     399             :  * This is the first of three slower telemetry packets which are transmitted by
     400             :  * the ECU at a user customizable period (between 0.5s and 10.0s). These three
     401             :  * packets contain data that is not likely to change as quickly as the data in
     402             :  * the fast telemetry packet. By default, the slow telemetry messages are
     403             :  * transmitted at 1Hz (period of 1.0s).
     404             :  * \param _pg_pkt points to the packet which will be created by this function
     405             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     406             :  */
     407           0 : void encodeECU_TelemetrySlow0PacketStructure(void* _pg_pkt, const ECU_TelemetrySlow0_t* _pg_user)
     408             : {
     409           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
     410           0 :     int _pg_byteindex = 0;
     411           0 :     unsigned int _pg_tempbitfield = 0;
     412             : 
     413             : 
     414             : 
     415             :     // RPM command in units of 50 RPM
     416           0 :     uint8ToBytes((uint8_t)(0), _pg_data, &_pg_byteindex);
     417             : 
     418             :     // Source of the throttle information
     419           0 :     _pg_data[_pg_byteindex] = (uint8_t)_pg_user->throttleSrc << 4;
     420             : 
     421             :     // Throttle pulse width in microseconds
     422             :     // Range of throttlePulse is 0 to 4095.
     423           0 :     _pg_tempbitfield = (unsigned int)limitMax(_pg_user->throttlePulse, 4095);
     424           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)_pg_tempbitfield;
     425             : 
     426           0 :     _pg_tempbitfield >>= 8;
     427           0 :     _pg_data[_pg_byteindex] |= (uint8_t)_pg_tempbitfield;
     428           0 :     _pg_byteindex += 2; // close bit field
     429             : 
     430             : 
     431             :     // Cylinder head temperature in Celsius
     432             :     // Range of cht is -10.0f to 245.0f.
     433           0 :     float32ScaledTo1UnsignedBytes(_pg_user->cht, _pg_data, &_pg_byteindex, -10.0f, 1.0f);
     434             : 
     435             :     // Low part of RPM command from 0 to 49
     436           0 :     uint8ToBytes((uint8_t)(0), _pg_data, &_pg_byteindex);
     437             : 
     438             :     // Barometric pressure in kilo-Pascals
     439             :     // Range of baro is 0.0f to 131.07f.
     440           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->baro, _pg_data, &_pg_byteindex, 0.0f, 500.0f);
     441             : 
     442             :     // Percentage ratio of manifold pressure to barometric pressure
     443           0 :     uint8ToBytes((uint8_t)(0), _pg_data, &_pg_byteindex);
     444             : 
     445             :     // Reconstruct the RPM command
     446           0 :     _pg_data[0] = (uint8_t)(_pg_user->rpmCmd/50); _pg_data[4] = (uint8_t)(_pg_user->rpmCmd - _pg_data[0]*50);
     447             : 
     448             :     // Reconstruct the manifold pressure
     449           0 :     _pg_data[7] = (uint8_t)(0.5f + 100.0f*_pg_user->map/_pg_user->baro);
     450             : 
     451             :     // complete the process of creating the packet
     452           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_TelemetrySlow0PacketID());
     453             : 
     454           0 : }// encodeECU_TelemetrySlow0PacketStructure
     455             : 
     456             : /*!
     457             :  * \brief Decode the ECU_TelemetrySlow0 packet
     458             :  *
     459             :  * This is the first of three slower telemetry packets which are transmitted by
     460             :  * the ECU at a user customizable period (between 0.5s and 10.0s). These three
     461             :  * packets contain data that is not likely to change as quickly as the data in
     462             :  * the fast telemetry packet. By default, the slow telemetry messages are
     463             :  * transmitted at 1Hz (period of 1.0s).
     464             :  * \param _pg_pkt points to the packet being decoded by this function
     465             :  * \param _pg_user receives the data decoded from the packet
     466             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     467             :  */
     468           0 : int decodeECU_TelemetrySlow0PacketStructure(const void* _pg_pkt, ECU_TelemetrySlow0_t* _pg_user)
     469             : {
     470             :     int _pg_numbytes;
     471           0 :     int _pg_byteindex = 0;
     472             :     const uint8_t* _pg_data;
     473           0 :     unsigned int _pg_tempbitfield = 0;
     474             : 
     475             :     // Verify the packet identifier
     476           0 :     if(getECUPacketID(_pg_pkt) != getECU_TelemetrySlow0PacketID())
     477           0 :         return 0;
     478             : 
     479             :     // Verify the packet size
     480           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
     481           0 :     if(_pg_numbytes < getECU_TelemetrySlow0MinDataLength())
     482           0 :         return 0;
     483             : 
     484             :     // The raw data from the packet
     485           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
     486             : 
     487             :     // RPM command in units of 50 RPM
     488           0 :     _pg_byteindex += 1;
     489             : 
     490             :     // Source of the throttle information
     491           0 :     _pg_user->throttleSrc = (ECUThrottleSource)(_pg_data[_pg_byteindex] >> 4);
     492             : 
     493             :     // Throttle pulse width in microseconds
     494             :     // Range of throttlePulse is 0 to 4095.
     495           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex] & 0xF);
     496             : 
     497           0 :     _pg_tempbitfield <<= 8;
     498           0 :     _pg_tempbitfield |= _pg_data[_pg_byteindex + 1];
     499             : 
     500           0 :     _pg_user->throttlePulse = _pg_tempbitfield;
     501           0 :     _pg_byteindex += 2; // close bit field
     502             : 
     503             :     // Cylinder head temperature in Celsius
     504             :     // Range of cht is -10.0f to 245.0f.
     505           0 :     _pg_user->cht = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -10.0f, 1.0f/1.0f);
     506             : 
     507             :     // Low part of RPM command from 0 to 49
     508           0 :     _pg_byteindex += 1;
     509             : 
     510             :     // Barometric pressure in kilo-Pascals
     511             :     // Range of baro is 0.0f to 131.07f.
     512           0 :     _pg_user->baro = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/500.0f);
     513             : 
     514             :     // Percentage ratio of manifold pressure to barometric pressure
     515           0 :     _pg_byteindex += 1;
     516             : 
     517             :     // Reconstruct the RPM command
     518           0 :     _pg_user->rpmCmd = (uint16_t)(_pg_data[0]*50 + _pg_data[4]);
     519             : 
     520             :     // Reconstruct the manifold pressure
     521           0 :     _pg_user->map = _pg_data[7]*0.01f*_pg_user->baro;
     522             : 
     523           0 :     return 1;
     524             : 
     525             : }// decodeECU_TelemetrySlow0PacketStructure
     526             : 
     527             : /*!
     528             :  * \brief Create the ECU_TelemetrySlow1 packet
     529             :  *
     530             :  * The second of three slow telemetry packets
     531             :  * \param _pg_pkt points to the packet which will be created by this function
     532             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     533             :  */
     534           0 : void encodeECU_TelemetrySlow1PacketStructure(void* _pg_pkt, const ECU_TelemetrySlow1_t* _pg_user)
     535             : {
     536           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
     537           0 :     int _pg_byteindex = 0;
     538             : 
     539             :     // Inlet air temperature in Celsius
     540             :     // Range of mat is -127.0f to 127.0f.
     541           0 :     float32ScaledTo1SignedBytes(_pg_user->mat, _pg_data, &_pg_byteindex, 1.0f);
     542             : 
     543             :     // Fuel pressure in kilo-Pascals
     544             :     // Range of fuelPressure is 0.0f to 1310.7f.
     545           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->fuelPressure, _pg_data, &_pg_byteindex, 0.0f, 50.0f);
     546             : 
     547             :     // Engine run time in seconds.
     548             :     // Range of hobbs is 0 to 16777215.
     549           0 :     uint24ToBeBytes((uint32_t)(limitMax(_pg_user->hobbs, 16777215)), _pg_data, &_pg_byteindex);
     550             : 
     551             :     // Input voltage in Volts
     552             :     // Range of voltage is 0.0f to 25.5f.
     553           0 :     float32ScaledTo1UnsignedBytes(_pg_user->voltage, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
     554             : 
     555           0 :     _pg_data[_pg_byteindex] = 0;
     556             : 
     557             :     // Operational mode of the governor
     558           0 :     _pg_data[_pg_byteindex] |= (uint8_t)_pg_user->governorMode;
     559           0 :     _pg_byteindex += 1; // close bit field
     560             : 
     561             :     // complete the process of creating the packet
     562           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_TelemetrySlow1PacketID());
     563             : 
     564           0 : }// encodeECU_TelemetrySlow1PacketStructure
     565             : 
     566             : /*!
     567             :  * \brief Decode the ECU_TelemetrySlow1 packet
     568             :  *
     569             :  * The second of three slow telemetry packets
     570             :  * \param _pg_pkt points to the packet being decoded by this function
     571             :  * \param _pg_user receives the data decoded from the packet
     572             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     573             :  */
     574           0 : int decodeECU_TelemetrySlow1PacketStructure(const void* _pg_pkt, ECU_TelemetrySlow1_t* _pg_user)
     575             : {
     576             :     int _pg_numbytes;
     577           0 :     int _pg_byteindex = 0;
     578             :     const uint8_t* _pg_data;
     579             : 
     580             :     // Verify the packet identifier
     581           0 :     if(getECUPacketID(_pg_pkt) != getECU_TelemetrySlow1PacketID())
     582           0 :         return 0;
     583             : 
     584             :     // Verify the packet size
     585           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
     586           0 :     if(_pg_numbytes < getECU_TelemetrySlow1MinDataLength())
     587           0 :         return 0;
     588             : 
     589             :     // The raw data from the packet
     590           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
     591             : 
     592             :     // Inlet air temperature in Celsius
     593             :     // Range of mat is -127.0f to 127.0f.
     594           0 :     _pg_user->mat = float32ScaledFrom1SignedBytes(_pg_data, &_pg_byteindex, 1.0f/1.0f);
     595             : 
     596             :     // Fuel pressure in kilo-Pascals
     597             :     // Range of fuelPressure is 0.0f to 1310.7f.
     598           0 :     _pg_user->fuelPressure = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/50.0f);
     599             : 
     600             :     // Engine run time in seconds.
     601             :     // Range of hobbs is 0 to 16777215.
     602           0 :     _pg_user->hobbs = (uint32_t)uint24FromBeBytes(_pg_data, &_pg_byteindex);
     603             : 
     604             :     // Input voltage in Volts
     605             :     // Range of voltage is 0.0f to 25.5f.
     606           0 :     _pg_user->voltage = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
     607             : 
     608             :     // Operational mode of the governor
     609           0 :     _pg_user->governorMode = (ECUGovernorMode)((_pg_data[_pg_byteindex]) & 0x7);
     610           0 :     _pg_byteindex += 1; // close bit field
     611             : 
     612           0 :     return 1;
     613             : 
     614             : }// decodeECU_TelemetrySlow1PacketStructure
     615             : 
     616             : /*!
     617             :  * \brief Create the ECU_TelemetrySlow2 packet
     618             :  *
     619             :  * The third of three slow telemetry packets
     620             :  * \param _pg_pkt points to the packet which will be created by this function
     621             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     622             :  */
     623           0 : void encodeECU_TelemetrySlow2PacketStructure(void* _pg_pkt, const ECU_TelemetrySlow2_t* _pg_user)
     624             : {
     625           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
     626           0 :     int _pg_byteindex = 0;
     627             : 
     628             :     // CPU load in percent
     629             :     // Range of cpuLoad is 0.0f to 255.0f.
     630           0 :     float32ScaledTo1UnsignedBytes(_pg_user->cpuLoad, _pg_data, &_pg_byteindex, 0.0f, 1.0f);
     631             : 
     632             :     // Charge temperature in Celsius
     633             :     // Range of chargeTemp is -128.0f to 254.5f.
     634           0 :     float32ScaledTo1UnsignedBytes(_pg_user->chargeTemp, _pg_data, &_pg_byteindex, -128.0f, 0.666666667f);
     635             : 
     636             :     // Injector duty cycle in percent
     637             :     // Range of injectorDuty is 0.0f to 6553.5f.
     638           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->injectorDuty, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
     639             : 
     640             :     // First ignition advance angle in degrees
     641             :     // Range of ignAngle1 is 0.0f to 127.5f.
     642           0 :     float32ScaledTo1UnsignedBytes(_pg_user->ignAngle1, _pg_data, &_pg_byteindex, 0.0f, 2.0f);
     643             : 
     644             :     // Second ignition advance angle in degrees
     645             :     // Range of ignAngle2 is 0.0f to 127.5f.
     646           0 :     float32ScaledTo1UnsignedBytes(_pg_user->ignAngle2, _pg_data, &_pg_byteindex, 0.0f, 2.0f);
     647             : 
     648             :     // Fuel flow rate in grams per minute
     649             :     // Range of flowRate is 0.0f to 1092.25f.
     650           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->flowRate, _pg_data, &_pg_byteindex, 0.0f, 60.0f);
     651             : 
     652             :     // complete the process of creating the packet
     653           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_TelemetrySlow2PacketID());
     654             : 
     655           0 : }// encodeECU_TelemetrySlow2PacketStructure
     656             : 
     657             : /*!
     658             :  * \brief Decode the ECU_TelemetrySlow2 packet
     659             :  *
     660             :  * The third of three slow telemetry packets
     661             :  * \param _pg_pkt points to the packet being decoded by this function
     662             :  * \param _pg_user receives the data decoded from the packet
     663             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     664             :  */
     665           0 : int decodeECU_TelemetrySlow2PacketStructure(const void* _pg_pkt, ECU_TelemetrySlow2_t* _pg_user)
     666             : {
     667             :     int _pg_numbytes;
     668           0 :     int _pg_byteindex = 0;
     669             :     const uint8_t* _pg_data;
     670             : 
     671             :     // Verify the packet identifier
     672           0 :     if(getECUPacketID(_pg_pkt) != getECU_TelemetrySlow2PacketID())
     673           0 :         return 0;
     674             : 
     675             :     // Verify the packet size
     676           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
     677           0 :     if(_pg_numbytes < getECU_TelemetrySlow2MinDataLength())
     678           0 :         return 0;
     679             : 
     680             :     // The raw data from the packet
     681           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
     682             : 
     683             :     // CPU load in percent
     684             :     // Range of cpuLoad is 0.0f to 255.0f.
     685           0 :     _pg_user->cpuLoad = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1.0f);
     686             : 
     687             :     // Charge temperature in Celsius
     688             :     // Range of chargeTemp is -128.0f to 254.5f.
     689           0 :     _pg_user->chargeTemp = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -128.0f, 1.0f/0.666666667f);
     690             : 
     691             :     // Injector duty cycle in percent
     692             :     // Range of injectorDuty is 0.0f to 6553.5f.
     693           0 :     _pg_user->injectorDuty = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
     694             : 
     695             :     // First ignition advance angle in degrees
     696             :     // Range of ignAngle1 is 0.0f to 127.5f.
     697           0 :     _pg_user->ignAngle1 = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/2.0f);
     698             : 
     699             :     // Second ignition advance angle in degrees
     700             :     // Range of ignAngle2 is 0.0f to 127.5f.
     701           0 :     _pg_user->ignAngle2 = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/2.0f);
     702             : 
     703             :     // Fuel flow rate in grams per minute
     704             :     // Range of flowRate is 0.0f to 1092.25f.
     705           0 :     _pg_user->flowRate = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/60.0f);
     706             : 
     707           0 :     return 1;
     708             : 
     709             : }// decodeECU_TelemetrySlow2PacketStructure
     710             : 
     711             : /*!
     712             :  * \brief Create the ECU_HardwareConfig packet
     713             :  *
     714             :  * The hardware config packet contains the ECU serial number and various ECU
     715             :  * configuration data. Send a zero length packet to request this data.
     716             :  * \param _pg_pkt points to the packet which will be created by this function
     717             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     718             :  */
     719           0 : void encodeECU_HardwareConfigPacketStructure(void* _pg_pkt, const ECU_HardwareConfig_t* _pg_user)
     720             : {
     721           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
     722           0 :     int _pg_byteindex = 0;
     723             : 
     724             :     // ECU serial number
     725             :     // Range of serialNumber is 0 to 65535.
     726           0 :     uint16ToBeBytes(_pg_user->serialNumber, _pg_data, &_pg_byteindex);
     727             : 
     728             :     // Fuel used divisior. If the divisor is greater than 100 then it is interpreted as units of 0.01 (for a higher resolution fuel calibration)
     729             :     // Range of fuelDivisor is 0 to 65535.
     730           0 :     uint16ToBeBytes(_pg_user->fuelDivisor, _pg_data, &_pg_byteindex);
     731             : 
     732           0 :     _pg_data[_pg_byteindex] = 0;
     733             : 
     734             :     // Autronic relay state. This is a volatile status which will reset to AUT_RELAY_OFF on ECU power cycle.
     735           0 :     _pg_data[_pg_byteindex] |= (uint8_t)_pg_user->relayState << 1;
     736             : 
     737             :     // Set if the fuel used value is reset each on each ECU power cycle
     738           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->resetFuelUsedOnStart == true) ? 1 : 0);
     739           0 :     _pg_byteindex += 1; // close bit field
     740             : 
     741             :     // complete the process of creating the packet
     742           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_HardwareConfigPacketID());
     743             : 
     744           0 : }// encodeECU_HardwareConfigPacketStructure
     745             : 
     746             : /*!
     747             :  * \brief Decode the ECU_HardwareConfig packet
     748             :  *
     749             :  * The hardware config packet contains the ECU serial number and various ECU
     750             :  * configuration data. Send a zero length packet to request this data.
     751             :  * \param _pg_pkt points to the packet being decoded by this function
     752             :  * \param _pg_user receives the data decoded from the packet
     753             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     754             :  */
     755           0 : int decodeECU_HardwareConfigPacketStructure(const void* _pg_pkt, ECU_HardwareConfig_t* _pg_user)
     756             : {
     757             :     int _pg_numbytes;
     758           0 :     int _pg_byteindex = 0;
     759             :     const uint8_t* _pg_data;
     760             : 
     761             :     // Verify the packet identifier
     762           0 :     if(getECUPacketID(_pg_pkt) != getECU_HardwareConfigPacketID())
     763           0 :         return 0;
     764             : 
     765             :     // Verify the packet size
     766           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
     767           0 :     if(_pg_numbytes < getECU_HardwareConfigMinDataLength())
     768           0 :         return 0;
     769             : 
     770             :     // The raw data from the packet
     771           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
     772             : 
     773             :     // ECU serial number
     774             :     // Range of serialNumber is 0 to 65535.
     775           0 :     _pg_user->serialNumber = uint16FromBeBytes(_pg_data, &_pg_byteindex);
     776             : 
     777             :     // Fuel used divisior. If the divisor is greater than 100 then it is interpreted as units of 0.01 (for a higher resolution fuel calibration)
     778             :     // Range of fuelDivisor is 0 to 65535.
     779           0 :     _pg_user->fuelDivisor = uint16FromBeBytes(_pg_data, &_pg_byteindex);
     780             : 
     781             :     // Autronic relay state. This is a volatile status which will reset to AUT_RELAY_OFF on ECU power cycle.
     782           0 :     _pg_user->relayState = (ECUAutronicRelayState)((_pg_data[_pg_byteindex] >> 1) & 0x3);
     783             : 
     784             :     // Set if the fuel used value is reset each on each ECU power cycle
     785           0 :     _pg_user->resetFuelUsedOnStart = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
     786           0 :     _pg_byteindex += 1; // close bit field
     787             : 
     788           0 :     return 1;
     789             : 
     790             : }// decodeECU_HardwareConfigPacketStructure
     791             : 
     792             : /*!
     793             :  * \brief Create the ECU_Version packet
     794             :  *
     795             :  * The software version packet contains the auxiliary processor firmware
     796             :  * version information. Send a zero length packet to request this data.
     797             :  * \param _pg_pkt points to the packet which will be created by this function
     798             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     799             :  */
     800           0 : void encodeECU_VersionPacketStructure(void* _pg_pkt, const ECU_Version_t* _pg_user)
     801             : {
     802           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
     803           0 :     int _pg_byteindex = 0;
     804             : 
     805             :     // 1 = Release version, 0 = Testing version
     806           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->release == true) ? 1 : 0) << 7;
     807             : 
     808             :     // Reserved for future use
     809             : 
     810             :     // Major version number
     811             :     // Range of versionMajor is 0 to 63.
     812           0 :     _pg_data[_pg_byteindex] |= (uint8_t)_pg_user->versionMajor;
     813           0 :     _pg_byteindex += 1; // close bit field
     814             : 
     815             : 
     816             :     // Minor version number
     817             :     // Range of versionMinor is 0 to 255.
     818           0 :     uint8ToBytes(_pg_user->versionMinor, _pg_data, &_pg_byteindex);
     819             : 
     820             :     // Revision number
     821             :     // Range of versionRev is 0 to 15.
     822           0 :     _pg_data[_pg_byteindex] = (uint8_t)limitMax(_pg_user->versionRev, 15) << 4;
     823             : 
     824             :     // The release month from 1 (January) to 12 (December)
     825             :     // Range of month is 0 to 15.
     826           0 :     _pg_data[_pg_byteindex] |= (uint8_t)limitMax(_pg_user->month, 15);
     827           0 :     _pg_byteindex += 1; // close bit field
     828             : 
     829             : 
     830             :     // The release day of month from 1 to 31
     831             :     // Range of day is 0 to 255.
     832           0 :     uint8ToBytes(_pg_user->day, _pg_data, &_pg_byteindex);
     833             : 
     834             :     // The release year
     835             :     // Range of year is 0 to 65535.
     836           0 :     uint16ToBeBytes(_pg_user->year, _pg_data, &_pg_byteindex);
     837             : 
     838             :     // Firmware checksum
     839             :     // Range of checksum is 0 to 65535.
     840           0 :     uint16ToBeBytes(_pg_user->checksum, _pg_data, &_pg_byteindex);
     841             : 
     842             :     // complete the process of creating the packet
     843           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_VersionPacketID());
     844             : 
     845           0 : }// encodeECU_VersionPacketStructure
     846             : 
     847             : /*!
     848             :  * \brief Decode the ECU_Version packet
     849             :  *
     850             :  * The software version packet contains the auxiliary processor firmware
     851             :  * version information. Send a zero length packet to request this data.
     852             :  * \param _pg_pkt points to the packet being decoded by this function
     853             :  * \param _pg_user receives the data decoded from the packet
     854             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     855             :  */
     856           0 : int decodeECU_VersionPacketStructure(const void* _pg_pkt, ECU_Version_t* _pg_user)
     857             : {
     858             :     int _pg_numbytes;
     859           0 :     int _pg_byteindex = 0;
     860             :     const uint8_t* _pg_data;
     861             : 
     862             :     // Verify the packet identifier
     863           0 :     if(getECUPacketID(_pg_pkt) != getECU_VersionPacketID())
     864           0 :         return 0;
     865             : 
     866             :     // Verify the packet size
     867           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
     868           0 :     if(_pg_numbytes < getECU_VersionMinDataLength())
     869           0 :         return 0;
     870             : 
     871             :     // The raw data from the packet
     872           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
     873             : 
     874             :     // 1 = Release version, 0 = Testing version
     875           0 :     _pg_user->release = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
     876             : 
     877             :     // Reserved for future use
     878             : 
     879             :     // Major version number
     880             :     // Range of versionMajor is 0 to 63.
     881           0 :     _pg_user->versionMajor = ((_pg_data[_pg_byteindex]) & 0x3F);
     882           0 :     _pg_byteindex += 1; // close bit field
     883             : 
     884             :     // Minor version number
     885             :     // Range of versionMinor is 0 to 255.
     886           0 :     _pg_user->versionMinor = uint8FromBytes(_pg_data, &_pg_byteindex);
     887             : 
     888             :     // Revision number
     889             :     // Range of versionRev is 0 to 15.
     890           0 :     _pg_user->versionRev = (_pg_data[_pg_byteindex] >> 4);
     891             : 
     892             :     // The release month from 1 (January) to 12 (December)
     893             :     // Range of month is 0 to 15.
     894           0 :     _pg_user->month = ((_pg_data[_pg_byteindex]) & 0xF);
     895           0 :     _pg_byteindex += 1; // close bit field
     896             : 
     897             :     // The release day of month from 1 to 31
     898             :     // Range of day is 0 to 255.
     899           0 :     _pg_user->day = uint8FromBytes(_pg_data, &_pg_byteindex);
     900             : 
     901             :     // The release year
     902             :     // Range of year is 0 to 65535.
     903           0 :     _pg_user->year = uint16FromBeBytes(_pg_data, &_pg_byteindex);
     904             : 
     905             :     // Firmware checksum
     906             :     // Range of checksum is 0 to 65535.
     907           0 :     _pg_user->checksum = uint16FromBeBytes(_pg_data, &_pg_byteindex);
     908             : 
     909           0 :     return 1;
     910             : 
     911             : }// decodeECU_VersionPacketStructure
     912             : 
     913             : /*!
     914             :  * \brief Create the ECU_Errors packet
     915             :  *
     916             :  * The errors packet contains error status information for the ECU. If any
     917             :  * error bits are set, then the global error bit in the [fast
     918             :  * telemetry](#PKT_ECU_TELEMETRY_FAST) packet will also be set. Send a zero
     919             :  * length packet to request this data.
     920             :  * \param _pg_pkt points to the packet which will be created by this function
     921             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     922             :  */
     923           0 : void encodeECU_ErrorsPacketStructure(void* _pg_pkt, const ECU_Errors_t* _pg_user)
     924             : {
     925           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
     926           0 :     int _pg_byteindex = 0;
     927             : 
     928             :     // Error bits for the Autronic processor
     929           0 :     encodeECU_AutronicErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->autronicErrors);
     930             : 
     931             :     // Error bits for the auxiliary processor
     932           0 :     encodeECU_AuxiliaryErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->auxiliaryErrors);
     933             : 
     934             :     // complete the process of creating the packet
     935           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_ErrorsPacketID());
     936             : 
     937           0 : }// encodeECU_ErrorsPacketStructure
     938             : 
     939             : /*!
     940             :  * \brief Decode the ECU_Errors packet
     941             :  *
     942             :  * The errors packet contains error status information for the ECU. If any
     943             :  * error bits are set, then the global error bit in the [fast
     944             :  * telemetry](#PKT_ECU_TELEMETRY_FAST) packet will also be set. Send a zero
     945             :  * length packet to request this data.
     946             :  * \param _pg_pkt points to the packet being decoded by this function
     947             :  * \param _pg_user receives the data decoded from the packet
     948             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     949             :  */
     950           0 : int decodeECU_ErrorsPacketStructure(const void* _pg_pkt, ECU_Errors_t* _pg_user)
     951             : {
     952             :     int _pg_numbytes;
     953           0 :     int _pg_byteindex = 0;
     954             :     const uint8_t* _pg_data;
     955             : 
     956             :     // Verify the packet identifier
     957           0 :     if(getECUPacketID(_pg_pkt) != getECU_ErrorsPacketID())
     958           0 :         return 0;
     959             : 
     960             :     // Verify the packet size
     961           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
     962           0 :     if(_pg_numbytes < getECU_ErrorsMinDataLength())
     963           0 :         return 0;
     964             : 
     965             :     // The raw data from the packet
     966           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
     967             : 
     968             :     // Error bits for the Autronic processor
     969           0 :     if(decodeECU_AutronicErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->autronicErrors) == 0)
     970           0 :         return 0;
     971             : 
     972             :     // Error bits for the auxiliary processor
     973           0 :     if(decodeECU_AuxiliaryErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->auxiliaryErrors) == 0)
     974           0 :         return 0;
     975             : 
     976           0 :     return 1;
     977             : 
     978             : }// decodeECU_ErrorsPacketStructure
     979             : 
     980             : /*!
     981             :  * \brief Create the ECU_PowerCycles packet
     982             :  *
     983             :  * The power cycles packet contains information on the reset condition of the
     984             :  * ECU. Send a zero length packet to request this data.
     985             :  * \param _pg_pkt points to the packet which will be created by this function
     986             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     987             :  */
     988           0 : void encodeECU_PowerCyclesPacketStructure(void* _pg_pkt, const ECU_PowerCycles_t* _pg_user)
     989             : {
     990           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
     991           0 :     int _pg_byteindex = 0;
     992             : 
     993             :     // Number of power cycles
     994             :     // Range of powerCycles is 0 to 65535.
     995           0 :     uint16ToBeBytes(_pg_user->powerCycles, _pg_data, &_pg_byteindex);
     996             : 
     997             :     // Range of reserved is 0 to 255.
     998           0 :     uint8ToBytes(_pg_user->reserved, _pg_data, &_pg_byteindex);
     999             : 
    1000             :     // Auxiliary processor reset code
    1001             :     // Range of resetCode is 0 to 255.
    1002           0 :     uint8ToBytes(_pg_user->resetCode, _pg_data, &_pg_byteindex);
    1003             : 
    1004             :     // Milliseconds since system reset
    1005             :     // Range of systemTime is 0 to 4294967295.
    1006           0 :     uint32ToBeBytes(_pg_user->systemTime, _pg_data, &_pg_byteindex);
    1007             : 
    1008             :     // complete the process of creating the packet
    1009           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_PowerCyclesPacketID());
    1010             : 
    1011           0 : }// encodeECU_PowerCyclesPacketStructure
    1012             : 
    1013             : /*!
    1014             :  * \brief Decode the ECU_PowerCycles packet
    1015             :  *
    1016             :  * The power cycles packet contains information on the reset condition of the
    1017             :  * ECU. Send a zero length packet to request this data.
    1018             :  * \param _pg_pkt points to the packet being decoded by this function
    1019             :  * \param _pg_user receives the data decoded from the packet
    1020             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1021             :  */
    1022           0 : int decodeECU_PowerCyclesPacketStructure(const void* _pg_pkt, ECU_PowerCycles_t* _pg_user)
    1023             : {
    1024             :     int _pg_numbytes;
    1025           0 :     int _pg_byteindex = 0;
    1026             :     const uint8_t* _pg_data;
    1027             : 
    1028             :     // Verify the packet identifier
    1029           0 :     if(getECUPacketID(_pg_pkt) != getECU_PowerCyclesPacketID())
    1030           0 :         return 0;
    1031             : 
    1032             :     // Verify the packet size
    1033           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    1034           0 :     if(_pg_numbytes < getECU_PowerCyclesMinDataLength())
    1035           0 :         return 0;
    1036             : 
    1037             :     // The raw data from the packet
    1038           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    1039             : 
    1040             :     // Number of power cycles
    1041             :     // Range of powerCycles is 0 to 65535.
    1042           0 :     _pg_user->powerCycles = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1043             : 
    1044             :     // Range of reserved is 0 to 255.
    1045           0 :     _pg_user->reserved = uint8FromBytes(_pg_data, &_pg_byteindex);
    1046             : 
    1047             :     // Auxiliary processor reset code
    1048             :     // Range of resetCode is 0 to 255.
    1049           0 :     _pg_user->resetCode = uint8FromBytes(_pg_data, &_pg_byteindex);
    1050             : 
    1051             :     // Milliseconds since system reset
    1052             :     // Range of systemTime is 0 to 4294967295.
    1053           0 :     _pg_user->systemTime = uint32FromBeBytes(_pg_data, &_pg_byteindex);
    1054             : 
    1055           0 :     return 1;
    1056             : 
    1057             : }// decodeECU_PowerCyclesPacketStructure
    1058             : 
    1059             : /*!
    1060             :  * \brief Create the ECU_PumpDebug packet
    1061             :  *
    1062             :  * The fuel pump debug packet contains information on the pump control system.
    1063             :  * Send a zero length packet to request this data.
    1064             :  * \param _pg_pkt points to the packet which will be created by this function
    1065             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1066             :  */
    1067           0 : void encodeECU_PumpDebugPacketStructure(void* _pg_pkt, const ECU_PumpDebug_t* _pg_user)
    1068             : {
    1069           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1070           0 :     int _pg_byteindex = 0;
    1071             : 
    1072             :     // Proportional term of the pump feedback control in percent
    1073             :     // Range of pTerm is -3276.7f to 3276.7f.
    1074           0 :     float32ScaledTo2SignedBeBytes(_pg_user->pTerm, _pg_data, &_pg_byteindex, 10.0f);
    1075             : 
    1076             :     // Integral term of the pump feedback control in percent
    1077             :     // Range of iTerm is -3276.7f to 3276.7f.
    1078           0 :     float32ScaledTo2SignedBeBytes(_pg_user->iTerm, _pg_data, &_pg_byteindex, 10.0f);
    1079             : 
    1080             :     // Pump duty cycle in percent
    1081             :     // Range of dutyCycle is 0.0f to 6553.5f.
    1082           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->dutyCycle, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    1083             : 
    1084             :     // Fuel pressure in kilo-Pascals
    1085             :     // Range of fuelPressure is 0.0f to 1310.7f.
    1086           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->fuelPressure, _pg_data, &_pg_byteindex, 0.0f, 50.0f);
    1087             : 
    1088             :     // complete the process of creating the packet
    1089           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_PumpDebugPacketID());
    1090             : 
    1091           0 : }// encodeECU_PumpDebugPacketStructure
    1092             : 
    1093             : /*!
    1094             :  * \brief Decode the ECU_PumpDebug packet
    1095             :  *
    1096             :  * The fuel pump debug packet contains information on the pump control system.
    1097             :  * Send a zero length packet to request this data.
    1098             :  * \param _pg_pkt points to the packet being decoded by this function
    1099             :  * \param _pg_user receives the data decoded from the packet
    1100             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1101             :  */
    1102           0 : int decodeECU_PumpDebugPacketStructure(const void* _pg_pkt, ECU_PumpDebug_t* _pg_user)
    1103             : {
    1104             :     int _pg_numbytes;
    1105           0 :     int _pg_byteindex = 0;
    1106             :     const uint8_t* _pg_data;
    1107             : 
    1108             :     // Verify the packet identifier
    1109           0 :     if(getECUPacketID(_pg_pkt) != getECU_PumpDebugPacketID())
    1110           0 :         return 0;
    1111             : 
    1112             :     // Verify the packet size
    1113           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    1114           0 :     if(_pg_numbytes < getECU_PumpDebugMinDataLength())
    1115           0 :         return 0;
    1116             : 
    1117             :     // The raw data from the packet
    1118           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    1119             : 
    1120             :     // Proportional term of the pump feedback control in percent
    1121             :     // Range of pTerm is -3276.7f to 3276.7f.
    1122           0 :     _pg_user->pTerm = float32ScaledFrom2SignedBeBytes(_pg_data, &_pg_byteindex, 1.0f/10.0f);
    1123             : 
    1124             :     // Integral term of the pump feedback control in percent
    1125             :     // Range of iTerm is -3276.7f to 3276.7f.
    1126           0 :     _pg_user->iTerm = float32ScaledFrom2SignedBeBytes(_pg_data, &_pg_byteindex, 1.0f/10.0f);
    1127             : 
    1128             :     // Pump duty cycle in percent
    1129             :     // Range of dutyCycle is 0.0f to 6553.5f.
    1130           0 :     _pg_user->dutyCycle = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    1131             : 
    1132             :     // Fuel pressure in kilo-Pascals
    1133             :     // Range of fuelPressure is 0.0f to 1310.7f.
    1134           0 :     _pg_user->fuelPressure = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/50.0f);
    1135             : 
    1136           0 :     return 1;
    1137             : 
    1138             : }// decodeECU_PumpDebugPacketStructure
    1139             : 
    1140             : /*!
    1141             :  * \brief Create the ECU_TotalEngineTime packet
    1142             :  *
    1143             :  * While the engine time contained in the ECU telemetry packet can be reset by
    1144             :  * the user, the ECU also stores the total engine time, which cannot be reset
    1145             :  * by the user. Send a zero length packet to request this data.
    1146             :  * \param _pg_pkt points to the packet which will be created by this function
    1147             :  * \param hobbs is Total engine run time in seconds
    1148             :  */
    1149           0 : void encodeECU_TotalEngineTimePacket(void* _pg_pkt, uint32_t hobbs)
    1150             : {
    1151           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1152           0 :     int _pg_byteindex = 0;
    1153             : 
    1154             :     // Total engine run time in seconds
    1155             :     // Range of hobbs is 0 to 16777215.
    1156           0 :     uint24ToBeBytes((uint32_t)(limitMax(hobbs, 16777215)), _pg_data, &_pg_byteindex);
    1157             : 
    1158             :     // complete the process of creating the packet
    1159           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_TotalEngineTimePacketID());
    1160             : 
    1161           0 : }// encodeECU_TotalEngineTimePacket
    1162             : 
    1163             : /*!
    1164             :  * \brief Decode the ECU_TotalEngineTime packet
    1165             :  *
    1166             :  * While the engine time contained in the ECU telemetry packet can be reset by
    1167             :  * the user, the ECU also stores the total engine time, which cannot be reset
    1168             :  * by the user. Send a zero length packet to request this data.
    1169             :  * \param _pg_pkt points to the packet being decoded by this function
    1170             :  * \param hobbs receives Total engine run time in seconds
    1171             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1172             :  */
    1173           0 : int decodeECU_TotalEngineTimePacket(const void* _pg_pkt, uint32_t* hobbs)
    1174             : {
    1175           0 :     int _pg_byteindex = 0;
    1176           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    1177           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    1178             : 
    1179             :     // Verify the packet identifier
    1180           0 :     if(getECUPacketID(_pg_pkt) != getECU_TotalEngineTimePacketID())
    1181           0 :         return 0;
    1182             : 
    1183           0 :     if(_pg_numbytes < getECU_TotalEngineTimeMinDataLength())
    1184           0 :         return 0;
    1185             : 
    1186             :     // Total engine run time in seconds
    1187             :     // Range of hobbs is 0 to 16777215.
    1188           0 :     (*hobbs) = (uint32_t)uint24FromBeBytes(_pg_data, &_pg_byteindex);
    1189             : 
    1190           0 :     return 1;
    1191             : 
    1192             : }// decodeECU_TotalEngineTimePacket
    1193             : 
    1194             : /*!
    1195             :  * \brief Create the ECU_eepromSettings packet
    1196             :  *
    1197             :  * The eeprom settings packet contains information on the non-volatile ECU
    1198             :  * settings stored in eeprom. In particular, it provides a checksum of the
    1199             :  * settings data for easy comparison of settings between different ECUs. Send a
    1200             :  * zero length packet to request this data.
    1201             :  * \param _pg_pkt points to the packet which will be created by this function
    1202             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1203             :  */
    1204           0 : void encodeECU_eepromSettingsPacketStructure(void* _pg_pkt, const ECU_eepromSettings_t* _pg_user)
    1205             : {
    1206           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1207           0 :     int _pg_byteindex = 0;
    1208             : 
    1209             :     // Version of the EEPROM data
    1210             :     // Range of eepromVersion is 0 to 255.
    1211           0 :     uint8ToBytes(_pg_user->eepromVersion, _pg_data, &_pg_byteindex);
    1212             : 
    1213             :     // Number of bytes of the EEPROM data
    1214             :     // Range of eepromSize is 0 to 65535.
    1215           0 :     uint16ToBeBytes(_pg_user->eepromSize, _pg_data, &_pg_byteindex);
    1216             : 
    1217             :     // Fletcher's checksum of the EEPROM data
    1218             :     // Range of eepromChecksum is 0 to 65535.
    1219           0 :     uint16ToBeBytes(_pg_user->eepromChecksum, _pg_data, &_pg_byteindex);
    1220             : 
    1221             :     // ECU compilation options
    1222           0 :     encodeECU_CompileOptions_t(_pg_data, &_pg_byteindex, &_pg_user->compileOptions);
    1223             : 
    1224             :     // complete the process of creating the packet
    1225           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_eepromSettingsPacketID());
    1226             : 
    1227           0 : }// encodeECU_eepromSettingsPacketStructure
    1228             : 
    1229             : /*!
    1230             :  * \brief Decode the ECU_eepromSettings packet
    1231             :  *
    1232             :  * The eeprom settings packet contains information on the non-volatile ECU
    1233             :  * settings stored in eeprom. In particular, it provides a checksum of the
    1234             :  * settings data for easy comparison of settings between different ECUs. Send a
    1235             :  * zero length packet to request this data.
    1236             :  * \param _pg_pkt points to the packet being decoded by this function
    1237             :  * \param _pg_user receives the data decoded from the packet
    1238             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1239             :  */
    1240           0 : int decodeECU_eepromSettingsPacketStructure(const void* _pg_pkt, ECU_eepromSettings_t* _pg_user)
    1241             : {
    1242             :     int _pg_numbytes;
    1243           0 :     int _pg_byteindex = 0;
    1244             :     const uint8_t* _pg_data;
    1245             : 
    1246             :     // Verify the packet identifier
    1247           0 :     if(getECUPacketID(_pg_pkt) != getECU_eepromSettingsPacketID())
    1248           0 :         return 0;
    1249             : 
    1250             :     // Verify the packet size
    1251           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    1252           0 :     if(_pg_numbytes < getECU_eepromSettingsMinDataLength())
    1253           0 :         return 0;
    1254             : 
    1255             :     // The raw data from the packet
    1256           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    1257             : 
    1258             :     // Version of the EEPROM data
    1259             :     // Range of eepromVersion is 0 to 255.
    1260           0 :     _pg_user->eepromVersion = uint8FromBytes(_pg_data, &_pg_byteindex);
    1261             : 
    1262             :     // Number of bytes of the EEPROM data
    1263             :     // Range of eepromSize is 0 to 65535.
    1264           0 :     _pg_user->eepromSize = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1265             : 
    1266             :     // Fletcher's checksum of the EEPROM data
    1267             :     // Range of eepromChecksum is 0 to 65535.
    1268           0 :     _pg_user->eepromChecksum = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1269             : 
    1270             :     // ECU compilation options
    1271           0 :     if(decodeECU_CompileOptions_t(_pg_data, &_pg_byteindex, &_pg_user->compileOptions) == 0)
    1272           0 :         return 0;
    1273             : 
    1274           0 :     return 1;
    1275             : 
    1276             : }// decodeECU_eepromSettingsPacketStructure
    1277             : 
    1278             : /*!
    1279             :  * \brief Create the ECU_eepromSettings packet
    1280             :  *
    1281             :  * The eeprom settings packet contains information on the non-volatile ECU
    1282             :  * settings stored in eeprom. In particular, it provides a checksum of the
    1283             :  * settings data for easy comparison of settings between different ECUs. Send a
    1284             :  * zero length packet to request this data.
    1285             :  * \param _pg_pkt points to the packet which will be created by this function
    1286             :  * \param eepromVersion is Version of the EEPROM data
    1287             :  * \param eepromSize is Number of bytes of the EEPROM data
    1288             :  * \param eepromChecksum is Fletcher's checksum of the EEPROM data
    1289             :  * \param compileOptions is ECU compilation options
    1290             :  */
    1291           0 : void encodeECU_eepromSettingsPacket(void* _pg_pkt, uint8_t eepromVersion, uint16_t eepromSize, uint16_t eepromChecksum, const ECU_CompileOptions_t* compileOptions)
    1292             : {
    1293           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1294           0 :     int _pg_byteindex = 0;
    1295             : 
    1296             :     // Version of the EEPROM data
    1297             :     // Range of eepromVersion is 0 to 255.
    1298           0 :     uint8ToBytes(eepromVersion, _pg_data, &_pg_byteindex);
    1299             : 
    1300             :     // Number of bytes of the EEPROM data
    1301             :     // Range of eepromSize is 0 to 65535.
    1302           0 :     uint16ToBeBytes(eepromSize, _pg_data, &_pg_byteindex);
    1303             : 
    1304             :     // Fletcher's checksum of the EEPROM data
    1305             :     // Range of eepromChecksum is 0 to 65535.
    1306           0 :     uint16ToBeBytes(eepromChecksum, _pg_data, &_pg_byteindex);
    1307             : 
    1308             :     // ECU compilation options
    1309           0 :     encodeECU_CompileOptions_t(_pg_data, &_pg_byteindex, compileOptions);
    1310             : 
    1311             :     // complete the process of creating the packet
    1312           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_eepromSettingsPacketID());
    1313             : 
    1314           0 : }// encodeECU_eepromSettingsPacket
    1315             : 
    1316             : /*!
    1317             :  * \brief Decode the ECU_eepromSettings packet
    1318             :  *
    1319             :  * The eeprom settings packet contains information on the non-volatile ECU
    1320             :  * settings stored in eeprom. In particular, it provides a checksum of the
    1321             :  * settings data for easy comparison of settings between different ECUs. Send a
    1322             :  * zero length packet to request this data.
    1323             :  * \param _pg_pkt points to the packet being decoded by this function
    1324             :  * \param eepromVersion receives Version of the EEPROM data
    1325             :  * \param eepromSize receives Number of bytes of the EEPROM data
    1326             :  * \param eepromChecksum receives Fletcher's checksum of the EEPROM data
    1327             :  * \param compileOptions receives ECU compilation options
    1328             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1329             :  */
    1330           0 : int decodeECU_eepromSettingsPacket(const void* _pg_pkt, uint8_t* eepromVersion, uint16_t* eepromSize, uint16_t* eepromChecksum, ECU_CompileOptions_t* compileOptions)
    1331             : {
    1332           0 :     int _pg_byteindex = 0;
    1333           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    1334           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    1335             : 
    1336             :     // Verify the packet identifier
    1337           0 :     if(getECUPacketID(_pg_pkt) != getECU_eepromSettingsPacketID())
    1338           0 :         return 0;
    1339             : 
    1340           0 :     if(_pg_numbytes < getECU_eepromSettingsMinDataLength())
    1341           0 :         return 0;
    1342             : 
    1343             :     // Version of the EEPROM data
    1344             :     // Range of eepromVersion is 0 to 255.
    1345           0 :     (*eepromVersion) = uint8FromBytes(_pg_data, &_pg_byteindex);
    1346             : 
    1347             :     // Number of bytes of the EEPROM data
    1348             :     // Range of eepromSize is 0 to 65535.
    1349           0 :     (*eepromSize) = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1350             : 
    1351             :     // Fletcher's checksum of the EEPROM data
    1352             :     // Range of eepromChecksum is 0 to 65535.
    1353           0 :     (*eepromChecksum) = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1354             : 
    1355             :     // ECU compilation options
    1356           0 :     if(decodeECU_CompileOptions_t(_pg_data, &_pg_byteindex, compileOptions) == 0)
    1357           0 :         return 0;
    1358             : 
    1359           0 :     return 1;
    1360             : 
    1361             : }// decodeECU_eepromSettingsPacket
    1362             : 
    1363             : /*!
    1364             :  * \brief Create the ECU_CHTLoopSettings packet
    1365             :  *
    1366             :  * Control loop settings for the CHT control loop
    1367             :  * \param _pg_pkt points to the packet which will be created by this function
    1368             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1369             :  */
    1370           0 : void encodeECU_CHTLoopSettingsPacketStructure(void* _pg_pkt, const ECU_CHTLoopSettings_t* _pg_user)
    1371             : {
    1372           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1373           0 :     int _pg_byteindex = 0;
    1374             : 
    1375           0 :     _pg_data[_pg_byteindex] = 0;
    1376             : 
    1377             :     // Filter value for derivative term
    1378             :     // Range of dTermFilter is 0 to 31.
    1379           0 :     _pg_data[_pg_byteindex] |= (uint8_t)limitMax(_pg_user->dTermFilter, 31) << 1;
    1380             : 
    1381             :     // CHT control loop enabled
    1382           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->enabled == true) ? 1 : 0);
    1383           0 :     _pg_byteindex += 1; // close bit field
    1384             : 
    1385             : 
    1386             :     // Target CHT temperature
    1387             :     // Range of targetTemp is 0 to 255.
    1388           0 :     uint8ToBytes(_pg_user->targetTemp, _pg_data, &_pg_byteindex);
    1389             : 
    1390             :     // Proportaional gain Kp
    1391             :     // Range of Kp is 0.0f to 65.535f.
    1392           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Kp, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1393             : 
    1394             :     // Proportaional gain Ki
    1395             :     // Range of Ki is 0.0f to 65.535f.
    1396           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Ki, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1397             : 
    1398             :     // Proportaional gain Kd
    1399             :     // Range of Kd is 0.0f to 65.535f.
    1400           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Kd, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1401             : 
    1402             :     // complete the process of creating the packet
    1403           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_CHTLoopSettingsPacketID());
    1404             : 
    1405           0 : }// encodeECU_CHTLoopSettingsPacketStructure
    1406             : 
    1407             : /*!
    1408             :  * \brief Decode the ECU_CHTLoopSettings packet
    1409             :  *
    1410             :  * Control loop settings for the CHT control loop
    1411             :  * \param _pg_pkt points to the packet being decoded by this function
    1412             :  * \param _pg_user receives the data decoded from the packet
    1413             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1414             :  */
    1415           0 : int decodeECU_CHTLoopSettingsPacketStructure(const void* _pg_pkt, ECU_CHTLoopSettings_t* _pg_user)
    1416             : {
    1417             :     int _pg_numbytes;
    1418           0 :     int _pg_byteindex = 0;
    1419             :     const uint8_t* _pg_data;
    1420             : 
    1421             :     // Verify the packet identifier
    1422           0 :     if(getECUPacketID(_pg_pkt) != getECU_CHTLoopSettingsPacketID())
    1423           0 :         return 0;
    1424             : 
    1425             :     // Verify the packet size
    1426           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    1427           0 :     if(_pg_numbytes < getECU_CHTLoopSettingsMinDataLength())
    1428           0 :         return 0;
    1429             : 
    1430             :     // The raw data from the packet
    1431           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    1432             : 
    1433             :     // Filter value for derivative term
    1434             :     // Range of dTermFilter is 0 to 31.
    1435           0 :     _pg_user->dTermFilter = ((_pg_data[_pg_byteindex] >> 1) & 0x1F);
    1436             : 
    1437             :     // CHT control loop enabled
    1438           0 :     _pg_user->enabled = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
    1439           0 :     _pg_byteindex += 1; // close bit field
    1440             : 
    1441             :     // Target CHT temperature
    1442             :     // Range of targetTemp is 0 to 255.
    1443           0 :     _pg_user->targetTemp = uint8FromBytes(_pg_data, &_pg_byteindex);
    1444             : 
    1445             :     // Proportaional gain Kp
    1446             :     // Range of Kp is 0.0f to 65.535f.
    1447           0 :     _pg_user->Kp = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1448             : 
    1449             :     // Proportaional gain Ki
    1450             :     // Range of Ki is 0.0f to 65.535f.
    1451           0 :     _pg_user->Ki = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1452             : 
    1453             :     // Proportaional gain Kd
    1454             :     // Range of Kd is 0.0f to 65.535f.
    1455           0 :     _pg_user->Kd = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1456             : 
    1457           0 :     return 1;
    1458             : 
    1459             : }// decodeECU_CHTLoopSettingsPacketStructure
    1460             : 
    1461             : /*!
    1462             :  * \brief Create the ECU_CHTLoopSettings packet
    1463             :  *
    1464             :  * Control loop settings for the CHT control loop
    1465             :  * \param _pg_pkt points to the packet which will be created by this function
    1466             :  * \param dTermFilter is Filter value for derivative term
    1467             :  * \param enabled is CHT control loop enabled
    1468             :  * \param targetTemp is Target CHT temperature
    1469             :  * \param Kp is Proportaional gain Kp
    1470             :  * \param Ki is Proportaional gain Ki
    1471             :  * \param Kd is Proportaional gain Kd
    1472             :  */
    1473           0 : void encodeECU_CHTLoopSettingsPacket(void* _pg_pkt, uint8_t dTermFilter, bool enabled, uint8_t targetTemp, float Kp, float Ki, float Kd)
    1474             : {
    1475           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1476           0 :     int _pg_byteindex = 0;
    1477             : 
    1478           0 :     _pg_data[_pg_byteindex] = 0;
    1479             : 
    1480             :     // Filter value for derivative term
    1481             :     // Range of dTermFilter is 0 to 31.
    1482           0 :     _pg_data[_pg_byteindex] |= (uint8_t)limitMax(dTermFilter, 31) << 1;
    1483             : 
    1484             :     // CHT control loop enabled
    1485           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((enabled == true) ? 1 : 0);
    1486           0 :     _pg_byteindex += 1; // close bit field
    1487             : 
    1488             :     // Target CHT temperature
    1489             :     // Range of targetTemp is 0 to 255.
    1490           0 :     uint8ToBytes(targetTemp, _pg_data, &_pg_byteindex);
    1491             : 
    1492             :     // Proportaional gain Kp
    1493             :     // Range of Kp is 0.0f to 65.535f.
    1494           0 :     float32ScaledTo2UnsignedBeBytes(Kp, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1495             : 
    1496             :     // Proportaional gain Ki
    1497             :     // Range of Ki is 0.0f to 65.535f.
    1498           0 :     float32ScaledTo2UnsignedBeBytes(Ki, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1499             : 
    1500             :     // Proportaional gain Kd
    1501             :     // Range of Kd is 0.0f to 65.535f.
    1502           0 :     float32ScaledTo2UnsignedBeBytes(Kd, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1503             : 
    1504             :     // complete the process of creating the packet
    1505           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_CHTLoopSettingsPacketID());
    1506             : 
    1507           0 : }// encodeECU_CHTLoopSettingsPacket
    1508             : 
    1509             : /*!
    1510             :  * \brief Decode the ECU_CHTLoopSettings packet
    1511             :  *
    1512             :  * Control loop settings for the CHT control loop
    1513             :  * \param _pg_pkt points to the packet being decoded by this function
    1514             :  * \param dTermFilter receives Filter value for derivative term
    1515             :  * \param enabled receives CHT control loop enabled
    1516             :  * \param targetTemp receives Target CHT temperature
    1517             :  * \param Kp receives Proportaional gain Kp
    1518             :  * \param Ki receives Proportaional gain Ki
    1519             :  * \param Kd receives Proportaional gain Kd
    1520             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1521             :  */
    1522           0 : int decodeECU_CHTLoopSettingsPacket(const void* _pg_pkt, uint8_t* dTermFilter, bool* enabled, uint8_t* targetTemp, float* Kp, float* Ki, float* Kd)
    1523             : {
    1524           0 :     int _pg_byteindex = 0;
    1525           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    1526           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    1527             : 
    1528             :     // Verify the packet identifier
    1529           0 :     if(getECUPacketID(_pg_pkt) != getECU_CHTLoopSettingsPacketID())
    1530           0 :         return 0;
    1531             : 
    1532           0 :     if(_pg_numbytes < getECU_CHTLoopSettingsMinDataLength())
    1533           0 :         return 0;
    1534             : 
    1535             :     // Filter value for derivative term
    1536             :     // Range of dTermFilter is 0 to 31.
    1537           0 :     (*dTermFilter) = ((_pg_data[_pg_byteindex] >> 1) & 0x1F);
    1538             : 
    1539             :     // CHT control loop enabled
    1540           0 :     (*enabled) = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
    1541           0 :     _pg_byteindex += 1; // close bit field
    1542             : 
    1543             :     // Target CHT temperature
    1544             :     // Range of targetTemp is 0 to 255.
    1545           0 :     (*targetTemp) = uint8FromBytes(_pg_data, &_pg_byteindex);
    1546             : 
    1547             :     // Proportaional gain Kp
    1548             :     // Range of Kp is 0.0f to 65.535f.
    1549           0 :     (*Kp) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1550             : 
    1551             :     // Proportaional gain Ki
    1552             :     // Range of Ki is 0.0f to 65.535f.
    1553           0 :     (*Ki) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1554             : 
    1555             :     // Proportaional gain Kd
    1556             :     // Range of Kd is 0.0f to 65.535f.
    1557           0 :     (*Kd) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1558             : 
    1559           0 :     return 1;
    1560             : 
    1561             : }// decodeECU_CHTLoopSettingsPacket
    1562             : 
    1563             : /*!
    1564             :  * \brief Create the ECU_DualPumpControlTelemetry packet
    1565             :  *
    1566             :  * Dual pump control telemetry. Send a zero-length packet with this identifier
    1567             :  * to the ECU to poll (request) this packet.
    1568             :  * \param _pg_pkt points to the packet which will be created by this function
    1569             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1570             :  */
    1571           0 : void encodeECU_DualPumpControlTelemetryPacketStructure(void* _pg_pkt, const ECU_DualPumpControlTelemetry_t* _pg_user)
    1572             : {
    1573           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1574           0 :     int _pg_byteindex = 0;
    1575             : 
    1576           0 :     uint8ToBytes((uint8_t)(0xBB), _pg_data, &_pg_byteindex);
    1577             : 
    1578             :     // Current pump mode (which pump is running). Refer to the DualFuelPumpMode enumeration.
    1579             :     // Range of mode is 0 to 7.
    1580           0 :     _pg_data[_pg_byteindex] = (uint8_t)limitMax(_pg_user->mode, 7) << 5;
    1581             : 
    1582             :     // Current pump state machine state. Refer to the DualFuelPumpState enumeration.
    1583             :     // Range of state is 0 to 7.
    1584           0 :     _pg_data[_pg_byteindex] |= (uint8_t)limitMax(_pg_user->state, 7) << 2;
    1585           0 :     _pg_byteindex += 1; // close bit field
    1586             : 
    1587             : 
    1588             :     // Time spent in current state
    1589             :     // Range of stateTimer is 0 to 65535.
    1590           0 :     uint16ToBeBytes(_pg_user->stateTimer, _pg_data, &_pg_byteindex);
    1591             : 
    1592             :     // complete the process of creating the packet
    1593           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_DualPumpControlTelemetryPacketID());
    1594             : 
    1595           0 : }// encodeECU_DualPumpControlTelemetryPacketStructure
    1596             : 
    1597             : /*!
    1598             :  * \brief Decode the ECU_DualPumpControlTelemetry packet
    1599             :  *
    1600             :  * Dual pump control telemetry. Send a zero-length packet with this identifier
    1601             :  * to the ECU to poll (request) this packet.
    1602             :  * \param _pg_pkt points to the packet being decoded by this function
    1603             :  * \param _pg_user receives the data decoded from the packet
    1604             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1605             :  */
    1606           0 : int decodeECU_DualPumpControlTelemetryPacketStructure(const void* _pg_pkt, ECU_DualPumpControlTelemetry_t* _pg_user)
    1607             : {
    1608             :     int _pg_numbytes;
    1609           0 :     int _pg_byteindex = 0;
    1610             :     const uint8_t* _pg_data;
    1611             : 
    1612             :     // Verify the packet identifier
    1613           0 :     if(getECUPacketID(_pg_pkt) != getECU_DualPumpControlTelemetryPacketID())
    1614           0 :         return 0;
    1615             : 
    1616             :     // Verify the packet size
    1617           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    1618           0 :     if(_pg_numbytes < getECU_DualPumpControlTelemetryMinDataLength())
    1619           0 :         return 0;
    1620             : 
    1621             :     // The raw data from the packet
    1622           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    1623             : 
    1624           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xBB)
    1625           0 :         return 0;
    1626             : 
    1627             :     // Current pump mode (which pump is running). Refer to the DualFuelPumpMode enumeration.
    1628             :     // Range of mode is 0 to 7.
    1629           0 :     _pg_user->mode = (_pg_data[_pg_byteindex] >> 5);
    1630             : 
    1631             :     // Current pump state machine state. Refer to the DualFuelPumpState enumeration.
    1632             :     // Range of state is 0 to 7.
    1633           0 :     _pg_user->state = ((_pg_data[_pg_byteindex] >> 2) & 0x7);
    1634           0 :     _pg_byteindex += 1; // close bit field
    1635             : 
    1636             :     // Time spent in current state
    1637             :     // Range of stateTimer is 0 to 65535.
    1638           0 :     _pg_user->stateTimer = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1639             : 
    1640           0 :     return 1;
    1641             : 
    1642             : }// decodeECU_DualPumpControlTelemetryPacketStructure
    1643             : 
    1644             : /*!
    1645             :  * \brief Create the ECU_DualPump_SetTelemetryPeriod packet
    1646             :  *
    1647             :  * Set the telemetry period for dual-pump messages
    1648             :  * \param _pg_pkt points to the packet which will be created by this function
    1649             :  * \param period is Telemetry period (0 = Off)
    1650             :  */
    1651           0 : void encodeECU_DualPump_SetTelemetryPeriodPacket(void* _pg_pkt, uint8_t period)
    1652             : {
    1653           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1654           0 :     int _pg_byteindex = 0;
    1655             : 
    1656           0 :     uint8ToBytes((uint8_t)(0xBB), _pg_data, &_pg_byteindex);
    1657             : 
    1658             :     // Telemetry period (0 = Off)
    1659             :     // Range of period is 0 to 255.
    1660           0 :     uint8ToBytes(period, _pg_data, &_pg_byteindex);
    1661             : 
    1662             :     // complete the process of creating the packet
    1663           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_DualPump_SetTelemetryPeriodPacketID());
    1664             : 
    1665           0 : }// encodeECU_DualPump_SetTelemetryPeriodPacket
    1666             : 
    1667             : /*!
    1668             :  * \brief Decode the ECU_DualPump_SetTelemetryPeriod packet
    1669             :  *
    1670             :  * Set the telemetry period for dual-pump messages
    1671             :  * \param _pg_pkt points to the packet being decoded by this function
    1672             :  * \param period receives Telemetry period (0 = Off)
    1673             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1674             :  */
    1675           0 : int decodeECU_DualPump_SetTelemetryPeriodPacket(const void* _pg_pkt, uint8_t* period)
    1676             : {
    1677           0 :     int _pg_byteindex = 0;
    1678           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    1679           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    1680             : 
    1681             :     // Verify the packet identifier
    1682           0 :     if(getECUPacketID(_pg_pkt) != getECU_DualPump_SetTelemetryPeriodPacketID())
    1683           0 :         return 0;
    1684             : 
    1685           0 :     if(_pg_numbytes < getECU_DualPump_SetTelemetryPeriodMinDataLength())
    1686           0 :         return 0;
    1687             : 
    1688           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xBB)
    1689           0 :         return 0;
    1690             : 
    1691             :     // Telemetry period (0 = Off)
    1692             :     // Range of period is 0 to 255.
    1693           0 :     (*period) = uint8FromBytes(_pg_data, &_pg_byteindex);
    1694             : 
    1695           0 :     return 1;
    1696             : 
    1697             : }// decodeECU_DualPump_SetTelemetryPeriodPacket
    1698             : 
    1699             : /*!
    1700             :  * \brief Create the ECU_DualPump_SelectPump packet
    1701             :  *
    1702             :  * Command to manually select a given pump mode.
    1703             :  * \param _pg_pkt points to the packet which will be created by this function
    1704             :  * \param pump is Pump selection (see DualFuelPumpMode enumeration)
    1705             :  */
    1706           0 : void encodeECU_DualPump_SelectPumpPacket(void* _pg_pkt, uint8_t pump)
    1707             : {
    1708           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1709           0 :     int _pg_byteindex = 0;
    1710             : 
    1711           0 :     uint8ToBytes((uint8_t)(0xCC), _pg_data, &_pg_byteindex);
    1712             : 
    1713           0 :     uint8ToBytes((uint8_t)(ECU_DUAL_PUMP_CMD_SET_PUMP), _pg_data, &_pg_byteindex);
    1714             : 
    1715             :     // Pump selection (see DualFuelPumpMode enumeration)
    1716             :     // Range of pump is 0 to 255.
    1717           0 :     uint8ToBytes(pump, _pg_data, &_pg_byteindex);
    1718             : 
    1719             :     // complete the process of creating the packet
    1720           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_DualPump_SelectPumpPacketID());
    1721             : 
    1722           0 : }// encodeECU_DualPump_SelectPumpPacket
    1723             : 
    1724             : /*!
    1725             :  * \brief Decode the ECU_DualPump_SelectPump packet
    1726             :  *
    1727             :  * Command to manually select a given pump mode.
    1728             :  * \param _pg_pkt points to the packet being decoded by this function
    1729             :  * \param pump receives Pump selection (see DualFuelPumpMode enumeration)
    1730             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1731             :  */
    1732           0 : int decodeECU_DualPump_SelectPumpPacket(const void* _pg_pkt, uint8_t* pump)
    1733             : {
    1734           0 :     int _pg_byteindex = 0;
    1735           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    1736           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    1737             : 
    1738             :     // Verify the packet identifier
    1739           0 :     if(getECUPacketID(_pg_pkt) != getECU_DualPump_SelectPumpPacketID())
    1740           0 :         return 0;
    1741             : 
    1742           0 :     if(_pg_numbytes < getECU_DualPump_SelectPumpMinDataLength())
    1743           0 :         return 0;
    1744             : 
    1745           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xCC)
    1746           0 :         return 0;
    1747             : 
    1748           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) ECU_DUAL_PUMP_CMD_SET_PUMP)
    1749           0 :         return 0;
    1750             : 
    1751             :     // Pump selection (see DualFuelPumpMode enumeration)
    1752             :     // Range of pump is 0 to 255.
    1753           0 :     (*pump) = uint8FromBytes(_pg_data, &_pg_byteindex);
    1754             : 
    1755           0 :     return 1;
    1756             : 
    1757             : }// decodeECU_DualPump_SelectPumpPacket
    1758             : 
    1759             : /*!
    1760             :  * \brief Create the ECU_DualPump_TestPump packet
    1761             :  *
    1762             :  * Command to temporarily run a particular pump in test mode. ECU will revert
    1763             :  * to OTHER pump when test expires
    1764             :  * \param _pg_pkt points to the packet which will be created by this function
    1765             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1766             :  */
    1767           0 : void encodeECU_DualPump_TestPumpPacketStructure(void* _pg_pkt, const ECU_DualPump_TestPump_t* _pg_user)
    1768             : {
    1769           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1770           0 :     int _pg_byteindex = 0;
    1771             : 
    1772           0 :     uint8ToBytes((uint8_t)(0xCC), _pg_data, &_pg_byteindex);
    1773             : 
    1774           0 :     uint8ToBytes((uint8_t)(ECU_DUAL_PUMP_CMD_TEST_PUMP), _pg_data, &_pg_byteindex);
    1775             : 
    1776             :     // Pump selection (see DualFuelPumpMode enumeration)
    1777             :     // Range of pump is 0 to 255.
    1778           0 :     uint8ToBytes(_pg_user->pump, _pg_data, &_pg_byteindex);
    1779             : 
    1780             :     // Test timeout
    1781             :     // Range of timeout is 0 to 255.
    1782           0 :     uint8ToBytes(_pg_user->timeout, _pg_data, &_pg_byteindex);
    1783             : 
    1784             :     // complete the process of creating the packet
    1785           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_DualPump_TestPumpPacketID());
    1786             : 
    1787           0 : }// encodeECU_DualPump_TestPumpPacketStructure
    1788             : 
    1789             : /*!
    1790             :  * \brief Decode the ECU_DualPump_TestPump packet
    1791             :  *
    1792             :  * Command to temporarily run a particular pump in test mode. ECU will revert
    1793             :  * to OTHER pump when test expires
    1794             :  * \param _pg_pkt points to the packet being decoded by this function
    1795             :  * \param _pg_user receives the data decoded from the packet
    1796             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1797             :  */
    1798           0 : int decodeECU_DualPump_TestPumpPacketStructure(const void* _pg_pkt, ECU_DualPump_TestPump_t* _pg_user)
    1799             : {
    1800             :     int _pg_numbytes;
    1801           0 :     int _pg_byteindex = 0;
    1802             :     const uint8_t* _pg_data;
    1803             : 
    1804             :     // Verify the packet identifier
    1805           0 :     if(getECUPacketID(_pg_pkt) != getECU_DualPump_TestPumpPacketID())
    1806           0 :         return 0;
    1807             : 
    1808             :     // Verify the packet size
    1809           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    1810           0 :     if(_pg_numbytes < getECU_DualPump_TestPumpMinDataLength())
    1811           0 :         return 0;
    1812             : 
    1813             :     // The raw data from the packet
    1814           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    1815             : 
    1816             :     // this packet has default fields, make sure they are set
    1817           0 :     _pg_user->timeout = 30;
    1818             : 
    1819           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xCC)
    1820           0 :         return 0;
    1821             : 
    1822           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) ECU_DUAL_PUMP_CMD_TEST_PUMP)
    1823           0 :         return 0;
    1824             : 
    1825             :     // Pump selection (see DualFuelPumpMode enumeration)
    1826             :     // Range of pump is 0 to 255.
    1827           0 :     _pg_user->pump = uint8FromBytes(_pg_data, &_pg_byteindex);
    1828             : 
    1829           0 :     if(_pg_byteindex + 1 > _pg_numbytes)
    1830           0 :         return 1;
    1831             : 
    1832             :     // Test timeout
    1833             :     // Range of timeout is 0 to 255.
    1834           0 :     _pg_user->timeout = uint8FromBytes(_pg_data, &_pg_byteindex);
    1835             : 
    1836           0 :     return 1;
    1837             : 
    1838             : }// decodeECU_DualPump_TestPumpPacketStructure
    1839             : 
    1840             : /*!
    1841             :  * \brief Create the ECU_ThrottleCalibration packet
    1842             :  *
    1843             :  * The throttle calibration packet sets the calibration values for minimum and
    1844             :  * maximum throttle position. The ECU uses these values to interpolate the
    1845             :  * throttle command.
    1846             :  * \param _pg_pkt points to the packet which will be created by this function
    1847             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1848             :  */
    1849           0 : void encodeECU_ThrottleCalibrationPacketStructure(void* _pg_pkt, const ECU_ThrottleSettings_t* _pg_user)
    1850             : {
    1851           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1852           0 :     int _pg_byteindex = 0;
    1853           0 :     unsigned int _pg_tempbitfield = 0;
    1854             : 
    1855             :     // Output position for 0% throttle in microseconds
    1856             :     // Range of pulseClosed is 0 to 65535.
    1857           0 :     uint16ToBeBytes(_pg_user->pulseClosed, _pg_data, &_pg_byteindex);
    1858             : 
    1859             :     // Output position for 100% throttle in microseconds
    1860             :     // Range of pulseOpen is 0 to 65535.
    1861           0 :     uint16ToBeBytes(_pg_user->pulseOpen, _pg_data, &_pg_byteindex);
    1862             : 
    1863             :     // Throttle configuration settings
    1864           0 :     encodeECU_ThrottleConfigBits_t(_pg_data, &_pg_byteindex, &_pg_user->config);
    1865             : 
    1866             :     // Input PWM in microseconds for 0% throttle
    1867             :     // Range of pulseInputClosed is 0 to 4095.
    1868           0 :     _pg_tempbitfield = (unsigned int)limitMax(_pg_user->pulseInputClosed, 4095);
    1869           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)(_pg_tempbitfield << 4);
    1870             : 
    1871           0 :     _pg_tempbitfield >>= 4;
    1872           0 :     _pg_data[_pg_byteindex] = (uint8_t)_pg_tempbitfield;
    1873             : 
    1874             : 
    1875             :     // Input PWM in microseconds for 100% throttle
    1876             :     // Range of pulseInputOpen is 0 to 4095.
    1877           0 :     _pg_tempbitfield = (unsigned int)limitMax(_pg_user->pulseInputOpen, 4095);
    1878           0 :     _pg_data[_pg_byteindex + 2] = (uint8_t)_pg_tempbitfield;
    1879             : 
    1880           0 :     _pg_tempbitfield >>= 8;
    1881           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_tempbitfield;
    1882           0 :     _pg_byteindex += 3; // close bit field
    1883             : 
    1884             :     // complete the process of creating the packet
    1885           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_ThrottleCalibrationPacketID());
    1886             : 
    1887           0 : }// encodeECU_ThrottleCalibrationPacketStructure
    1888             : 
    1889             : /*!
    1890             :  * \brief Decode the ECU_ThrottleCalibration packet
    1891             :  *
    1892             :  * The throttle calibration packet sets the calibration values for minimum and
    1893             :  * maximum throttle position. The ECU uses these values to interpolate the
    1894             :  * throttle command.
    1895             :  * \param _pg_pkt points to the packet being decoded by this function
    1896             :  * \param _pg_user receives the data decoded from the packet
    1897             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1898             :  */
    1899           0 : int decodeECU_ThrottleCalibrationPacketStructure(const void* _pg_pkt, ECU_ThrottleSettings_t* _pg_user)
    1900             : {
    1901             :     int _pg_numbytes;
    1902           0 :     int _pg_byteindex = 0;
    1903             :     const uint8_t* _pg_data;
    1904           0 :     unsigned int _pg_tempbitfield = 0;
    1905             : 
    1906             :     // Verify the packet identifier
    1907           0 :     if(getECUPacketID(_pg_pkt) != getECU_ThrottleCalibrationPacketID())
    1908           0 :         return 0;
    1909             : 
    1910             :     // Verify the packet size
    1911           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    1912           0 :     if(_pg_numbytes < getECU_ThrottleCalibrationMinDataLength())
    1913           0 :         return 0;
    1914             : 
    1915             :     // The raw data from the packet
    1916           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    1917             : 
    1918             :     // Output position for 0% throttle in microseconds
    1919             :     // Range of pulseClosed is 0 to 65535.
    1920           0 :     _pg_user->pulseClosed = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1921             : 
    1922             :     // Output position for 100% throttle in microseconds
    1923             :     // Range of pulseOpen is 0 to 65535.
    1924           0 :     _pg_user->pulseOpen = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1925             : 
    1926             :     // Throttle configuration settings
    1927           0 :     if(decodeECU_ThrottleConfigBits_t(_pg_data, &_pg_byteindex, &_pg_user->config) == 0)
    1928           0 :         return 0;
    1929             : 
    1930             :     // Input PWM in microseconds for 0% throttle
    1931             :     // Range of pulseInputClosed is 0 to 4095.
    1932           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex] & 0xFF);
    1933             : 
    1934           0 :     _pg_tempbitfield <<= 4;
    1935           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 1] >> 4);
    1936             : 
    1937           0 :     _pg_user->pulseInputClosed = _pg_tempbitfield;
    1938             : 
    1939             :     // Input PWM in microseconds for 100% throttle
    1940             :     // Range of pulseInputOpen is 0 to 4095.
    1941           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 1] & 0xF);
    1942             : 
    1943           0 :     _pg_tempbitfield <<= 8;
    1944           0 :     _pg_tempbitfield |= _pg_data[_pg_byteindex + 2];
    1945             : 
    1946           0 :     _pg_user->pulseInputOpen = _pg_tempbitfield;
    1947           0 :     _pg_byteindex += 3; // close bit field
    1948             : 
    1949           0 :     return 1;
    1950             : 
    1951             : }// decodeECU_ThrottleCalibrationPacketStructure
    1952             : 
    1953             : /*!
    1954             :  * \brief Create the ECU_ThrottleCalibration packet
    1955             :  *
    1956             :  * The throttle calibration packet sets the calibration values for minimum and
    1957             :  * maximum throttle position. The ECU uses these values to interpolate the
    1958             :  * throttle command.
    1959             :  * \param _pg_pkt points to the packet which will be created by this function
    1960             :  * \param pulseClosed is Output position for 0% throttle in microseconds
    1961             :  * \param pulseOpen is Output position for 100% throttle in microseconds
    1962             :  * \param config is Throttle configuration settings
    1963             :  * \param pulseInputClosed is Input PWM in microseconds for 0% throttle
    1964             :  * \param pulseInputOpen is Input PWM in microseconds for 100% throttle
    1965             :  */
    1966           0 : void encodeECU_ThrottleCalibrationPacket(void* _pg_pkt, uint16_t pulseClosed, uint16_t pulseOpen, const ECU_ThrottleConfigBits_t* config, uint16_t pulseInputClosed, uint16_t pulseInputOpen)
    1967             : {
    1968           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    1969           0 :     int _pg_byteindex = 0;
    1970           0 :     unsigned int _pg_tempbitfield = 0;
    1971             : 
    1972             :     // Output position for 0% throttle in microseconds
    1973             :     // Range of pulseClosed is 0 to 65535.
    1974           0 :     uint16ToBeBytes(pulseClosed, _pg_data, &_pg_byteindex);
    1975             : 
    1976             :     // Output position for 100% throttle in microseconds
    1977             :     // Range of pulseOpen is 0 to 65535.
    1978           0 :     uint16ToBeBytes(pulseOpen, _pg_data, &_pg_byteindex);
    1979             : 
    1980             :     // Throttle configuration settings
    1981           0 :     encodeECU_ThrottleConfigBits_t(_pg_data, &_pg_byteindex, config);
    1982             : 
    1983             :     // Input PWM in microseconds for 0% throttle
    1984             :     // Range of pulseInputClosed is 0 to 4095.
    1985           0 :     _pg_tempbitfield = (unsigned int)limitMax(pulseInputClosed, 4095);
    1986           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)(_pg_tempbitfield << 4);
    1987             : 
    1988           0 :     _pg_tempbitfield >>= 4;
    1989           0 :     _pg_data[_pg_byteindex] = (uint8_t)_pg_tempbitfield;
    1990             : 
    1991             :     // Input PWM in microseconds for 100% throttle
    1992             :     // Range of pulseInputOpen is 0 to 4095.
    1993           0 :     _pg_tempbitfield = (unsigned int)limitMax(pulseInputOpen, 4095);
    1994           0 :     _pg_data[_pg_byteindex + 2] = (uint8_t)_pg_tempbitfield;
    1995             : 
    1996           0 :     _pg_tempbitfield >>= 8;
    1997           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_tempbitfield;
    1998           0 :     _pg_byteindex += 3; // close bit field
    1999             : 
    2000             :     // complete the process of creating the packet
    2001           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_ThrottleCalibrationPacketID());
    2002             : 
    2003           0 : }// encodeECU_ThrottleCalibrationPacket
    2004             : 
    2005             : /*!
    2006             :  * \brief Decode the ECU_ThrottleCalibration packet
    2007             :  *
    2008             :  * The throttle calibration packet sets the calibration values for minimum and
    2009             :  * maximum throttle position. The ECU uses these values to interpolate the
    2010             :  * throttle command.
    2011             :  * \param _pg_pkt points to the packet being decoded by this function
    2012             :  * \param pulseClosed receives Output position for 0% throttle in microseconds
    2013             :  * \param pulseOpen receives Output position for 100% throttle in microseconds
    2014             :  * \param config receives Throttle configuration settings
    2015             :  * \param pulseInputClosed receives Input PWM in microseconds for 0% throttle
    2016             :  * \param pulseInputOpen receives Input PWM in microseconds for 100% throttle
    2017             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2018             :  */
    2019           0 : int decodeECU_ThrottleCalibrationPacket(const void* _pg_pkt, uint16_t* pulseClosed, uint16_t* pulseOpen, ECU_ThrottleConfigBits_t* config, uint16_t* pulseInputClosed, uint16_t* pulseInputOpen)
    2020             : {
    2021           0 :     unsigned int _pg_tempbitfield = 0;
    2022           0 :     int _pg_byteindex = 0;
    2023           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    2024           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    2025             : 
    2026             :     // Verify the packet identifier
    2027           0 :     if(getECUPacketID(_pg_pkt) != getECU_ThrottleCalibrationPacketID())
    2028           0 :         return 0;
    2029             : 
    2030           0 :     if(_pg_numbytes < getECU_ThrottleCalibrationMinDataLength())
    2031           0 :         return 0;
    2032             : 
    2033             :     // Output position for 0% throttle in microseconds
    2034             :     // Range of pulseClosed is 0 to 65535.
    2035           0 :     (*pulseClosed) = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    2036             : 
    2037             :     // Output position for 100% throttle in microseconds
    2038             :     // Range of pulseOpen is 0 to 65535.
    2039           0 :     (*pulseOpen) = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    2040             : 
    2041             :     // Throttle configuration settings
    2042           0 :     if(decodeECU_ThrottleConfigBits_t(_pg_data, &_pg_byteindex, config) == 0)
    2043           0 :         return 0;
    2044             : 
    2045             :     // Input PWM in microseconds for 0% throttle
    2046             :     // Range of pulseInputClosed is 0 to 4095.
    2047           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex] & 0xFF);
    2048             : 
    2049           0 :     _pg_tempbitfield <<= 4;
    2050           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 1] >> 4);
    2051             : 
    2052           0 :     (*pulseInputClosed) = _pg_tempbitfield;
    2053             : 
    2054             :     // Input PWM in microseconds for 100% throttle
    2055             :     // Range of pulseInputOpen is 0 to 4095.
    2056           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 1] & 0xF);
    2057             : 
    2058           0 :     _pg_tempbitfield <<= 8;
    2059           0 :     _pg_tempbitfield |= _pg_data[_pg_byteindex + 2];
    2060             : 
    2061           0 :     (*pulseInputOpen) = _pg_tempbitfield;
    2062           0 :     _pg_byteindex += 3; // close bit field
    2063             : 
    2064           0 :     return 1;
    2065             : 
    2066             : }// decodeECU_ThrottleCalibrationPacket
    2067             : 
    2068             : /*!
    2069             :  * \brief Create the ECU_RPMLoopCalibration packet
    2070             :  *
    2071             :  * The RPM loop calibration packet controls the operating parameters of the RPM
    2072             :  * governor on the ECU. The control loop is implemented using a closed-loop PID
    2073             :  * controller with user-configurable proportional, integral, and derivative
    2074             :  * gains, and a gain scaler.
    2075             :  * \param _pg_pkt points to the packet which will be created by this function
    2076             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    2077             :  */
    2078           0 : void encodeECU_RPMLoopCalibrationPacketStructure(void* _pg_pkt, const ECU_GovernorSettings_t* _pg_user)
    2079             : {
    2080           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2081           0 :     int _pg_byteindex = 0;
    2082             : 
    2083             :     // Proportaional feedback gain from normalized RPM error to throttle fraction
    2084             :     // Range of pGain is 0.0f to 6.5535f.
    2085           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->pGain, _pg_data, &_pg_byteindex, 0.0f, 10000.0f);
    2086             : 
    2087             :     // Integral feedback gain from normalized RPM error to throttle fraction
    2088             :     // Range of iGain is 0.0f to 6.5535f.
    2089           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->iGain, _pg_data, &_pg_byteindex, 0.0f, 10000.0f);
    2090             : 
    2091             :     // Derivative feedback gain from normalized RPM error to throttle fraction
    2092             :     // Range of dGain is 0.0f to 6.5535f.
    2093           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->dGain, _pg_data, &_pg_byteindex, 0.0f, 10000.0f);
    2094             : 
    2095             :     // Gain scaler power, positive numbers increase gain with RPM, and vice versa. User 0 to disable gain scaling
    2096             :     // Range of scalePower is -2.54f to 2.54f.
    2097           0 :     float32ScaledTo1SignedBytes(_pg_user->scalePower, _pg_data, &_pg_byteindex, 50.0f);
    2098             : 
    2099             :     // Maximum commandable RPM
    2100             :     // Range of maxRPM is 0.0f to 25500.0f.
    2101           0 :     float32ScaledTo1UnsignedBytes(_pg_user->maxRPM, _pg_data, &_pg_byteindex, 0.0f, 0.01f);
    2102             : 
    2103             :     // complete the process of creating the packet
    2104           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_RPMLoopCalibrationPacketID());
    2105             : 
    2106           0 : }// encodeECU_RPMLoopCalibrationPacketStructure
    2107             : 
    2108             : /*!
    2109             :  * \brief Decode the ECU_RPMLoopCalibration packet
    2110             :  *
    2111             :  * The RPM loop calibration packet controls the operating parameters of the RPM
    2112             :  * governor on the ECU. The control loop is implemented using a closed-loop PID
    2113             :  * controller with user-configurable proportional, integral, and derivative
    2114             :  * gains, and a gain scaler.
    2115             :  * \param _pg_pkt points to the packet being decoded by this function
    2116             :  * \param _pg_user receives the data decoded from the packet
    2117             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2118             :  */
    2119           0 : int decodeECU_RPMLoopCalibrationPacketStructure(const void* _pg_pkt, ECU_GovernorSettings_t* _pg_user)
    2120             : {
    2121             :     int _pg_numbytes;
    2122           0 :     int _pg_byteindex = 0;
    2123             :     const uint8_t* _pg_data;
    2124             : 
    2125             :     // Verify the packet identifier
    2126           0 :     if(getECUPacketID(_pg_pkt) != getECU_RPMLoopCalibrationPacketID())
    2127           0 :         return 0;
    2128             : 
    2129             :     // Verify the packet size
    2130           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    2131           0 :     if(_pg_numbytes < getECU_RPMLoopCalibrationMinDataLength())
    2132           0 :         return 0;
    2133             : 
    2134             :     // The raw data from the packet
    2135           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    2136             : 
    2137             :     // Proportaional feedback gain from normalized RPM error to throttle fraction
    2138             :     // Range of pGain is 0.0f to 6.5535f.
    2139           0 :     _pg_user->pGain = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10000.0f);
    2140             : 
    2141             :     // Integral feedback gain from normalized RPM error to throttle fraction
    2142             :     // Range of iGain is 0.0f to 6.5535f.
    2143           0 :     _pg_user->iGain = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10000.0f);
    2144             : 
    2145             :     // Derivative feedback gain from normalized RPM error to throttle fraction
    2146             :     // Range of dGain is 0.0f to 6.5535f.
    2147           0 :     _pg_user->dGain = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10000.0f);
    2148             : 
    2149             :     // Gain scaler power, positive numbers increase gain with RPM, and vice versa. User 0 to disable gain scaling
    2150             :     // Range of scalePower is -2.54f to 2.54f.
    2151           0 :     _pg_user->scalePower = float32ScaledFrom1SignedBytes(_pg_data, &_pg_byteindex, 1.0f/50.0f);
    2152             : 
    2153             :     // Maximum commandable RPM
    2154             :     // Range of maxRPM is 0.0f to 25500.0f.
    2155           0 :     _pg_user->maxRPM = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/0.01f);
    2156             : 
    2157           0 :     return 1;
    2158             : 
    2159             : }// decodeECU_RPMLoopCalibrationPacketStructure
    2160             : 
    2161             : /*!
    2162             :  * \brief Create the ECU_TPSDelayCalibration packet
    2163             :  *
    2164             :  * The throttle position delay configuration packet sends the desired throttle
    2165             :  * position delay (between 0 and 500ms) to the ECU, and also echoes back the
    2166             :  * TPS delay.
    2167             :  * \param _pg_pkt points to the packet which will be created by this function
    2168             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    2169             :  */
    2170           0 : void encodeECU_TPSDelayCalibrationPacketStructure(void* _pg_pkt, const ECU_ThrottleSettings_t* _pg_user)
    2171             : {
    2172           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2173           0 :     int _pg_byteindex = 0;
    2174             : 
    2175             :     // Current TPS delay in seconds
    2176             :     // Range of delay is 0 to 255.
    2177           0 :     uint8ToBytes(_pg_user->delay, _pg_data, &_pg_byteindex);
    2178             : 
    2179             :     // Throttle delay configuration bits
    2180           0 :     encodeECU_ThrottleDelayConfigBits_t(_pg_data, &_pg_byteindex, &_pg_user->delayConfig);
    2181             : 
    2182             :     // Maximum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2183             :     // Range of maxDelay is 0 to 255.
    2184           0 :     uint8ToBytes(_pg_user->maxDelay, _pg_data, &_pg_byteindex);
    2185             : 
    2186             :     // Minimum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2187             :     // Range of minDelay is 0 to 255.
    2188           0 :     uint8ToBytes(_pg_user->minDelay, _pg_data, &_pg_byteindex);
    2189             : 
    2190             :     // throttle percentage below which the throttle position will gradually fall off rather than dropping instantaneously (Set this value to zero for the throttle to operate without a soft limit)
    2191             :     // Range of softLimit is 0 to 255.
    2192           0 :     uint8ToBytes(_pg_user->softLimit, _pg_data, &_pg_byteindex);
    2193             : 
    2194             :     // Throttle falloff rate. This determines the rate at which the throttle position decreases if it is below the soft limit
    2195             :     // Range of falloffRate is 0 to 255.
    2196           0 :     uint8ToBytes(_pg_user->falloffRate, _pg_data, &_pg_byteindex);
    2197             : 
    2198             :     // The throttle target position is the TPS input value, which may be given to the ECU via any of the available input types (analog, PWM, serial or CAN). This may vary from the output value, due to the dashpot functionality or the linearization curve. Note: this value cannot be written to the ECU
    2199             :     // Range of throttleTarget is 0 to 255.
    2200           0 :     uint8ToBytes(_pg_user->throttleTarget, _pg_data, &_pg_byteindex);
    2201             : 
    2202             :     // This value sets the minimum allowable throttle position in percent. The throttle position will not fall below this value
    2203             :     // Range of hardLimit is 0 to 255.
    2204           0 :     uint8ToBytes(_pg_user->hardLimit, _pg_data, &_pg_byteindex);
    2205             : 
    2206             :     // complete the process of creating the packet
    2207           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_TPSDelayCalibrationPacketID());
    2208             : 
    2209           0 : }// encodeECU_TPSDelayCalibrationPacketStructure
    2210             : 
    2211             : /*!
    2212             :  * \brief Decode the ECU_TPSDelayCalibration packet
    2213             :  *
    2214             :  * The throttle position delay configuration packet sends the desired throttle
    2215             :  * position delay (between 0 and 500ms) to the ECU, and also echoes back the
    2216             :  * TPS delay.
    2217             :  * \param _pg_pkt points to the packet being decoded by this function
    2218             :  * \param _pg_user receives the data decoded from the packet
    2219             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2220             :  */
    2221           0 : int decodeECU_TPSDelayCalibrationPacketStructure(const void* _pg_pkt, ECU_ThrottleSettings_t* _pg_user)
    2222             : {
    2223             :     int _pg_numbytes;
    2224           0 :     int _pg_byteindex = 0;
    2225             :     const uint8_t* _pg_data;
    2226             : 
    2227             :     // Verify the packet identifier
    2228           0 :     if(getECUPacketID(_pg_pkt) != getECU_TPSDelayCalibrationPacketID())
    2229           0 :         return 0;
    2230             : 
    2231             :     // Verify the packet size
    2232           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    2233           0 :     if(_pg_numbytes < getECU_TPSDelayCalibrationMinDataLength())
    2234           0 :         return 0;
    2235             : 
    2236             :     // The raw data from the packet
    2237           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    2238             : 
    2239             :     // Current TPS delay in seconds
    2240             :     // Range of delay is 0 to 255.
    2241           0 :     _pg_user->delay = uint8FromBytes(_pg_data, &_pg_byteindex);
    2242             : 
    2243             :     // Throttle delay configuration bits
    2244           0 :     if(decodeECU_ThrottleDelayConfigBits_t(_pg_data, &_pg_byteindex, &_pg_user->delayConfig) == 0)
    2245           0 :         return 0;
    2246             : 
    2247             :     // Maximum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2248             :     // Range of maxDelay is 0 to 255.
    2249           0 :     _pg_user->maxDelay = uint8FromBytes(_pg_data, &_pg_byteindex);
    2250             : 
    2251             :     // Minimum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2252             :     // Range of minDelay is 0 to 255.
    2253           0 :     _pg_user->minDelay = uint8FromBytes(_pg_data, &_pg_byteindex);
    2254             : 
    2255             :     // throttle percentage below which the throttle position will gradually fall off rather than dropping instantaneously (Set this value to zero for the throttle to operate without a soft limit)
    2256             :     // Range of softLimit is 0 to 255.
    2257           0 :     _pg_user->softLimit = uint8FromBytes(_pg_data, &_pg_byteindex);
    2258             : 
    2259             :     // Throttle falloff rate. This determines the rate at which the throttle position decreases if it is below the soft limit
    2260             :     // Range of falloffRate is 0 to 255.
    2261           0 :     _pg_user->falloffRate = uint8FromBytes(_pg_data, &_pg_byteindex);
    2262             : 
    2263             :     // The throttle target position is the TPS input value, which may be given to the ECU via any of the available input types (analog, PWM, serial or CAN). This may vary from the output value, due to the dashpot functionality or the linearization curve. Note: this value cannot be written to the ECU
    2264             :     // Range of throttleTarget is 0 to 255.
    2265           0 :     _pg_user->throttleTarget = uint8FromBytes(_pg_data, &_pg_byteindex);
    2266             : 
    2267             :     // This value sets the minimum allowable throttle position in percent. The throttle position will not fall below this value
    2268             :     // Range of hardLimit is 0 to 255.
    2269           0 :     _pg_user->hardLimit = uint8FromBytes(_pg_data, &_pg_byteindex);
    2270             : 
    2271           0 :     return 1;
    2272             : 
    2273             : }// decodeECU_TPSDelayCalibrationPacketStructure
    2274             : 
    2275             : /*!
    2276             :  * \brief Create the ECU_TPSDelayCalibration packet
    2277             :  *
    2278             :  * The throttle position delay configuration packet sends the desired throttle
    2279             :  * position delay (between 0 and 500ms) to the ECU, and also echoes back the
    2280             :  * TPS delay.
    2281             :  * \param _pg_pkt points to the packet which will be created by this function
    2282             :  * \param delay is Current TPS delay in seconds
    2283             :  * \param delayConfig is Throttle delay configuration bits
    2284             :  * \param maxDelay is Maximum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2285             :  * \param minDelay is Minimum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2286             :  * \param softLimit is throttle percentage below which the throttle position will gradually fall off rather than dropping instantaneously (Set this value to zero for the throttle to operate without a soft limit)
    2287             :  * \param falloffRate is Throttle falloff rate. This determines the rate at which the throttle position decreases if it is below the soft limit
    2288             :  * \param throttleTarget is The throttle target position is the TPS input value, which may be given to the ECU via any of the available input types (analog, PWM, serial or CAN). This may vary from the output value, due to the dashpot functionality or the linearization curve. Note: this value cannot be written to the ECU
    2289             :  * \param hardLimit is This value sets the minimum allowable throttle position in percent. The throttle position will not fall below this value
    2290             :  */
    2291           0 : void encodeECU_TPSDelayCalibrationPacket(void* _pg_pkt, uint8_t delay, const ECU_ThrottleDelayConfigBits_t* delayConfig, uint8_t maxDelay, uint8_t minDelay, uint8_t softLimit, uint8_t falloffRate, uint8_t throttleTarget, uint8_t hardLimit)
    2292             : {
    2293           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2294           0 :     int _pg_byteindex = 0;
    2295             : 
    2296             :     // Current TPS delay in seconds
    2297             :     // Range of delay is 0 to 255.
    2298           0 :     uint8ToBytes(delay, _pg_data, &_pg_byteindex);
    2299             : 
    2300             :     // Throttle delay configuration bits
    2301           0 :     encodeECU_ThrottleDelayConfigBits_t(_pg_data, &_pg_byteindex, delayConfig);
    2302             : 
    2303             :     // Maximum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2304             :     // Range of maxDelay is 0 to 255.
    2305           0 :     uint8ToBytes(maxDelay, _pg_data, &_pg_byteindex);
    2306             : 
    2307             :     // Minimum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2308             :     // Range of minDelay is 0 to 255.
    2309           0 :     uint8ToBytes(minDelay, _pg_data, &_pg_byteindex);
    2310             : 
    2311             :     // throttle percentage below which the throttle position will gradually fall off rather than dropping instantaneously (Set this value to zero for the throttle to operate without a soft limit)
    2312             :     // Range of softLimit is 0 to 255.
    2313           0 :     uint8ToBytes(softLimit, _pg_data, &_pg_byteindex);
    2314             : 
    2315             :     // Throttle falloff rate. This determines the rate at which the throttle position decreases if it is below the soft limit
    2316             :     // Range of falloffRate is 0 to 255.
    2317           0 :     uint8ToBytes(falloffRate, _pg_data, &_pg_byteindex);
    2318             : 
    2319             :     // The throttle target position is the TPS input value, which may be given to the ECU via any of the available input types (analog, PWM, serial or CAN). This may vary from the output value, due to the dashpot functionality or the linearization curve. Note: this value cannot be written to the ECU
    2320             :     // Range of throttleTarget is 0 to 255.
    2321           0 :     uint8ToBytes(throttleTarget, _pg_data, &_pg_byteindex);
    2322             : 
    2323             :     // This value sets the minimum allowable throttle position in percent. The throttle position will not fall below this value
    2324             :     // Range of hardLimit is 0 to 255.
    2325           0 :     uint8ToBytes(hardLimit, _pg_data, &_pg_byteindex);
    2326             : 
    2327             :     // complete the process of creating the packet
    2328           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_TPSDelayCalibrationPacketID());
    2329             : 
    2330           0 : }// encodeECU_TPSDelayCalibrationPacket
    2331             : 
    2332             : /*!
    2333             :  * \brief Decode the ECU_TPSDelayCalibration packet
    2334             :  *
    2335             :  * The throttle position delay configuration packet sends the desired throttle
    2336             :  * position delay (between 0 and 500ms) to the ECU, and also echoes back the
    2337             :  * TPS delay.
    2338             :  * \param _pg_pkt points to the packet being decoded by this function
    2339             :  * \param delay receives Current TPS delay in seconds
    2340             :  * \param delayConfig receives Throttle delay configuration bits
    2341             :  * \param maxDelay receives Maximum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2342             :  * \param minDelay receives Minimum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2343             :  * \param softLimit receives throttle percentage below which the throttle position will gradually fall off rather than dropping instantaneously (Set this value to zero for the throttle to operate without a soft limit)
    2344             :  * \param falloffRate receives Throttle falloff rate. This determines the rate at which the throttle position decreases if it is below the soft limit
    2345             :  * \param throttleTarget receives The throttle target position is the TPS input value, which may be given to the ECU via any of the available input types (analog, PWM, serial or CAN). This may vary from the output value, due to the dashpot functionality or the linearization curve. Note: this value cannot be written to the ECU
    2346             :  * \param hardLimit receives This value sets the minimum allowable throttle position in percent. The throttle position will not fall below this value
    2347             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2348             :  */
    2349           0 : int decodeECU_TPSDelayCalibrationPacket(const void* _pg_pkt, uint8_t* delay, ECU_ThrottleDelayConfigBits_t* delayConfig, uint8_t* maxDelay, uint8_t* minDelay, uint8_t* softLimit, uint8_t* falloffRate, uint8_t* throttleTarget, uint8_t* hardLimit)
    2350             : {
    2351           0 :     int _pg_byteindex = 0;
    2352           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    2353           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    2354             : 
    2355             :     // Verify the packet identifier
    2356           0 :     if(getECUPacketID(_pg_pkt) != getECU_TPSDelayCalibrationPacketID())
    2357           0 :         return 0;
    2358             : 
    2359           0 :     if(_pg_numbytes < getECU_TPSDelayCalibrationMinDataLength())
    2360           0 :         return 0;
    2361             : 
    2362             :     // Current TPS delay in seconds
    2363             :     // Range of delay is 0 to 255.
    2364           0 :     (*delay) = uint8FromBytes(_pg_data, &_pg_byteindex);
    2365             : 
    2366             :     // Throttle delay configuration bits
    2367           0 :     if(decodeECU_ThrottleDelayConfigBits_t(_pg_data, &_pg_byteindex, delayConfig) == 0)
    2368           0 :         return 0;
    2369             : 
    2370             :     // Maximum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2371             :     // Range of maxDelay is 0 to 255.
    2372           0 :     (*maxDelay) = uint8FromBytes(_pg_data, &_pg_byteindex);
    2373             : 
    2374             :     // Minimum TPS delay in seconds (for use with temperature dependent TPS delay setting
    2375             :     // Range of minDelay is 0 to 255.
    2376           0 :     (*minDelay) = uint8FromBytes(_pg_data, &_pg_byteindex);
    2377             : 
    2378             :     // throttle percentage below which the throttle position will gradually fall off rather than dropping instantaneously (Set this value to zero for the throttle to operate without a soft limit)
    2379             :     // Range of softLimit is 0 to 255.
    2380           0 :     (*softLimit) = uint8FromBytes(_pg_data, &_pg_byteindex);
    2381             : 
    2382             :     // Throttle falloff rate. This determines the rate at which the throttle position decreases if it is below the soft limit
    2383             :     // Range of falloffRate is 0 to 255.
    2384           0 :     (*falloffRate) = uint8FromBytes(_pg_data, &_pg_byteindex);
    2385             : 
    2386             :     // The throttle target position is the TPS input value, which may be given to the ECU via any of the available input types (analog, PWM, serial or CAN). This may vary from the output value, due to the dashpot functionality or the linearization curve. Note: this value cannot be written to the ECU
    2387             :     // Range of throttleTarget is 0 to 255.
    2388           0 :     (*throttleTarget) = uint8FromBytes(_pg_data, &_pg_byteindex);
    2389             : 
    2390             :     // This value sets the minimum allowable throttle position in percent. The throttle position will not fall below this value
    2391             :     // Range of hardLimit is 0 to 255.
    2392           0 :     (*hardLimit) = uint8FromBytes(_pg_data, &_pg_byteindex);
    2393             : 
    2394           0 :     return 1;
    2395             : 
    2396             : }// decodeECU_TPSDelayCalibrationPacket
    2397             : 
    2398             : /*!
    2399             :  * \brief Create the ECU_TelemetrySettings packet
    2400             :  *
    2401             :  * The telmetry settings packet is used to configure the telemetry data rates
    2402             :  * for the ECU. The ECU will echo the packet as confirmation of its receipt.
    2403             :  * Send a zero length packet to request the current settings.
    2404             :  * \param _pg_pkt points to the packet which will be created by this function
    2405             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    2406             :  */
    2407           0 : void encodeECU_TelemetrySettingsPacketStructure(void* _pg_pkt, const ECU_TelemetrySettings_t* _pg_user)
    2408             : {
    2409           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2410           0 :     int _pg_byteindex = 0;
    2411             : 
    2412             :     // Time between fast telemetry packets in 50ms increments
    2413             :     // Range of fastTelemetryPeriod is 0 to 255.
    2414           0 :     uint8ToBytes(_pg_user->fastTelemetryPeriod, _pg_data, &_pg_byteindex);
    2415             : 
    2416             :     // Time between slow telemetry packets in 500ms increments
    2417             :     // Range of slowTelemetryPeriod is 0 to 255.
    2418           0 :     uint8ToBytes(_pg_user->slowTelemetryPeriod, _pg_data, &_pg_byteindex);
    2419             : 
    2420             :     // Seconds of time the ECU waits after bootup before sending telemetry.
    2421             :     // Range of silencePeriod is 0 to 255.
    2422           0 :     uint8ToBytes(_pg_user->silencePeriod, _pg_data, &_pg_byteindex);
    2423             : 
    2424             :     // complete the process of creating the packet
    2425           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_TelemetrySettingsPacketID());
    2426             : 
    2427           0 : }// encodeECU_TelemetrySettingsPacketStructure
    2428             : 
    2429             : /*!
    2430             :  * \brief Decode the ECU_TelemetrySettings packet
    2431             :  *
    2432             :  * The telmetry settings packet is used to configure the telemetry data rates
    2433             :  * for the ECU. The ECU will echo the packet as confirmation of its receipt.
    2434             :  * Send a zero length packet to request the current settings.
    2435             :  * \param _pg_pkt points to the packet being decoded by this function
    2436             :  * \param _pg_user receives the data decoded from the packet
    2437             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2438             :  */
    2439           0 : int decodeECU_TelemetrySettingsPacketStructure(const void* _pg_pkt, ECU_TelemetrySettings_t* _pg_user)
    2440             : {
    2441             :     int _pg_numbytes;
    2442           0 :     int _pg_byteindex = 0;
    2443             :     const uint8_t* _pg_data;
    2444             : 
    2445             :     // Verify the packet identifier
    2446           0 :     if(getECUPacketID(_pg_pkt) != getECU_TelemetrySettingsPacketID())
    2447           0 :         return 0;
    2448             : 
    2449             :     // Verify the packet size
    2450           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    2451           0 :     if(_pg_numbytes < getECU_TelemetrySettingsMinDataLength())
    2452           0 :         return 0;
    2453             : 
    2454             :     // The raw data from the packet
    2455           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    2456             : 
    2457             :     // Time between fast telemetry packets in 50ms increments
    2458             :     // Range of fastTelemetryPeriod is 0 to 255.
    2459           0 :     _pg_user->fastTelemetryPeriod = uint8FromBytes(_pg_data, &_pg_byteindex);
    2460             : 
    2461             :     // Time between slow telemetry packets in 500ms increments
    2462             :     // Range of slowTelemetryPeriod is 0 to 255.
    2463           0 :     _pg_user->slowTelemetryPeriod = uint8FromBytes(_pg_data, &_pg_byteindex);
    2464             : 
    2465             :     // Seconds of time the ECU waits after bootup before sending telemetry.
    2466             :     // Range of silencePeriod is 0 to 255.
    2467           0 :     _pg_user->silencePeriod = uint8FromBytes(_pg_data, &_pg_byteindex);
    2468             : 
    2469           0 :     return 1;
    2470             : 
    2471             : }// decodeECU_TelemetrySettingsPacketStructure
    2472             : 
    2473             : /*!
    2474             :  * \brief Create the ECU_PumpConfig packet
    2475             :  *
    2476             :  * The pump config packet is sent to the ECU to configure fuel pump control
    2477             :  * loop parameters. The ECU will echo the packet as confirmation of its
    2478             :  * receipt. Send a zero length packet to request the current settings. Note
    2479             :  * that the fuel pump configuration consists of two packets, this one and
    2480             :  * Pump2config.
    2481             :  * \param _pg_pkt points to the packet which will be created by this function
    2482             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    2483             :  */
    2484           0 : void encodeECU_PumpConfigPacketStructure(void* _pg_pkt, const ECU_PumpSettings_t* _pg_user)
    2485             : {
    2486           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2487           0 :     int _pg_byteindex = 0;
    2488             : 
    2489             :     // Fuel pump proportional gain
    2490             :     // Range of kp is 0.0f to 655.35f.
    2491           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->kp, _pg_data, &_pg_byteindex, 0.0f, 100.0f);
    2492             : 
    2493             :     // Pump low pressure limit in kilo-Pascals
    2494             :     // Range of pressureLowerLimit is 0.0f to 4518.40871f.
    2495           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->pressureLowerLimit, _pg_data, &_pg_byteindex, 0.0f, 14.504f);
    2496             : 
    2497             :     // Pump high pressure limit in kilo-Pascals
    2498             :     // Range of pressureUpperLimit is 0.0f to 4518.40871f.
    2499           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->pressureUpperLimit, _pg_data, &_pg_byteindex, 0.0f, 14.504f);
    2500             : 
    2501             :     // Pump pressure setpoint in kilo-Pascals
    2502             :     // Range of pressureSetpoint is 0.0f to 4518.40871f.
    2503           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->pressureSetpoint, _pg_data, &_pg_byteindex, 0.0f, 14.504f);
    2504             : 
    2505             :     // complete the process of creating the packet
    2506           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_PumpConfigPacketID());
    2507             : 
    2508           0 : }// encodeECU_PumpConfigPacketStructure
    2509             : 
    2510             : /*!
    2511             :  * \brief Decode the ECU_PumpConfig packet
    2512             :  *
    2513             :  * The pump config packet is sent to the ECU to configure fuel pump control
    2514             :  * loop parameters. The ECU will echo the packet as confirmation of its
    2515             :  * receipt. Send a zero length packet to request the current settings. Note
    2516             :  * that the fuel pump configuration consists of two packets, this one and
    2517             :  * Pump2config.
    2518             :  * \param _pg_pkt points to the packet being decoded by this function
    2519             :  * \param _pg_user receives the data decoded from the packet
    2520             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2521             :  */
    2522           0 : int decodeECU_PumpConfigPacketStructure(const void* _pg_pkt, ECU_PumpSettings_t* _pg_user)
    2523             : {
    2524             :     int _pg_numbytes;
    2525           0 :     int _pg_byteindex = 0;
    2526             :     const uint8_t* _pg_data;
    2527             : 
    2528             :     // Verify the packet identifier
    2529           0 :     if(getECUPacketID(_pg_pkt) != getECU_PumpConfigPacketID())
    2530           0 :         return 0;
    2531             : 
    2532             :     // Verify the packet size
    2533           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    2534           0 :     if(_pg_numbytes < getECU_PumpConfigMinDataLength())
    2535           0 :         return 0;
    2536             : 
    2537             :     // The raw data from the packet
    2538           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    2539             : 
    2540             :     // Fuel pump proportional gain
    2541             :     // Range of kp is 0.0f to 655.35f.
    2542           0 :     _pg_user->kp = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/100.0f);
    2543             : 
    2544             :     // Pump low pressure limit in kilo-Pascals
    2545             :     // Range of pressureLowerLimit is 0.0f to 4518.40871f.
    2546           0 :     _pg_user->pressureLowerLimit = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/14.504f);
    2547             : 
    2548             :     // Pump high pressure limit in kilo-Pascals
    2549             :     // Range of pressureUpperLimit is 0.0f to 4518.40871f.
    2550           0 :     _pg_user->pressureUpperLimit = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/14.504f);
    2551             : 
    2552             :     // Pump pressure setpoint in kilo-Pascals
    2553             :     // Range of pressureSetpoint is 0.0f to 4518.40871f.
    2554           0 :     _pg_user->pressureSetpoint = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/14.504f);
    2555             : 
    2556           0 :     return 1;
    2557             : 
    2558             : }// decodeECU_PumpConfigPacketStructure
    2559             : 
    2560             : /*!
    2561             :  * \brief Create the ECU_Pump2Config packet
    2562             :  *
    2563             :  * The pump 2 config packet is used for further configuration of pump
    2564             :  * operation. This packet allows the user to configure integral gain values and
    2565             :  * PWM limits. The ECU will echo the packet as confirmation of its receipt.
    2566             :  * Send a zero length packet to request the current settings.
    2567             :  * \param _pg_pkt points to the packet which will be created by this function
    2568             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    2569             :  */
    2570           0 : void encodeECU_Pump2ConfigPacketStructure(void* _pg_pkt, const ECU_PumpSettings_t* _pg_user)
    2571             : {
    2572           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2573           0 :     int _pg_byteindex = 0;
    2574             : 
    2575             :     // Fuel pump integral gain
    2576             :     // Range of ki is 0.0f to 65.535f.
    2577           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->ki, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    2578             : 
    2579             :     // Minimum duty cycle in percent (250 = 100%)
    2580             :     // Range of minimumPWM is 0 to 255.
    2581           0 :     uint8ToBytes(_pg_user->minimumPWM, _pg_data, &_pg_byteindex);
    2582             : 
    2583             :     // Maximum duty cycle in percent (250 = 100%)
    2584             :     // Range of maximumPWM is 0 to 255.
    2585           0 :     uint8ToBytes(_pg_user->maximumPWM, _pg_data, &_pg_byteindex);
    2586             : 
    2587             :     // Reserved for future use
    2588           0 :     uint16ToBeBytes((uint16_t)(0), _pg_data, &_pg_byteindex);
    2589             : 
    2590             :     // Pump duty cycle ramp rate
    2591             :     // Range of rampRate is 0 to 255.
    2592           0 :     uint8ToBytes(_pg_user->rampRate, _pg_data, &_pg_byteindex);
    2593             : 
    2594             :     // complete the process of creating the packet
    2595           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_Pump2ConfigPacketID());
    2596             : 
    2597           0 : }// encodeECU_Pump2ConfigPacketStructure
    2598             : 
    2599             : /*!
    2600             :  * \brief Decode the ECU_Pump2Config packet
    2601             :  *
    2602             :  * The pump 2 config packet is used for further configuration of pump
    2603             :  * operation. This packet allows the user to configure integral gain values and
    2604             :  * PWM limits. The ECU will echo the packet as confirmation of its receipt.
    2605             :  * Send a zero length packet to request the current settings.
    2606             :  * \param _pg_pkt points to the packet being decoded by this function
    2607             :  * \param _pg_user receives the data decoded from the packet
    2608             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2609             :  */
    2610           0 : int decodeECU_Pump2ConfigPacketStructure(const void* _pg_pkt, ECU_PumpSettings_t* _pg_user)
    2611             : {
    2612             :     int _pg_numbytes;
    2613           0 :     int _pg_byteindex = 0;
    2614             :     const uint8_t* _pg_data;
    2615             : 
    2616             :     // Verify the packet identifier
    2617           0 :     if(getECUPacketID(_pg_pkt) != getECU_Pump2ConfigPacketID())
    2618           0 :         return 0;
    2619             : 
    2620             :     // Verify the packet size
    2621           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    2622           0 :     if(_pg_numbytes < getECU_Pump2ConfigMinDataLength())
    2623           0 :         return 0;
    2624             : 
    2625             :     // The raw data from the packet
    2626           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    2627             : 
    2628             :     // Fuel pump integral gain
    2629             :     // Range of ki is 0.0f to 65.535f.
    2630           0 :     _pg_user->ki = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    2631             : 
    2632             :     // Minimum duty cycle in percent (250 = 100%)
    2633             :     // Range of minimumPWM is 0 to 255.
    2634           0 :     _pg_user->minimumPWM = uint8FromBytes(_pg_data, &_pg_byteindex);
    2635             : 
    2636             :     // Maximum duty cycle in percent (250 = 100%)
    2637             :     // Range of maximumPWM is 0 to 255.
    2638           0 :     _pg_user->maximumPWM = uint8FromBytes(_pg_data, &_pg_byteindex);
    2639             : 
    2640             :     // Reserved for future use
    2641           0 :     _pg_byteindex += 2;
    2642             : 
    2643             :     // Pump duty cycle ramp rate
    2644             :     // Range of rampRate is 0 to 255.
    2645           0 :     _pg_user->rampRate = uint8FromBytes(_pg_data, &_pg_byteindex);
    2646             : 
    2647           0 :     return 1;
    2648             : 
    2649             : }// decodeECU_Pump2ConfigPacketStructure
    2650             : 
    2651             : /*!
    2652             :  * \brief Create the ECU_UserData packet
    2653             :  *
    2654             :  * The user data packet provides the user with 8 (eight) bytes of data for
    2655             :  * storing custom parameters or settings in ECU EEPROM (non-volatile) memory.
    2656             :  * The ECU does not make use of these values; they are simply for storing user
    2657             :  * data. Send a zero length packet to request the current settings. To set
    2658             :  * these values send the system command SET_USER_DATA. Data values must be set
    2659             :  * individually.
    2660             :  * \param _pg_pkt points to the packet which will be created by this function
    2661             :  * \param userData is 8 bytes of user data
    2662             :  */
    2663           0 : void encodeECU_UserDataPacket(void* _pg_pkt, const uint8_t userData[8])
    2664             : {
    2665           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2666           0 :     int _pg_byteindex = 0;
    2667           0 :     unsigned _pg_i = 0;
    2668             : 
    2669             :     // 8 bytes of user data
    2670             :     // Range of userData is 0 to 255.
    2671           0 :     for(_pg_i = 0; _pg_i < 8; _pg_i++)
    2672           0 :         uint8ToBytes(userData[_pg_i], _pg_data, &_pg_byteindex);
    2673             : 
    2674             :     // complete the process of creating the packet
    2675           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_UserDataPacketID());
    2676             : 
    2677           0 : }// encodeECU_UserDataPacket
    2678             : 
    2679             : /*!
    2680             :  * \brief Decode the ECU_UserData packet
    2681             :  *
    2682             :  * The user data packet provides the user with 8 (eight) bytes of data for
    2683             :  * storing custom parameters or settings in ECU EEPROM (non-volatile) memory.
    2684             :  * The ECU does not make use of these values; they are simply for storing user
    2685             :  * data. Send a zero length packet to request the current settings. To set
    2686             :  * these values send the system command SET_USER_DATA. Data values must be set
    2687             :  * individually.
    2688             :  * \param _pg_pkt points to the packet being decoded by this function
    2689             :  * \param userData receives 8 bytes of user data
    2690             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2691             :  */
    2692           0 : int decodeECU_UserDataPacket(const void* _pg_pkt, uint8_t userData[8])
    2693             : {
    2694           0 :     unsigned _pg_i = 0;
    2695           0 :     int _pg_byteindex = 0;
    2696           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    2697           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    2698             : 
    2699             :     // Verify the packet identifier
    2700           0 :     if(getECUPacketID(_pg_pkt) != getECU_UserDataPacketID())
    2701           0 :         return 0;
    2702             : 
    2703           0 :     if(_pg_numbytes < getECU_UserDataMinDataLength())
    2704           0 :         return 0;
    2705             : 
    2706             :     // 8 bytes of user data
    2707             :     // Range of userData is 0 to 255.
    2708           0 :     for(_pg_i = 0; _pg_i < 8; _pg_i++)
    2709           0 :         userData[_pg_i] = uint8FromBytes(_pg_data, &_pg_byteindex);
    2710             : 
    2711           0 :     return 1;
    2712             : 
    2713             : }// decodeECU_UserDataPacket
    2714             : 
    2715             : /*!
    2716             :  * \brief Create the ECU_ThrottleCurve packet
    2717             :  *
    2718             :  * First throttle curve packet, which contains the lower 6 term of the throttle
    2719             :  * linearization table. To request the throttle curve data (both packets), send
    2720             :  * the system command REQUEST_THROTTLE_CURVE_DATA. To change the throttle curve
    2721             :  * data send the system command SET_THROTTLE_CURVE_ELEMENT.
    2722             :  * \param _pg_pkt points to the packet which will be created by this function
    2723             :  * \param throttleCurve is Throttle output values for the lower 6 cells in the throttle lookup table
    2724             :  */
    2725           0 : void encodeECU_ThrottleCurvePacket(void* _pg_pkt, const float throttleCurve[6])
    2726             : {
    2727           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2728           0 :     int _pg_byteindex = 0;
    2729           0 :     unsigned _pg_i = 0;
    2730             : 
    2731             :     // Throttle output values for the lower 6 cells in the throttle lookup table
    2732             :     // Range of throttleCurve is 0.0f to 127.5f.
    2733           0 :     for(_pg_i = 0; _pg_i < 6; _pg_i++)
    2734           0 :         float32ScaledTo1UnsignedBytes(throttleCurve[_pg_i], _pg_data, &_pg_byteindex, 0.0f, 2.0f);
    2735             : 
    2736             :     // complete the process of creating the packet
    2737           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_ThrottleCurvePacketID());
    2738             : 
    2739           0 : }// encodeECU_ThrottleCurvePacket
    2740             : 
    2741             : /*!
    2742             :  * \brief Decode the ECU_ThrottleCurve packet
    2743             :  *
    2744             :  * First throttle curve packet, which contains the lower 6 term of the throttle
    2745             :  * linearization table. To request the throttle curve data (both packets), send
    2746             :  * the system command REQUEST_THROTTLE_CURVE_DATA. To change the throttle curve
    2747             :  * data send the system command SET_THROTTLE_CURVE_ELEMENT.
    2748             :  * \param _pg_pkt points to the packet being decoded by this function
    2749             :  * \param throttleCurve receives Throttle output values for the lower 6 cells in the throttle lookup table
    2750             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2751             :  */
    2752           0 : int decodeECU_ThrottleCurvePacket(const void* _pg_pkt, float throttleCurve[6])
    2753             : {
    2754           0 :     unsigned _pg_i = 0;
    2755           0 :     int _pg_byteindex = 0;
    2756           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    2757           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    2758             : 
    2759             :     // Verify the packet identifier
    2760           0 :     if(getECUPacketID(_pg_pkt) != getECU_ThrottleCurvePacketID())
    2761           0 :         return 0;
    2762             : 
    2763           0 :     if(_pg_numbytes < getECU_ThrottleCurveMinDataLength())
    2764           0 :         return 0;
    2765             : 
    2766             :     // Throttle output values for the lower 6 cells in the throttle lookup table
    2767             :     // Range of throttleCurve is 0.0f to 127.5f.
    2768           0 :     for(_pg_i = 0; _pg_i < 6; _pg_i++)
    2769           0 :         throttleCurve[_pg_i] = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/2.0f);
    2770             : 
    2771           0 :     return 1;
    2772             : 
    2773             : }// decodeECU_ThrottleCurvePacket
    2774             : 
    2775             : /*!
    2776             :  * \brief Create the ECU_ThrottleCurve1 packet
    2777             :  *
    2778             :  * Second throttle curve packet, which contains the upper 5 term of the
    2779             :  * throttle linearization table. To request the throttle curve data (both
    2780             :  * packets), send the system command REQUEST_THROTTLE_CURVE_DATA. To change the
    2781             :  * throttle curve data send the system command SET_THROTTLE_CURVE_ELEMENT.
    2782             :  * \param _pg_pkt points to the packet which will be created by this function
    2783             :  * \param throttleCurve is Throttle output values for the upper 5 cells in the throttle lookup table
    2784             :  */
    2785           0 : void encodeECU_ThrottleCurve1Packet(void* _pg_pkt, const float throttleCurve[5])
    2786             : {
    2787           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2788           0 :     int _pg_byteindex = 0;
    2789           0 :     unsigned _pg_i = 0;
    2790             : 
    2791             :     // Throttle output values for the upper 5 cells in the throttle lookup table
    2792             :     // Range of throttleCurve is 0.0f to 127.5f.
    2793           0 :     for(_pg_i = 0; _pg_i < 5; _pg_i++)
    2794           0 :         float32ScaledTo1UnsignedBytes(throttleCurve[_pg_i], _pg_data, &_pg_byteindex, 0.0f, 2.0f);
    2795             : 
    2796             :     // complete the process of creating the packet
    2797           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_ThrottleCurve1PacketID());
    2798             : 
    2799           0 : }// encodeECU_ThrottleCurve1Packet
    2800             : 
    2801             : /*!
    2802             :  * \brief Decode the ECU_ThrottleCurve1 packet
    2803             :  *
    2804             :  * Second throttle curve packet, which contains the upper 5 term of the
    2805             :  * throttle linearization table. To request the throttle curve data (both
    2806             :  * packets), send the system command REQUEST_THROTTLE_CURVE_DATA. To change the
    2807             :  * throttle curve data send the system command SET_THROTTLE_CURVE_ELEMENT.
    2808             :  * \param _pg_pkt points to the packet being decoded by this function
    2809             :  * \param throttleCurve receives Throttle output values for the upper 5 cells in the throttle lookup table
    2810             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2811             :  */
    2812           0 : int decodeECU_ThrottleCurve1Packet(const void* _pg_pkt, float throttleCurve[5])
    2813             : {
    2814           0 :     unsigned _pg_i = 0;
    2815           0 :     int _pg_byteindex = 0;
    2816           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    2817           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    2818             : 
    2819             :     // Verify the packet identifier
    2820           0 :     if(getECUPacketID(_pg_pkt) != getECU_ThrottleCurve1PacketID())
    2821           0 :         return 0;
    2822             : 
    2823           0 :     if(_pg_numbytes < getECU_ThrottleCurve1MinDataLength())
    2824           0 :         return 0;
    2825             : 
    2826             :     // Throttle output values for the upper 5 cells in the throttle lookup table
    2827             :     // Range of throttleCurve is 0.0f to 127.5f.
    2828           0 :     for(_pg_i = 0; _pg_i < 5; _pg_i++)
    2829           0 :         throttleCurve[_pg_i] = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/2.0f);
    2830             : 
    2831           0 :     return 1;
    2832             : 
    2833             : }// decodeECU_ThrottleCurve1Packet
    2834             : 
    2835             : /*!
    2836             :  * \brief Create the ECU_SystemCommand packet
    2837             :  *
    2838             :  * The system command packets follow the format provided below. Refer further
    2839             :  * in the document for complete documentation on each system command packet.
    2840             :  * \param _pg_pkt points to the packet which will be created by this function
    2841             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    2842             :  */
    2843           0 : void encodeECU_SystemCommandPacketStructure(void* _pg_pkt, const ECU_SystemCommand_t* _pg_user)
    2844             : {
    2845           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2846           0 :     int _pg_byteindex = 0;
    2847           0 :     unsigned _pg_i = 0;
    2848             : 
    2849             :     // The command enumeration
    2850             :     // Range of cmd is 0 to 255.
    2851           0 :     uint8ToBytes(_pg_user->cmd, _pg_data, &_pg_byteindex);
    2852             : 
    2853             :     // Up to 3 parameter bytes for a system command
    2854             :     // Range of parambytes is 0 to 255.
    2855           0 :     for(_pg_i = 0; _pg_i < 3; _pg_i++)
    2856           0 :         uint8ToBytes(_pg_user->parambytes[_pg_i], _pg_data, &_pg_byteindex);
    2857             : 
    2858             :     // complete the process of creating the packet
    2859           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SystemCommandPacketID());
    2860             : 
    2861           0 : }// encodeECU_SystemCommandPacketStructure
    2862             : 
    2863             : /*!
    2864             :  * \brief Decode the ECU_SystemCommand packet
    2865             :  *
    2866             :  * The system command packets follow the format provided below. Refer further
    2867             :  * in the document for complete documentation on each system command packet.
    2868             :  * \param _pg_pkt points to the packet being decoded by this function
    2869             :  * \param _pg_user receives the data decoded from the packet
    2870             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2871             :  */
    2872           0 : int decodeECU_SystemCommandPacketStructure(const void* _pg_pkt, ECU_SystemCommand_t* _pg_user)
    2873             : {
    2874             :     int _pg_numbytes;
    2875           0 :     int _pg_byteindex = 0;
    2876             :     const uint8_t* _pg_data;
    2877           0 :     unsigned _pg_i = 0;
    2878             : 
    2879             :     // Verify the packet identifier
    2880           0 :     if(getECUPacketID(_pg_pkt) != getECU_SystemCommandPacketID())
    2881           0 :         return 0;
    2882             : 
    2883             :     // Verify the packet size
    2884           0 :     _pg_numbytes = getECUPacketSize(_pg_pkt);
    2885           0 :     if(_pg_numbytes < getECU_SystemCommandMinDataLength())
    2886           0 :         return 0;
    2887             : 
    2888             :     // The raw data from the packet
    2889           0 :     _pg_data = getECUPacketDataConst(_pg_pkt);
    2890             : 
    2891             :     // this packet has default fields, make sure they are set
    2892           0 :     for(_pg_i = 0; _pg_i < 3; _pg_i++)
    2893           0 :         _pg_user->parambytes[_pg_i] = 0;
    2894             : 
    2895             :     // The command enumeration
    2896             :     // Range of cmd is 0 to 255.
    2897           0 :     _pg_user->cmd = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    2898             : 
    2899           0 :     if(_pg_byteindex + 1*3 > _pg_numbytes)
    2900           0 :         return 1;
    2901             : 
    2902             :     // Up to 3 parameter bytes for a system command
    2903             :     // Range of parambytes is 0 to 255.
    2904           0 :     for(_pg_i = 0; _pg_i < 3; _pg_i++)
    2905           0 :         _pg_user->parambytes[_pg_i] = uint8FromBytes(_pg_data, &_pg_byteindex);
    2906             : 
    2907           0 :     return 1;
    2908             : 
    2909             : }// decodeECU_SystemCommandPacketStructure
    2910             : 
    2911             : /*!
    2912             :  * \brief Create the ECU_CalibrateAnalogClosed packet
    2913             :  *
    2914             :  * Save the current value of the analog throttle position input as the 'Closed'
    2915             :  * position. To calibrate the closed analog input position, set the desired
    2916             :  * analog input level, and send this command to the ECU.
    2917             :  * \param _pg_pkt points to the packet which will be created by this function
    2918             :  */
    2919           0 : void encodeECU_CalibrateAnalogClosedPacket(void* _pg_pkt)
    2920             : {
    2921           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2922           0 :     int _pg_byteindex = 0;
    2923             : 
    2924             :     // The command enumeration
    2925           0 :     uint8ToBytes((uint8_t)(CMD_ECU_CALIBRATE_ANALOG_CLOSED), _pg_data, &_pg_byteindex);
    2926             : 
    2927             :     // complete the process of creating the packet
    2928           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_CalibrateAnalogClosedPacketID());
    2929             : 
    2930           0 : }// encodeECU_CalibrateAnalogClosedPacket
    2931             : 
    2932             : /*!
    2933             :  * \brief Decode the ECU_CalibrateAnalogClosed packet
    2934             :  *
    2935             :  * Save the current value of the analog throttle position input as the 'Closed'
    2936             :  * position. To calibrate the closed analog input position, set the desired
    2937             :  * analog input level, and send this command to the ECU.
    2938             :  * \param _pg_pkt points to the packet being decoded by this function
    2939             :  * \param cmd receives The command enumeration
    2940             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2941             :  */
    2942           0 : int decodeECU_CalibrateAnalogClosedPacket(const void* _pg_pkt, ECUSystemCommands* cmd)
    2943             : {
    2944           0 :     int _pg_byteindex = 0;
    2945           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    2946           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    2947             : 
    2948             :     // Verify the packet identifier
    2949           0 :     if(getECUPacketID(_pg_pkt) != getECU_CalibrateAnalogClosedPacketID())
    2950           0 :         return 0;
    2951             : 
    2952           0 :     if(_pg_numbytes < getECU_CalibrateAnalogClosedMinDataLength())
    2953           0 :         return 0;
    2954             : 
    2955             :     // The command enumeration
    2956             :     // Range of cmd is 0 to 255.
    2957             :     // Decoded value must be CMD_ECU_CALIBRATE_ANALOG_CLOSED
    2958           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    2959           0 :     if ((*cmd) != CMD_ECU_CALIBRATE_ANALOG_CLOSED)
    2960           0 :         return 0;
    2961             : 
    2962           0 :     return 1;
    2963             : 
    2964             : }// decodeECU_CalibrateAnalogClosedPacket
    2965             : 
    2966             : /*!
    2967             :  * \brief Create the ECU_CalibrateAnalogOpen packet
    2968             :  *
    2969             :  * Save the current value of the analog throttle position input as the 'Open'
    2970             :  * position. To calibrate the open analog input position, set the desired
    2971             :  * analog input level, and send this command to the ECU.
    2972             :  * \param _pg_pkt points to the packet which will be created by this function
    2973             :  */
    2974           0 : void encodeECU_CalibrateAnalogOpenPacket(void* _pg_pkt)
    2975             : {
    2976           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    2977           0 :     int _pg_byteindex = 0;
    2978             : 
    2979             :     // The command enumeration
    2980           0 :     uint8ToBytes((uint8_t)(CMD_ECU_CALIBRATE_ANALOG_OPEN), _pg_data, &_pg_byteindex);
    2981             : 
    2982             :     // complete the process of creating the packet
    2983           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_CalibrateAnalogOpenPacketID());
    2984             : 
    2985           0 : }// encodeECU_CalibrateAnalogOpenPacket
    2986             : 
    2987             : /*!
    2988             :  * \brief Decode the ECU_CalibrateAnalogOpen packet
    2989             :  *
    2990             :  * Save the current value of the analog throttle position input as the 'Open'
    2991             :  * position. To calibrate the open analog input position, set the desired
    2992             :  * analog input level, and send this command to the ECU.
    2993             :  * \param _pg_pkt points to the packet being decoded by this function
    2994             :  * \param cmd receives The command enumeration
    2995             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2996             :  */
    2997           0 : int decodeECU_CalibrateAnalogOpenPacket(const void* _pg_pkt, ECUSystemCommands* cmd)
    2998             : {
    2999           0 :     int _pg_byteindex = 0;
    3000           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3001           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3002             : 
    3003             :     // Verify the packet identifier
    3004           0 :     if(getECUPacketID(_pg_pkt) != getECU_CalibrateAnalogOpenPacketID())
    3005           0 :         return 0;
    3006             : 
    3007           0 :     if(_pg_numbytes < getECU_CalibrateAnalogOpenMinDataLength())
    3008           0 :         return 0;
    3009             : 
    3010             :     // The command enumeration
    3011             :     // Range of cmd is 0 to 255.
    3012             :     // Decoded value must be CMD_ECU_CALIBRATE_ANALOG_OPEN
    3013           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3014           0 :     if ((*cmd) != CMD_ECU_CALIBRATE_ANALOG_OPEN)
    3015           0 :         return 0;
    3016             : 
    3017           0 :     return 1;
    3018             : 
    3019             : }// decodeECU_CalibrateAnalogOpenPacket
    3020             : 
    3021             : /*!
    3022             :  * \brief Create the ECU_CalibratePulseClosed packet
    3023             :  *
    3024             :  * Save the current value of the throttle output pulse width to a temporary
    3025             :  * variable in the ECU. When the CALIBRATE_PULSE_WRITE command is sent to the
    3026             :  * ECU, this value will be saved as the 'Closed' pulse width.
    3027             :  * \param _pg_pkt points to the packet which will be created by this function
    3028             :  */
    3029           0 : void encodeECU_CalibratePulseClosedPacket(void* _pg_pkt)
    3030             : {
    3031           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3032           0 :     int _pg_byteindex = 0;
    3033             : 
    3034             :     // The command enumeration
    3035           0 :     uint8ToBytes((uint8_t)(CMD_ECU_CALIBRATE_PULSE_CLOSED), _pg_data, &_pg_byteindex);
    3036             : 
    3037             :     // complete the process of creating the packet
    3038           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_CalibratePulseClosedPacketID());
    3039             : 
    3040           0 : }// encodeECU_CalibratePulseClosedPacket
    3041             : 
    3042             : /*!
    3043             :  * \brief Decode the ECU_CalibratePulseClosed packet
    3044             :  *
    3045             :  * Save the current value of the throttle output pulse width to a temporary
    3046             :  * variable in the ECU. When the CALIBRATE_PULSE_WRITE command is sent to the
    3047             :  * ECU, this value will be saved as the 'Closed' pulse width.
    3048             :  * \param _pg_pkt points to the packet being decoded by this function
    3049             :  * \param cmd receives The command enumeration
    3050             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3051             :  */
    3052           0 : int decodeECU_CalibratePulseClosedPacket(const void* _pg_pkt, ECUSystemCommands* cmd)
    3053             : {
    3054           0 :     int _pg_byteindex = 0;
    3055           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3056           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3057             : 
    3058             :     // Verify the packet identifier
    3059           0 :     if(getECUPacketID(_pg_pkt) != getECU_CalibratePulseClosedPacketID())
    3060           0 :         return 0;
    3061             : 
    3062           0 :     if(_pg_numbytes < getECU_CalibratePulseClosedMinDataLength())
    3063           0 :         return 0;
    3064             : 
    3065             :     // The command enumeration
    3066             :     // Range of cmd is 0 to 255.
    3067             :     // Decoded value must be CMD_ECU_CALIBRATE_PULSE_CLOSED
    3068           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3069           0 :     if ((*cmd) != CMD_ECU_CALIBRATE_PULSE_CLOSED)
    3070           0 :         return 0;
    3071             : 
    3072           0 :     return 1;
    3073             : 
    3074             : }// decodeECU_CalibratePulseClosedPacket
    3075             : 
    3076             : /*!
    3077             :  * \brief Create the ECU_CalibratePulseOpen packet
    3078             :  *
    3079             :  * Save the current value of the throttle output pulse width to a temporary
    3080             :  * variable in the ECU. When the CALIBRATE_PULSE_WRITE command is sent to the
    3081             :  * ECU, this value will be saved as the 'Open' pulse width.
    3082             :  * \param _pg_pkt points to the packet which will be created by this function
    3083             :  */
    3084           0 : void encodeECU_CalibratePulseOpenPacket(void* _pg_pkt)
    3085             : {
    3086           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3087           0 :     int _pg_byteindex = 0;
    3088             : 
    3089             :     // The command enumeration
    3090           0 :     uint8ToBytes((uint8_t)(CMD_ECU_CALIBRATE_PULSE_OPEN), _pg_data, &_pg_byteindex);
    3091             : 
    3092             :     // complete the process of creating the packet
    3093           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_CalibratePulseOpenPacketID());
    3094             : 
    3095           0 : }// encodeECU_CalibratePulseOpenPacket
    3096             : 
    3097             : /*!
    3098             :  * \brief Decode the ECU_CalibratePulseOpen packet
    3099             :  *
    3100             :  * Save the current value of the throttle output pulse width to a temporary
    3101             :  * variable in the ECU. When the CALIBRATE_PULSE_WRITE command is sent to the
    3102             :  * ECU, this value will be saved as the 'Open' pulse width.
    3103             :  * \param _pg_pkt points to the packet being decoded by this function
    3104             :  * \param cmd receives The command enumeration
    3105             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3106             :  */
    3107           0 : int decodeECU_CalibratePulseOpenPacket(const void* _pg_pkt, ECUSystemCommands* cmd)
    3108             : {
    3109           0 :     int _pg_byteindex = 0;
    3110           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3111           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3112             : 
    3113             :     // Verify the packet identifier
    3114           0 :     if(getECUPacketID(_pg_pkt) != getECU_CalibratePulseOpenPacketID())
    3115           0 :         return 0;
    3116             : 
    3117           0 :     if(_pg_numbytes < getECU_CalibratePulseOpenMinDataLength())
    3118           0 :         return 0;
    3119             : 
    3120             :     // The command enumeration
    3121             :     // Range of cmd is 0 to 255.
    3122             :     // Decoded value must be CMD_ECU_CALIBRATE_PULSE_OPEN
    3123           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3124           0 :     if ((*cmd) != CMD_ECU_CALIBRATE_PULSE_OPEN)
    3125           0 :         return 0;
    3126             : 
    3127           0 :     return 1;
    3128             : 
    3129             : }// decodeECU_CalibratePulseOpenPacket
    3130             : 
    3131             : /*!
    3132             :  * \brief Create the ECU_CalibratePulseWrite packet
    3133             :  *
    3134             :  * Configure the throttle output positions. The CALIBRATE_PULSE_CLOSED and
    3135             :  * CALIBRATE_PULSE_OPEN commands should have already been sent to the ECU. The
    3136             :  * ECU then saves the temporary values as the 'Closed' and 'Open' throttle
    3137             :  * output values, respectively.
    3138             :  * \param _pg_pkt points to the packet which will be created by this function
    3139             :  */
    3140           0 : void encodeECU_CalibratePulseWritePacket(void* _pg_pkt)
    3141             : {
    3142           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3143           0 :     int _pg_byteindex = 0;
    3144             : 
    3145             :     // The command enumeration
    3146           0 :     uint8ToBytes((uint8_t)(CMD_ECU_CALIBRATE_PULSE_WRITE), _pg_data, &_pg_byteindex);
    3147             : 
    3148             :     // complete the process of creating the packet
    3149           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_CalibratePulseWritePacketID());
    3150             : 
    3151           0 : }// encodeECU_CalibratePulseWritePacket
    3152             : 
    3153             : /*!
    3154             :  * \brief Decode the ECU_CalibratePulseWrite packet
    3155             :  *
    3156             :  * Configure the throttle output positions. The CALIBRATE_PULSE_CLOSED and
    3157             :  * CALIBRATE_PULSE_OPEN commands should have already been sent to the ECU. The
    3158             :  * ECU then saves the temporary values as the 'Closed' and 'Open' throttle
    3159             :  * output values, respectively.
    3160             :  * \param _pg_pkt points to the packet being decoded by this function
    3161             :  * \param cmd receives The command enumeration
    3162             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3163             :  */
    3164           0 : int decodeECU_CalibratePulseWritePacket(const void* _pg_pkt, ECUSystemCommands* cmd)
    3165             : {
    3166           0 :     int _pg_byteindex = 0;
    3167           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3168           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3169             : 
    3170             :     // Verify the packet identifier
    3171           0 :     if(getECUPacketID(_pg_pkt) != getECU_CalibratePulseWritePacketID())
    3172           0 :         return 0;
    3173             : 
    3174           0 :     if(_pg_numbytes < getECU_CalibratePulseWriteMinDataLength())
    3175           0 :         return 0;
    3176             : 
    3177             :     // The command enumeration
    3178             :     // Range of cmd is 0 to 255.
    3179             :     // Decoded value must be CMD_ECU_CALIBRATE_PULSE_WRITE
    3180           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3181           0 :     if ((*cmd) != CMD_ECU_CALIBRATE_PULSE_WRITE)
    3182           0 :         return 0;
    3183             : 
    3184           0 :     return 1;
    3185             : 
    3186             : }// decodeECU_CalibratePulseWritePacket
    3187             : 
    3188             : /*!
    3189             :  * \brief Create the ECU_SetOutputDriver packet
    3190             :  *
    3191             :  * Set one of four high-current output drivers.
    3192             :  * \param _pg_pkt points to the packet which will be created by this function
    3193             :  * \param driver is Select driver number (1, 2, 3 or 4)
    3194             :  * \param status is Set driver status (1 = ON, 0 = OFF)
    3195             :  */
    3196           0 : void encodeECU_SetOutputDriverPacket(void* _pg_pkt, uint8_t driver, uint8_t status)
    3197             : {
    3198           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3199           0 :     int _pg_byteindex = 0;
    3200             : 
    3201             :     // The command enumeration
    3202           0 :     uint8ToBytes((uint8_t)(CMD_ECU_SET_OUTPUT_DRIVER), _pg_data, &_pg_byteindex);
    3203             : 
    3204             :     // Select driver number (1, 2, 3 or 4)
    3205             :     // Range of driver is 0 to 255.
    3206           0 :     uint8ToBytes(driver, _pg_data, &_pg_byteindex);
    3207             : 
    3208             :     // Set driver status (1 = ON, 0 = OFF)
    3209             :     // Range of status is 0 to 255.
    3210           0 :     uint8ToBytes(status, _pg_data, &_pg_byteindex);
    3211             : 
    3212             :     // complete the process of creating the packet
    3213           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SetOutputDriverPacketID());
    3214             : 
    3215           0 : }// encodeECU_SetOutputDriverPacket
    3216             : 
    3217             : /*!
    3218             :  * \brief Decode the ECU_SetOutputDriver packet
    3219             :  *
    3220             :  * Set one of four high-current output drivers.
    3221             :  * \param _pg_pkt points to the packet being decoded by this function
    3222             :  * \param cmd receives The command enumeration
    3223             :  * \param driver receives Select driver number (1, 2, 3 or 4)
    3224             :  * \param status receives Set driver status (1 = ON, 0 = OFF)
    3225             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3226             :  */
    3227           0 : int decodeECU_SetOutputDriverPacket(const void* _pg_pkt, ECUSystemCommands* cmd, uint8_t* driver, uint8_t* status)
    3228             : {
    3229           0 :     int _pg_byteindex = 0;
    3230           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3231           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3232             : 
    3233             :     // Verify the packet identifier
    3234           0 :     if(getECUPacketID(_pg_pkt) != getECU_SetOutputDriverPacketID())
    3235           0 :         return 0;
    3236             : 
    3237           0 :     if(_pg_numbytes < getECU_SetOutputDriverMinDataLength())
    3238           0 :         return 0;
    3239             : 
    3240             :     // The command enumeration
    3241             :     // Range of cmd is 0 to 255.
    3242             :     // Decoded value must be CMD_ECU_SET_OUTPUT_DRIVER
    3243           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3244           0 :     if ((*cmd) != CMD_ECU_SET_OUTPUT_DRIVER)
    3245           0 :         return 0;
    3246             : 
    3247             :     // Select driver number (1, 2, 3 or 4)
    3248             :     // Range of driver is 0 to 255.
    3249           0 :     (*driver) = uint8FromBytes(_pg_data, &_pg_byteindex);
    3250             : 
    3251             :     // Set driver status (1 = ON, 0 = OFF)
    3252             :     // Range of status is 0 to 255.
    3253           0 :     (*status) = uint8FromBytes(_pg_data, &_pg_byteindex);
    3254             : 
    3255           0 :     return 1;
    3256             : 
    3257             : }// decodeECU_SetOutputDriverPacket
    3258             : 
    3259             : /*!
    3260             :  * \brief Create the ECU_SetThrottleCurveActive packet
    3261             :  *
    3262             :  * Turn the throttle linearization curve either on or off.
    3263             :  * \param _pg_pkt points to the packet which will be created by this function
    3264             :  * \param active is Curve active (1 = ON, 0 = OFF)
    3265             :  */
    3266           0 : void encodeECU_SetThrottleCurveActivePacket(void* _pg_pkt, uint8_t active)
    3267             : {
    3268           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3269           0 :     int _pg_byteindex = 0;
    3270             : 
    3271             :     // The command enumeration
    3272           0 :     uint8ToBytes((uint8_t)(CMD_ECU_SET_THROTTLE_CURVE_ACTIVE), _pg_data, &_pg_byteindex);
    3273             : 
    3274             :     // Curve active (1 = ON, 0 = OFF)
    3275             :     // Range of active is 0 to 255.
    3276           0 :     uint8ToBytes(active, _pg_data, &_pg_byteindex);
    3277             : 
    3278             :     // complete the process of creating the packet
    3279           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SetThrottleCurveActivePacketID());
    3280             : 
    3281           0 : }// encodeECU_SetThrottleCurveActivePacket
    3282             : 
    3283             : /*!
    3284             :  * \brief Decode the ECU_SetThrottleCurveActive packet
    3285             :  *
    3286             :  * Turn the throttle linearization curve either on or off.
    3287             :  * \param _pg_pkt points to the packet being decoded by this function
    3288             :  * \param cmd receives The command enumeration
    3289             :  * \param active receives Curve active (1 = ON, 0 = OFF)
    3290             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3291             :  */
    3292           0 : int decodeECU_SetThrottleCurveActivePacket(const void* _pg_pkt, ECUSystemCommands* cmd, uint8_t* active)
    3293             : {
    3294           0 :     int _pg_byteindex = 0;
    3295           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3296           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3297             : 
    3298             :     // Verify the packet identifier
    3299           0 :     if(getECUPacketID(_pg_pkt) != getECU_SetThrottleCurveActivePacketID())
    3300           0 :         return 0;
    3301             : 
    3302           0 :     if(_pg_numbytes < getECU_SetThrottleCurveActiveMinDataLength())
    3303           0 :         return 0;
    3304             : 
    3305             :     // The command enumeration
    3306             :     // Range of cmd is 0 to 255.
    3307             :     // Decoded value must be CMD_ECU_SET_THROTTLE_CURVE_ACTIVE
    3308           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3309           0 :     if ((*cmd) != CMD_ECU_SET_THROTTLE_CURVE_ACTIVE)
    3310           0 :         return 0;
    3311             : 
    3312             :     // Curve active (1 = ON, 0 = OFF)
    3313             :     // Range of active is 0 to 255.
    3314           0 :     (*active) = uint8FromBytes(_pg_data, &_pg_byteindex);
    3315             : 
    3316           0 :     return 1;
    3317             : 
    3318             : }// decodeECU_SetThrottleCurveActivePacket
    3319             : 
    3320             : /*!
    3321             :  * \brief Create the ECU_SetThrottleCurveElement packet
    3322             :  *
    3323             :  * Set individual elements in the throttle linearization lookup table.
    3324             :  * \param _pg_pkt points to the packet which will be created by this function
    3325             :  * \param index is Index into the throttle curve table from 0 to 10 (0% to 100%) throttle input
    3326             :  * \param throttleOutput is Percentage throttle output for this curve element
    3327             :  */
    3328           0 : void encodeECU_SetThrottleCurveElementPacket(void* _pg_pkt, uint8_t index, float throttleOutput)
    3329             : {
    3330           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3331           0 :     int _pg_byteindex = 0;
    3332             : 
    3333             :     // The command enumeration
    3334           0 :     uint8ToBytes((uint8_t)(CMD_ECU_SET_THROTTLE_CURVE_ELEMENT), _pg_data, &_pg_byteindex);
    3335             : 
    3336             :     // Index into the throttle curve table from 0 to 10 (0% to 100%) throttle input
    3337             :     // Range of index is 0 to 255.
    3338           0 :     uint8ToBytes(index, _pg_data, &_pg_byteindex);
    3339             : 
    3340             :     // Percentage throttle output for this curve element
    3341             :     // Range of throttleOutput is 0.0f to 127.5f.
    3342           0 :     float32ScaledTo1UnsignedBytes(throttleOutput, _pg_data, &_pg_byteindex, 0.0f, 2.0f);
    3343             : 
    3344             :     // complete the process of creating the packet
    3345           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SetThrottleCurveElementPacketID());
    3346             : 
    3347           0 : }// encodeECU_SetThrottleCurveElementPacket
    3348             : 
    3349             : /*!
    3350             :  * \brief Decode the ECU_SetThrottleCurveElement packet
    3351             :  *
    3352             :  * Set individual elements in the throttle linearization lookup table.
    3353             :  * \param _pg_pkt points to the packet being decoded by this function
    3354             :  * \param cmd receives The command enumeration
    3355             :  * \param index receives Index into the throttle curve table from 0 to 10 (0% to 100%) throttle input
    3356             :  * \param throttleOutput receives Percentage throttle output for this curve element
    3357             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3358             :  */
    3359           0 : int decodeECU_SetThrottleCurveElementPacket(const void* _pg_pkt, ECUSystemCommands* cmd, uint8_t* index, float* throttleOutput)
    3360             : {
    3361           0 :     int _pg_byteindex = 0;
    3362           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3363           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3364             : 
    3365             :     // Verify the packet identifier
    3366           0 :     if(getECUPacketID(_pg_pkt) != getECU_SetThrottleCurveElementPacketID())
    3367           0 :         return 0;
    3368             : 
    3369           0 :     if(_pg_numbytes < getECU_SetThrottleCurveElementMinDataLength())
    3370           0 :         return 0;
    3371             : 
    3372             :     // The command enumeration
    3373             :     // Range of cmd is 0 to 255.
    3374             :     // Decoded value must be CMD_ECU_SET_THROTTLE_CURVE_ELEMENT
    3375           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3376           0 :     if ((*cmd) != CMD_ECU_SET_THROTTLE_CURVE_ELEMENT)
    3377           0 :         return 0;
    3378             : 
    3379             :     // Index into the throttle curve table from 0 to 10 (0% to 100%) throttle input
    3380             :     // Range of index is 0 to 255.
    3381           0 :     (*index) = uint8FromBytes(_pg_data, &_pg_byteindex);
    3382             : 
    3383             :     // Percentage throttle output for this curve element
    3384             :     // Range of throttleOutput is 0.0f to 127.5f.
    3385           0 :     (*throttleOutput) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/2.0f);
    3386             : 
    3387           0 :     return 1;
    3388             : 
    3389             : }// decodeECU_SetThrottleCurveElementPacket
    3390             : 
    3391             : /*!
    3392             :  * \brief Create the ECU_RequestThrottleCurveData packet
    3393             :  *
    3394             :  * Request the throttle curve lookup table data. If requested on CAN, the data
    3395             :  * will be returned on CAN. If requested on RS232, the data will be returned on
    3396             :  * RS232.
    3397             :  * \param _pg_pkt points to the packet which will be created by this function
    3398             :  */
    3399           0 : void encodeECU_RequestThrottleCurveDataPacket(void* _pg_pkt)
    3400             : {
    3401           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3402           0 :     int _pg_byteindex = 0;
    3403             : 
    3404             :     // The command enumeration
    3405           0 :     uint8ToBytes((uint8_t)(CMD_ECU_REQUEST_THROTTLE_CURVE_DATA), _pg_data, &_pg_byteindex);
    3406             : 
    3407             :     // complete the process of creating the packet
    3408           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_RequestThrottleCurveDataPacketID());
    3409             : 
    3410           0 : }// encodeECU_RequestThrottleCurveDataPacket
    3411             : 
    3412             : /*!
    3413             :  * \brief Decode the ECU_RequestThrottleCurveData packet
    3414             :  *
    3415             :  * Request the throttle curve lookup table data. If requested on CAN, the data
    3416             :  * will be returned on CAN. If requested on RS232, the data will be returned on
    3417             :  * RS232.
    3418             :  * \param _pg_pkt points to the packet being decoded by this function
    3419             :  * \param cmd receives The command enumeration
    3420             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3421             :  */
    3422           0 : int decodeECU_RequestThrottleCurveDataPacket(const void* _pg_pkt, ECUSystemCommands* cmd)
    3423             : {
    3424           0 :     int _pg_byteindex = 0;
    3425           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3426           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3427             : 
    3428             :     // Verify the packet identifier
    3429           0 :     if(getECUPacketID(_pg_pkt) != getECU_RequestThrottleCurveDataPacketID())
    3430           0 :         return 0;
    3431             : 
    3432           0 :     if(_pg_numbytes < getECU_RequestThrottleCurveDataMinDataLength())
    3433           0 :         return 0;
    3434             : 
    3435             :     // The command enumeration
    3436             :     // Range of cmd is 0 to 255.
    3437             :     // Decoded value must be CMD_ECU_REQUEST_THROTTLE_CURVE_DATA
    3438           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3439           0 :     if ((*cmd) != CMD_ECU_REQUEST_THROTTLE_CURVE_DATA)
    3440           0 :         return 0;
    3441             : 
    3442           0 :     return 1;
    3443             : 
    3444             : }// decodeECU_RequestThrottleCurveDataPacket
    3445             : 
    3446             : /*!
    3447             :  * \brief Create the ECU_ResetFuelUsed packet
    3448             :  *
    3449             :  * Reset the FuelUsed value. This will set the FuelUsed data to zero.
    3450             :  * \param _pg_pkt points to the packet which will be created by this function
    3451             :  */
    3452           0 : void encodeECU_ResetFuelUsedPacket(void* _pg_pkt)
    3453             : {
    3454           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3455           0 :     int _pg_byteindex = 0;
    3456             : 
    3457             :     // The command enumeration
    3458           0 :     uint8ToBytes((uint8_t)(CMD_ECU_RESET_FUEL_USED), _pg_data, &_pg_byteindex);
    3459             : 
    3460             :     // complete the process of creating the packet
    3461           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_ResetFuelUsedPacketID());
    3462             : 
    3463           0 : }// encodeECU_ResetFuelUsedPacket
    3464             : 
    3465             : /*!
    3466             :  * \brief Decode the ECU_ResetFuelUsed packet
    3467             :  *
    3468             :  * Reset the FuelUsed value. This will set the FuelUsed data to zero.
    3469             :  * \param _pg_pkt points to the packet being decoded by this function
    3470             :  * \param cmd receives The command enumeration
    3471             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3472             :  */
    3473           0 : int decodeECU_ResetFuelUsedPacket(const void* _pg_pkt, ECUSystemCommands* cmd)
    3474             : {
    3475           0 :     int _pg_byteindex = 0;
    3476           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3477           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3478             : 
    3479             :     // Verify the packet identifier
    3480           0 :     if(getECUPacketID(_pg_pkt) != getECU_ResetFuelUsedPacketID())
    3481           0 :         return 0;
    3482             : 
    3483           0 :     if(_pg_numbytes < getECU_ResetFuelUsedMinDataLength())
    3484           0 :         return 0;
    3485             : 
    3486             :     // The command enumeration
    3487             :     // Range of cmd is 0 to 255.
    3488             :     // Decoded value must be CMD_ECU_RESET_FUEL_USED
    3489           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3490           0 :     if ((*cmd) != CMD_ECU_RESET_FUEL_USED)
    3491           0 :         return 0;
    3492             : 
    3493           0 :     return 1;
    3494             : 
    3495             : }// decodeECU_ResetFuelUsedPacket
    3496             : 
    3497             : /*!
    3498             :  * \brief Create the ECU_SetFuelUsedDivisor packet
    3499             :  *
    3500             :  * Set the fuel used divisor
    3501             :  * \param _pg_pkt points to the packet which will be created by this function
    3502             :  * \param divisor is The fuel used divisor. The fuel used value is divided by this divisor before being transmitted by the auxiliary processor. Set this value to 1 to leave the fuel used data unaffected. If you use values greater than 100 the divisor is automatically interpreted as being in units of 0.01 (i.e. 100 times the resolution).
    3503             :  */
    3504           0 : void encodeECU_SetFuelUsedDivisorPacket(void* _pg_pkt, uint16_t divisor)
    3505             : {
    3506           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3507           0 :     int _pg_byteindex = 0;
    3508             : 
    3509             :     // The command enumeration
    3510           0 :     uint8ToBytes((uint8_t)(CMD_ECU_SET_FUEL_USED_DIVISOR), _pg_data, &_pg_byteindex);
    3511             : 
    3512             :     // The fuel used divisor. The fuel used value is divided by this divisor before being transmitted by the auxiliary processor. Set this value to 1 to leave the fuel used data unaffected. If you use values greater than 100 the divisor is automatically interpreted as being in units of 0.01 (i.e. 100 times the resolution).
    3513             :     // Range of divisor is 0 to 65535.
    3514           0 :     uint16ToBeBytes(divisor, _pg_data, &_pg_byteindex);
    3515             : 
    3516             :     // complete the process of creating the packet
    3517           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SetFuelUsedDivisorPacketID());
    3518             : 
    3519           0 : }// encodeECU_SetFuelUsedDivisorPacket
    3520             : 
    3521             : /*!
    3522             :  * \brief Decode the ECU_SetFuelUsedDivisor packet
    3523             :  *
    3524             :  * Set the fuel used divisor
    3525             :  * \param _pg_pkt points to the packet being decoded by this function
    3526             :  * \param cmd receives The command enumeration
    3527             :  * \param divisor receives The fuel used divisor. The fuel used value is divided by this divisor before being transmitted by the auxiliary processor. Set this value to 1 to leave the fuel used data unaffected. If you use values greater than 100 the divisor is automatically interpreted as being in units of 0.01 (i.e. 100 times the resolution).
    3528             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3529             :  */
    3530           0 : int decodeECU_SetFuelUsedDivisorPacket(const void* _pg_pkt, ECUSystemCommands* cmd, uint16_t* divisor)
    3531             : {
    3532           0 :     int _pg_byteindex = 0;
    3533           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3534           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3535             : 
    3536             :     // Verify the packet identifier
    3537           0 :     if(getECUPacketID(_pg_pkt) != getECU_SetFuelUsedDivisorPacketID())
    3538           0 :         return 0;
    3539             : 
    3540           0 :     if(_pg_numbytes < getECU_SetFuelUsedDivisorMinDataLength())
    3541           0 :         return 0;
    3542             : 
    3543             :     // The command enumeration
    3544             :     // Range of cmd is 0 to 255.
    3545             :     // Decoded value must be CMD_ECU_SET_FUEL_USED_DIVISOR
    3546           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3547           0 :     if ((*cmd) != CMD_ECU_SET_FUEL_USED_DIVISOR)
    3548           0 :         return 0;
    3549             : 
    3550             :     // The fuel used divisor. The fuel used value is divided by this divisor before being transmitted by the auxiliary processor. Set this value to 1 to leave the fuel used data unaffected. If you use values greater than 100 the divisor is automatically interpreted as being in units of 0.01 (i.e. 100 times the resolution).
    3551             :     // Range of divisor is 0 to 65535.
    3552           0 :     (*divisor) = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    3553             : 
    3554           0 :     return 1;
    3555             : 
    3556             : }// decodeECU_SetFuelUsedDivisorPacket
    3557             : 
    3558             : /*!
    3559             :  * \brief Create the ECU_SetFuelUsedResetFlag packet
    3560             :  *
    3561             :  * Set or clear the Fuel Used reset flag. If this flag is set, the FuelUsed
    3562             :  * data will reset (to zero) when the ECU is power cycled.
    3563             :  * \param _pg_pkt points to the packet which will be created by this function
    3564             :  * \param reset is 1 = Reset Fuel Used data on powerup 0 = Do not reset Fuel Used data on power up
    3565             :  */
    3566           0 : void encodeECU_SetFuelUsedResetFlagPacket(void* _pg_pkt, uint8_t reset)
    3567             : {
    3568           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3569           0 :     int _pg_byteindex = 0;
    3570             : 
    3571             :     // The command enumeration
    3572           0 :     uint8ToBytes((uint8_t)(CMD_ECU_FUEL_USED_RESET_ON_STARTUP), _pg_data, &_pg_byteindex);
    3573             : 
    3574             :     // 1 = Reset Fuel Used data on powerup 0 = Do not reset Fuel Used data on power up
    3575             :     // Range of reset is 0 to 255.
    3576           0 :     uint8ToBytes(reset, _pg_data, &_pg_byteindex);
    3577             : 
    3578             :     // complete the process of creating the packet
    3579           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SetFuelUsedResetFlagPacketID());
    3580             : 
    3581           0 : }// encodeECU_SetFuelUsedResetFlagPacket
    3582             : 
    3583             : /*!
    3584             :  * \brief Decode the ECU_SetFuelUsedResetFlag packet
    3585             :  *
    3586             :  * Set or clear the Fuel Used reset flag. If this flag is set, the FuelUsed
    3587             :  * data will reset (to zero) when the ECU is power cycled.
    3588             :  * \param _pg_pkt points to the packet being decoded by this function
    3589             :  * \param cmd receives The command enumeration
    3590             :  * \param reset receives 1 = Reset Fuel Used data on powerup 0 = Do not reset Fuel Used data on power up
    3591             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3592             :  */
    3593           0 : int decodeECU_SetFuelUsedResetFlagPacket(const void* _pg_pkt, ECUSystemCommands* cmd, uint8_t* reset)
    3594             : {
    3595           0 :     int _pg_byteindex = 0;
    3596           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3597           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3598             : 
    3599             :     // Verify the packet identifier
    3600           0 :     if(getECUPacketID(_pg_pkt) != getECU_SetFuelUsedResetFlagPacketID())
    3601           0 :         return 0;
    3602             : 
    3603           0 :     if(_pg_numbytes < getECU_SetFuelUsedResetFlagMinDataLength())
    3604           0 :         return 0;
    3605             : 
    3606             :     // The command enumeration
    3607             :     // Range of cmd is 0 to 255.
    3608             :     // Decoded value must be CMD_ECU_FUEL_USED_RESET_ON_STARTUP
    3609           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3610           0 :     if ((*cmd) != CMD_ECU_FUEL_USED_RESET_ON_STARTUP)
    3611           0 :         return 0;
    3612             : 
    3613             :     // 1 = Reset Fuel Used data on powerup 0 = Do not reset Fuel Used data on power up
    3614             :     // Range of reset is 0 to 255.
    3615           0 :     (*reset) = uint8FromBytes(_pg_data, &_pg_byteindex);
    3616             : 
    3617           0 :     return 1;
    3618             : 
    3619             : }// decodeECU_SetFuelUsedResetFlagPacket
    3620             : 
    3621             : /*!
    3622             :  * \brief Create the ECU_SetGovernorMode packet
    3623             :  *
    3624             :  * Manually set the RPM governor mode.
    3625             :  * \param _pg_pkt points to the packet which will be created by this function
    3626             :  * \param mode is MODE 0 = Governor Off (Open loop throttle control) 1 = Governor based on throttle command 2 = Governor based on RPM command
    3627             :  */
    3628           0 : void encodeECU_SetGovernorModePacket(void* _pg_pkt, ECUGovernorMode mode)
    3629             : {
    3630           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3631           0 :     int _pg_byteindex = 0;
    3632             : 
    3633             :     // The command enumeration
    3634           0 :     uint8ToBytes((uint8_t)(CMD_ECU_SET_GOVERNOR_MODE), _pg_data, &_pg_byteindex);
    3635             : 
    3636             :     // MODE 0 = Governor Off (Open loop throttle control) 1 = Governor based on throttle command 2 = Governor based on RPM command
    3637             :     // Range of mode is 0 to 255.
    3638           0 :     uint8ToBytes(mode, _pg_data, &_pg_byteindex);
    3639             : 
    3640             :     // complete the process of creating the packet
    3641           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SetGovernorModePacketID());
    3642             : 
    3643           0 : }// encodeECU_SetGovernorModePacket
    3644             : 
    3645             : /*!
    3646             :  * \brief Decode the ECU_SetGovernorMode packet
    3647             :  *
    3648             :  * Manually set the RPM governor mode.
    3649             :  * \param _pg_pkt points to the packet being decoded by this function
    3650             :  * \param cmd receives The command enumeration
    3651             :  * \param mode receives MODE 0 = Governor Off (Open loop throttle control) 1 = Governor based on throttle command 2 = Governor based on RPM command
    3652             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3653             :  */
    3654           0 : int decodeECU_SetGovernorModePacket(const void* _pg_pkt, ECUSystemCommands* cmd, ECUGovernorMode* mode)
    3655             : {
    3656           0 :     int _pg_byteindex = 0;
    3657           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3658           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3659             : 
    3660             :     // Verify the packet identifier
    3661           0 :     if(getECUPacketID(_pg_pkt) != getECU_SetGovernorModePacketID())
    3662           0 :         return 0;
    3663             : 
    3664           0 :     if(_pg_numbytes < getECU_SetGovernorModeMinDataLength())
    3665           0 :         return 0;
    3666             : 
    3667             :     // The command enumeration
    3668             :     // Range of cmd is 0 to 255.
    3669             :     // Decoded value must be CMD_ECU_SET_GOVERNOR_MODE
    3670           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3671           0 :     if ((*cmd) != CMD_ECU_SET_GOVERNOR_MODE)
    3672           0 :         return 0;
    3673             : 
    3674             :     // MODE 0 = Governor Off (Open loop throttle control) 1 = Governor based on throttle command 2 = Governor based on RPM command
    3675             :     // Range of mode is 0 to 255.
    3676           0 :     (*mode) = (ECUGovernorMode)uint8FromBytes(_pg_data, &_pg_byteindex);
    3677             : 
    3678           0 :     return 1;
    3679             : 
    3680             : }// decodeECU_SetGovernorModePacket
    3681             : 
    3682             : /*!
    3683             :  * \brief Create the ECU_SetSerialMode packet
    3684             :  *
    3685             :  * Set the serial mode used for Autronic relay. When Autronic relay is enabled
    3686             :  * the external serial port of the ECU is reconfigured to connect to ECUCal,
    3687             :  * relaying bytes to the internal autronic processor; while still allowing the
    3688             :  * auxiliary processor to see telemetry from Autronic. This is fundamentally
    3689             :  * different from using the switch to calibration mode, which bypasses the
    3690             :  * auxiliary processor altogether, cutting it off from autronic telemetry.
    3691             :  * \param _pg_pkt points to the packet which will be created by this function
    3692             :  * \param mode is The serial relay mode to command
    3693             :  */
    3694           0 : void encodeECU_SetSerialModePacket(void* _pg_pkt, ECUAutronicRelayState mode)
    3695             : {
    3696           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3697           0 :     int _pg_byteindex = 0;
    3698             : 
    3699             :     // The command enumeration
    3700           0 :     uint8ToBytes((uint8_t)(CMD_ECU_SET_SERIAL_MODE), _pg_data, &_pg_byteindex);
    3701             : 
    3702             :     // The serial relay mode to command
    3703             :     // Range of mode is 0 to 255.
    3704           0 :     uint8ToBytes(mode, _pg_data, &_pg_byteindex);
    3705             : 
    3706             :     // complete the process of creating the packet
    3707           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SetSerialModePacketID());
    3708             : 
    3709           0 : }// encodeECU_SetSerialModePacket
    3710             : 
    3711             : /*!
    3712             :  * \brief Decode the ECU_SetSerialMode packet
    3713             :  *
    3714             :  * Set the serial mode used for Autronic relay. When Autronic relay is enabled
    3715             :  * the external serial port of the ECU is reconfigured to connect to ECUCal,
    3716             :  * relaying bytes to the internal autronic processor; while still allowing the
    3717             :  * auxiliary processor to see telemetry from Autronic. This is fundamentally
    3718             :  * different from using the switch to calibration mode, which bypasses the
    3719             :  * auxiliary processor altogether, cutting it off from autronic telemetry.
    3720             :  * \param _pg_pkt points to the packet being decoded by this function
    3721             :  * \param cmd receives The command enumeration
    3722             :  * \param mode receives The serial relay mode to command
    3723             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3724             :  */
    3725           0 : int decodeECU_SetSerialModePacket(const void* _pg_pkt, ECUSystemCommands* cmd, ECUAutronicRelayState* mode)
    3726             : {
    3727           0 :     int _pg_byteindex = 0;
    3728           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3729           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3730             : 
    3731             :     // Verify the packet identifier
    3732           0 :     if(getECUPacketID(_pg_pkt) != getECU_SetSerialModePacketID())
    3733           0 :         return 0;
    3734             : 
    3735           0 :     if(_pg_numbytes < getECU_SetSerialModeMinDataLength())
    3736           0 :         return 0;
    3737             : 
    3738             :     // The command enumeration
    3739             :     // Range of cmd is 0 to 255.
    3740             :     // Decoded value must be CMD_ECU_SET_SERIAL_MODE
    3741           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3742           0 :     if ((*cmd) != CMD_ECU_SET_SERIAL_MODE)
    3743           0 :         return 0;
    3744             : 
    3745             :     // The serial relay mode to command
    3746             :     // Range of mode is 0 to 255.
    3747           0 :     (*mode) = (ECUAutronicRelayState)uint8FromBytes(_pg_data, &_pg_byteindex);
    3748             : 
    3749           0 :     return 1;
    3750             : 
    3751             : }// decodeECU_SetSerialModePacket
    3752             : 
    3753             : /*!
    3754             :  * \brief Create the ECU_SetECUAddress packet
    3755             :  *
    3756             :  * Set a custom address value for the ECU.
    3757             :  * \param _pg_pkt points to the packet which will be created by this function
    3758             :  * \param address is ECU address in the range {1, 65534}
    3759             :  */
    3760           0 : void encodeECU_SetECUAddressPacket(void* _pg_pkt, uint16_t address)
    3761             : {
    3762           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3763           0 :     int _pg_byteindex = 0;
    3764             : 
    3765             :     // The command enumeration
    3766           0 :     uint8ToBytes((uint8_t)(CMD_ECU_SET_NODE_ID), _pg_data, &_pg_byteindex);
    3767             : 
    3768             :     // ECU address in the range {1, 65534}
    3769             :     // Range of address is 0 to 65535.
    3770           0 :     uint16ToBeBytes(address, _pg_data, &_pg_byteindex);
    3771             : 
    3772             :     // complete the process of creating the packet
    3773           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SetECUAddressPacketID());
    3774             : 
    3775           0 : }// encodeECU_SetECUAddressPacket
    3776             : 
    3777             : /*!
    3778             :  * \brief Decode the ECU_SetECUAddress packet
    3779             :  *
    3780             :  * Set a custom address value for the ECU.
    3781             :  * \param _pg_pkt points to the packet being decoded by this function
    3782             :  * \param cmd receives The command enumeration
    3783             :  * \param address receives ECU address in the range {1, 65534}
    3784             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3785             :  */
    3786           0 : int decodeECU_SetECUAddressPacket(const void* _pg_pkt, ECUSystemCommands* cmd, uint16_t* address)
    3787             : {
    3788           0 :     int _pg_byteindex = 0;
    3789           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3790           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3791             : 
    3792             :     // Verify the packet identifier
    3793           0 :     if(getECUPacketID(_pg_pkt) != getECU_SetECUAddressPacketID())
    3794           0 :         return 0;
    3795             : 
    3796           0 :     if(_pg_numbytes < getECU_SetECUAddressMinDataLength())
    3797           0 :         return 0;
    3798             : 
    3799             :     // The command enumeration
    3800             :     // Range of cmd is 0 to 255.
    3801             :     // Decoded value must be CMD_ECU_SET_NODE_ID
    3802           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3803           0 :     if ((*cmd) != CMD_ECU_SET_NODE_ID)
    3804           0 :         return 0;
    3805             : 
    3806             :     // ECU address in the range {1, 65534}
    3807             :     // Range of address is 0 to 65535.
    3808           0 :     (*address) = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    3809             : 
    3810           0 :     return 1;
    3811             : 
    3812             : }// decodeECU_SetECUAddressPacket
    3813             : 
    3814             : /*!
    3815             :  * \brief Create the ECU_SetUserData packet
    3816             :  *
    3817             :  * Save a single byte of USER_DATA in EEPROM.
    3818             :  * \param _pg_pkt points to the packet which will be created by this function
    3819             :  * \param index is USER_DATA address (0 to 7)
    3820             :  * \param userdata is USER_DATA variable
    3821             :  */
    3822           0 : void encodeECU_SetUserDataPacket(void* _pg_pkt, uint8_t index, uint8_t userdata)
    3823             : {
    3824           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3825           0 :     int _pg_byteindex = 0;
    3826             : 
    3827             :     // The command enumeration
    3828           0 :     uint8ToBytes((uint8_t)(CMD_ECU_SET_USER_DATA), _pg_data, &_pg_byteindex);
    3829             : 
    3830             :     // USER_DATA address (0 to 7)
    3831             :     // Range of index is 0 to 255.
    3832           0 :     uint8ToBytes(index, _pg_data, &_pg_byteindex);
    3833             : 
    3834             :     // USER_DATA variable
    3835             :     // Range of userdata is 0 to 255.
    3836           0 :     uint8ToBytes(userdata, _pg_data, &_pg_byteindex);
    3837             : 
    3838             :     // complete the process of creating the packet
    3839           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_SetUserDataPacketID());
    3840             : 
    3841           0 : }// encodeECU_SetUserDataPacket
    3842             : 
    3843             : /*!
    3844             :  * \brief Decode the ECU_SetUserData packet
    3845             :  *
    3846             :  * Save a single byte of USER_DATA in EEPROM.
    3847             :  * \param _pg_pkt points to the packet being decoded by this function
    3848             :  * \param cmd receives The command enumeration
    3849             :  * \param index receives USER_DATA address (0 to 7)
    3850             :  * \param userdata receives USER_DATA variable
    3851             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3852             :  */
    3853           0 : int decodeECU_SetUserDataPacket(const void* _pg_pkt, ECUSystemCommands* cmd, uint8_t* index, uint8_t* userdata)
    3854             : {
    3855           0 :     int _pg_byteindex = 0;
    3856           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3857           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3858             : 
    3859             :     // Verify the packet identifier
    3860           0 :     if(getECUPacketID(_pg_pkt) != getECU_SetUserDataPacketID())
    3861           0 :         return 0;
    3862             : 
    3863           0 :     if(_pg_numbytes < getECU_SetUserDataMinDataLength())
    3864           0 :         return 0;
    3865             : 
    3866             :     // The command enumeration
    3867             :     // Range of cmd is 0 to 255.
    3868             :     // Decoded value must be CMD_ECU_SET_USER_DATA
    3869           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3870           0 :     if ((*cmd) != CMD_ECU_SET_USER_DATA)
    3871           0 :         return 0;
    3872             : 
    3873             :     // USER_DATA address (0 to 7)
    3874             :     // Range of index is 0 to 255.
    3875           0 :     (*index) = uint8FromBytes(_pg_data, &_pg_byteindex);
    3876             : 
    3877             :     // USER_DATA variable
    3878             :     // Range of userdata is 0 to 255.
    3879           0 :     (*userdata) = uint8FromBytes(_pg_data, &_pg_byteindex);
    3880             : 
    3881           0 :     return 1;
    3882             : 
    3883             : }// decodeECU_SetUserDataPacket
    3884             : 
    3885             : /*!
    3886             :  * \brief Create the ECU_ResetEngineTime packet
    3887             :  *
    3888             :  * Reset the engine runtime.
    3889             :  * \param _pg_pkt points to the packet which will be created by this function
    3890             :  * \param time is The new value of the engine time counter in seconds
    3891             :  */
    3892           0 : void encodeECU_ResetEngineTimePacket(void* _pg_pkt, uint32_t time)
    3893             : {
    3894           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3895           0 :     int _pg_byteindex = 0;
    3896             : 
    3897             :     // The command enumeration
    3898           0 :     uint8ToBytes((uint8_t)(CMD_ECU_RESET_ENGINE_TIME), _pg_data, &_pg_byteindex);
    3899             : 
    3900             :     // The new value of the engine time counter in seconds
    3901             :     // Range of time is 0 to 16777215.
    3902           0 :     uint24ToBeBytes((uint32_t)(limitMax(time, 16777215)), _pg_data, &_pg_byteindex);
    3903             : 
    3904             :     // complete the process of creating the packet
    3905           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_ResetEngineTimePacketID());
    3906             : 
    3907           0 : }// encodeECU_ResetEngineTimePacket
    3908             : 
    3909             : /*!
    3910             :  * \brief Decode the ECU_ResetEngineTime packet
    3911             :  *
    3912             :  * Reset the engine runtime.
    3913             :  * \param _pg_pkt points to the packet being decoded by this function
    3914             :  * \param cmd receives The command enumeration
    3915             :  * \param time receives The new value of the engine time counter in seconds
    3916             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3917             :  */
    3918           0 : int decodeECU_ResetEngineTimePacket(const void* _pg_pkt, ECUSystemCommands* cmd, uint32_t* time)
    3919             : {
    3920           0 :     int _pg_byteindex = 0;
    3921           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3922           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3923             : 
    3924             :     // Verify the packet identifier
    3925           0 :     if(getECUPacketID(_pg_pkt) != getECU_ResetEngineTimePacketID())
    3926           0 :         return 0;
    3927             : 
    3928           0 :     if(_pg_numbytes < getECU_ResetEngineTimeMinDataLength())
    3929           0 :         return 0;
    3930             : 
    3931             :     // this packet has default fields, make sure they are set
    3932           0 :     (*time) = 0;
    3933             : 
    3934             :     // The command enumeration
    3935             :     // Range of cmd is 0 to 255.
    3936             :     // Decoded value must be CMD_ECU_RESET_ENGINE_TIME
    3937           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    3938           0 :     if ((*cmd) != CMD_ECU_RESET_ENGINE_TIME)
    3939           0 :         return 0;
    3940             : 
    3941           0 :     if(_pg_byteindex + 3 > _pg_numbytes)
    3942           0 :         return 1;
    3943             : 
    3944             :     // The new value of the engine time counter in seconds
    3945             :     // Range of time is 0 to 16777215.
    3946           0 :     (*time) = (uint32_t)uint24FromBeBytes(_pg_data, &_pg_byteindex);
    3947             : 
    3948           0 :     return 1;
    3949             : 
    3950             : }// decodeECU_ResetEngineTimePacket
    3951             : 
    3952             : /*!
    3953             :  * \brief Create the ECU_ResetECU packet
    3954             :  *
    3955             :  * Reset the ECU
    3956             :  * \param _pg_pkt points to the packet which will be created by this function
    3957             :  */
    3958           0 : void encodeECU_ResetECUPacket(void* _pg_pkt)
    3959             : {
    3960           0 :     uint8_t* _pg_data = getECUPacketData(_pg_pkt);
    3961           0 :     int _pg_byteindex = 0;
    3962             : 
    3963             :     // The command enumeration
    3964           0 :     uint8ToBytes((uint8_t)(CMD_ECU_RESET_ECU), _pg_data, &_pg_byteindex);
    3965             : 
    3966             :     // Required constant value
    3967           0 :     uint8ToBytes((uint8_t)(0xA5), _pg_data, &_pg_byteindex);
    3968             : 
    3969             :     // Required constant value
    3970           0 :     uint8ToBytes((uint8_t)(0x5A), _pg_data, &_pg_byteindex);
    3971             : 
    3972             :     // Required constant value
    3973           0 :     uint8ToBytes((uint8_t)(0xCC), _pg_data, &_pg_byteindex);
    3974             : 
    3975             :     // complete the process of creating the packet
    3976           0 :     finishECUPacket(_pg_pkt, _pg_byteindex, getECU_ResetECUPacketID());
    3977             : 
    3978           0 : }// encodeECU_ResetECUPacket
    3979             : 
    3980             : /*!
    3981             :  * \brief Decode the ECU_ResetECU packet
    3982             :  *
    3983             :  * Reset the ECU
    3984             :  * \param _pg_pkt points to the packet being decoded by this function
    3985             :  * \param cmd receives The command enumeration
    3986             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    3987             :  */
    3988           0 : int decodeECU_ResetECUPacket(const void* _pg_pkt, ECUSystemCommands* cmd)
    3989             : {
    3990           0 :     int _pg_byteindex = 0;
    3991           0 :     const uint8_t* _pg_data = getECUPacketDataConst(_pg_pkt);
    3992           0 :     int _pg_numbytes = getECUPacketSize(_pg_pkt);
    3993             : 
    3994             :     // Verify the packet identifier
    3995           0 :     if(getECUPacketID(_pg_pkt) != getECU_ResetECUPacketID())
    3996           0 :         return 0;
    3997             : 
    3998           0 :     if(_pg_numbytes < getECU_ResetECUMinDataLength())
    3999           0 :         return 0;
    4000             : 
    4001             :     // The command enumeration
    4002             :     // Range of cmd is 0 to 255.
    4003             :     // Decoded value must be CMD_ECU_RESET_ECU
    4004           0 :     (*cmd) = (ECUSystemCommands)uint8FromBytes(_pg_data, &_pg_byteindex);
    4005           0 :     if ((*cmd) != CMD_ECU_RESET_ECU)
    4006           0 :         return 0;
    4007             : 
    4008             :     // Required constant value
    4009           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xA5)
    4010           0 :         return 0;
    4011             : 
    4012             :     // Required constant value
    4013           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0x5A)
    4014           0 :         return 0;
    4015             : 
    4016             :     // Required constant value
    4017           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xCC)
    4018           0 :         return 0;
    4019             : 
    4020           0 :     return 1;
    4021             : 
    4022             : }// decodeECU_ResetECUPacket
    4023             : // end of ECUPackets.c

Generated by: LCOV version 1.14