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

          Line data    Source code
       1             : // ECUDefines.c was generated by ProtoGen version 3.2.a
       2             : 
       3             : /*
       4             :  * This file is free software: you can redistribute it and/or modify it
       5             :  * under the terms of the GNU General Public License as published by the
       6             :  * Free Software Foundation, either version 3 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * This file is distributed in the hope that it will be useful, but
      10             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      12             :  * See the GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License along
      15             :  * with this program.  If not, see <http://www.gnu.org/licenses/>.
      16             :  *
      17             :  * Author: Oliver Walters / Currawong Engineering Pty Ltd
      18             :  */
      19             :  
      20             : 
      21             : #include "ECUDefines.h"
      22             : #include "fielddecode.h"
      23             : #include "fieldencode.h"
      24             : #include "scaleddecode.h"
      25             : #include "scaledencode.h"
      26             : 
      27             : /*!
      28             :  * \brief Encode a ECU_AuxiliaryErrorBits_t into a byte array
      29             :  *
      30             : 
      31             :  * \param _pg_data points to the byte array to add encoded data to
      32             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
      33             :  * \param _pg_user is the data to encode in the byte array
      34             :  */
      35           0 : void encodeECU_AuxiliaryErrorBits_t(uint8_t* _pg_data, int* _pg_bytecount, const ECU_AuxiliaryErrorBits_t* _pg_user)
      36             : {
      37           0 :     int _pg_byteindex = *_pg_bytecount;
      38             : 
      39             :     // 1 if CAN servo is not connected
      40           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->servoLink == true) ? 1 : 0) << 7;
      41             : 
      42             :     // 1 if CAN servo is reporting a position error
      43           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->servoPosition == true) ? 1 : 0) << 6;
      44             : 
      45             :     // Reserved for future use
      46             :     // Range of reserved_A is 0 to 63.
      47           0 :     _pg_data[_pg_byteindex] |= (uint8_t)_pg_user->reserved_A;
      48             : 
      49             :     // Reserved for future use
      50             :     // Range of reserved_B is 0 to 255.
      51           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)_pg_user->reserved_B;
      52             : 
      53             :     // Reserved for future use
      54             :     // Range of reserved_C is 0 to 255.
      55           0 :     _pg_data[_pg_byteindex + 2] = (uint8_t)_pg_user->reserved_C;
      56             : 
      57             :     // Reserved for future use
      58             :     // Range of reserved_D is 0 to 255.
      59           0 :     _pg_data[_pg_byteindex + 3] = (uint8_t)_pg_user->reserved_D;
      60           0 :     _pg_byteindex += 4; // close bit field
      61             : 
      62           0 :     *_pg_bytecount = _pg_byteindex;
      63             : 
      64           0 : }// encodeECU_AuxiliaryErrorBits_t
      65             : 
      66             : /*!
      67             :  * \brief Decode a ECU_AuxiliaryErrorBits_t from a byte array
      68             :  *
      69             : 
      70             :  * \param _pg_data points to the byte array to decoded data from
      71             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
      72             :  * \param _pg_user is the data to decode from the byte array
      73             :  * \return 1 if the data are decoded, else 0.
      74             :  */
      75           0 : int decodeECU_AuxiliaryErrorBits_t(const uint8_t* _pg_data, int* _pg_bytecount, ECU_AuxiliaryErrorBits_t* _pg_user)
      76             : {
      77           0 :     int _pg_byteindex = *_pg_bytecount;
      78             : 
      79             :     // 1 if CAN servo is not connected
      80           0 :     _pg_user->servoLink = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
      81             : 
      82             :     // 1 if CAN servo is reporting a position error
      83           0 :     _pg_user->servoPosition = (((_pg_data[_pg_byteindex] >> 6) & 0x1)) ? true : false;
      84             : 
      85             :     // Reserved for future use
      86             :     // Range of reserved_A is 0 to 63.
      87           0 :     _pg_user->reserved_A = ((_pg_data[_pg_byteindex]) & 0x3F);
      88             : 
      89             :     // Reserved for future use
      90             :     // Range of reserved_B is 0 to 255.
      91           0 :     _pg_user->reserved_B = _pg_data[_pg_byteindex + 1];
      92             : 
      93             :     // Reserved for future use
      94             :     // Range of reserved_C is 0 to 255.
      95           0 :     _pg_user->reserved_C = _pg_data[_pg_byteindex + 2];
      96             : 
      97             :     // Reserved for future use
      98             :     // Range of reserved_D is 0 to 255.
      99           0 :     _pg_user->reserved_D = _pg_data[_pg_byteindex + 3];
     100           0 :     _pg_byteindex += 4; // close bit field
     101             : 
     102           0 :     *_pg_bytecount = _pg_byteindex;
     103             : 
     104           0 :     return 1;
     105             : 
     106             : }// decodeECU_AuxiliaryErrorBits_t
     107             : 
     108             : /*!
     109             :  * \brief Encode a ECU_AutronicErrorBits_t into a byte array
     110             :  *
     111             : 
     112             :  * \param _pg_data points to the byte array to add encoded data to
     113             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     114             :  * \param _pg_user is the data to encode in the byte array
     115             :  */
     116           0 : void encodeECU_AutronicErrorBits_t(uint8_t* _pg_data, int* _pg_bytecount, const ECU_AutronicErrorBits_t* _pg_user)
     117             : {
     118           0 :     int _pg_byteindex = *_pg_bytecount;
     119             : 
     120             :     // Reserved
     121           0 :     _pg_data[_pg_byteindex] = 0;
     122             : 
     123             :     // Knock control error
     124           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)_pg_user->knockControl << 7;
     125             : 
     126             :     // AF closed loop error
     127           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_user->afCloseLoop << 6;
     128             : 
     129             :     // EEPROM error
     130           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_user->eepromError << 5;
     131             : 
     132             :     // CMOS RAM error
     133           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_user->cmosRam << 4;
     134             : 
     135             :     // Over voltage error
     136           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_user->overVoltage << 3;
     137             : 
     138             :     // Power down error
     139           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_user->powerDown << 2;
     140             : 
     141             :     // Knock sensor error
     142           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_user->knockSensor << 1;
     143             : 
     144             :     // Over boost error
     145           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_user->overBoost;
     146             : 
     147             :     // CAM2 position error
     148           0 :     _pg_data[_pg_byteindex + 2] = (uint8_t)_pg_user->cam2Pos << 7;
     149             : 
     150             :     // CAM1 position error
     151           0 :     _pg_data[_pg_byteindex + 2] |= (uint8_t)_pg_user->cam1Pos << 6;
     152             : 
     153             :     // High speed input 1 error
     154           0 :     _pg_data[_pg_byteindex + 2] |= (uint8_t)_pg_user->highSpeedInput2 << 5;
     155             : 
     156             :     // High speed input 2 error
     157           0 :     _pg_data[_pg_byteindex + 2] |= (uint8_t)_pg_user->highSpeedInput1 << 4;
     158             : 
     159             :     // Set if too many cylinder pulses
     160           0 :     _pg_data[_pg_byteindex + 2] |= (uint8_t)_pg_user->tooManyCylPulse << 3;
     161             : 
     162             :     // Set if too few cylinder pulses
     163           0 :     _pg_data[_pg_byteindex + 2] |= (uint8_t)_pg_user->tooFewCylPulse << 2;
     164             : 
     165             :     // Set if sync input pulse missing
     166           0 :     _pg_data[_pg_byteindex + 2] |= (uint8_t)_pg_user->syncInputPulseMissing << 1;
     167             : 
     168             :     // Set if cylinder input pulse missing
     169           0 :     _pg_data[_pg_byteindex + 2] |= (uint8_t)_pg_user->cylinderInputPulseMissing;
     170             : 
     171             :     // Air fuel sensor 2 error
     172           0 :     _pg_data[_pg_byteindex + 3] = (uint8_t)_pg_user->af2Sensor << 7;
     173             : 
     174             :     // Air fuel sensor 1 error
     175           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)_pg_user->af1Sensor << 6;
     176             : 
     177             :     // Barometric pressure sensor error
     178           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)_pg_user->baroSensor << 5;
     179             : 
     180             :     // Exhaust back pressure sensor error
     181           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)_pg_user->ebpSensor << 4;
     182             : 
     183             :     // Manifold pressure sensor error
     184           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)_pg_user->mapSensor << 3;
     185             : 
     186             :     // Throttle position sensor error
     187           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)_pg_user->tpsSensor << 2;
     188             : 
     189             :     // Cylinder head temperature sensor error
     190           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)_pg_user->chtSensor << 1;
     191             : 
     192             :     // Manifold pressure sensor error
     193           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)_pg_user->matSensor;
     194           0 :     _pg_byteindex += 4; // close bit field
     195             : 
     196           0 :     *_pg_bytecount = _pg_byteindex;
     197             : 
     198           0 : }// encodeECU_AutronicErrorBits_t
     199             : 
     200             : /*!
     201             :  * \brief Decode a ECU_AutronicErrorBits_t from a byte array
     202             :  *
     203             : 
     204             :  * \param _pg_data points to the byte array to decoded data from
     205             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     206             :  * \param _pg_user is the data to decode from the byte array
     207             :  * \return 1 if the data are decoded, else 0.
     208             :  */
     209           0 : int decodeECU_AutronicErrorBits_t(const uint8_t* _pg_data, int* _pg_bytecount, ECU_AutronicErrorBits_t* _pg_user)
     210             : {
     211           0 :     int _pg_byteindex = *_pg_bytecount;
     212             : 
     213             :     // Reserved
     214             : 
     215             :     // Knock control error
     216           0 :     _pg_user->knockControl = (_pg_data[_pg_byteindex + 1] >> 7);
     217             : 
     218             :     // AF closed loop error
     219           0 :     _pg_user->afCloseLoop = ((_pg_data[_pg_byteindex + 1] >> 6) & 0x1);
     220             : 
     221             :     // EEPROM error
     222           0 :     _pg_user->eepromError = ((_pg_data[_pg_byteindex + 1] >> 5) & 0x1);
     223             : 
     224             :     // CMOS RAM error
     225           0 :     _pg_user->cmosRam = ((_pg_data[_pg_byteindex + 1] >> 4) & 0x1);
     226             : 
     227             :     // Over voltage error
     228           0 :     _pg_user->overVoltage = ((_pg_data[_pg_byteindex + 1] >> 3) & 0x1);
     229             : 
     230             :     // Power down error
     231           0 :     _pg_user->powerDown = ((_pg_data[_pg_byteindex + 1] >> 2) & 0x1);
     232             : 
     233             :     // Knock sensor error
     234           0 :     _pg_user->knockSensor = ((_pg_data[_pg_byteindex + 1] >> 1) & 0x1);
     235             : 
     236             :     // Over boost error
     237           0 :     _pg_user->overBoost = ((_pg_data[_pg_byteindex + 1]) & 0x1);
     238             : 
     239             :     // CAM2 position error
     240           0 :     _pg_user->cam2Pos = (_pg_data[_pg_byteindex + 2] >> 7);
     241             : 
     242             :     // CAM1 position error
     243           0 :     _pg_user->cam1Pos = ((_pg_data[_pg_byteindex + 2] >> 6) & 0x1);
     244             : 
     245             :     // High speed input 1 error
     246           0 :     _pg_user->highSpeedInput2 = ((_pg_data[_pg_byteindex + 2] >> 5) & 0x1);
     247             : 
     248             :     // High speed input 2 error
     249           0 :     _pg_user->highSpeedInput1 = ((_pg_data[_pg_byteindex + 2] >> 4) & 0x1);
     250             : 
     251             :     // Set if too many cylinder pulses
     252           0 :     _pg_user->tooManyCylPulse = ((_pg_data[_pg_byteindex + 2] >> 3) & 0x1);
     253             : 
     254             :     // Set if too few cylinder pulses
     255           0 :     _pg_user->tooFewCylPulse = ((_pg_data[_pg_byteindex + 2] >> 2) & 0x1);
     256             : 
     257             :     // Set if sync input pulse missing
     258           0 :     _pg_user->syncInputPulseMissing = ((_pg_data[_pg_byteindex + 2] >> 1) & 0x1);
     259             : 
     260             :     // Set if cylinder input pulse missing
     261           0 :     _pg_user->cylinderInputPulseMissing = ((_pg_data[_pg_byteindex + 2]) & 0x1);
     262             : 
     263             :     // Air fuel sensor 2 error
     264           0 :     _pg_user->af2Sensor = (_pg_data[_pg_byteindex + 3] >> 7);
     265             : 
     266             :     // Air fuel sensor 1 error
     267           0 :     _pg_user->af1Sensor = ((_pg_data[_pg_byteindex + 3] >> 6) & 0x1);
     268             : 
     269             :     // Barometric pressure sensor error
     270           0 :     _pg_user->baroSensor = ((_pg_data[_pg_byteindex + 3] >> 5) & 0x1);
     271             : 
     272             :     // Exhaust back pressure sensor error
     273           0 :     _pg_user->ebpSensor = ((_pg_data[_pg_byteindex + 3] >> 4) & 0x1);
     274             : 
     275             :     // Manifold pressure sensor error
     276           0 :     _pg_user->mapSensor = ((_pg_data[_pg_byteindex + 3] >> 3) & 0x1);
     277             : 
     278             :     // Throttle position sensor error
     279           0 :     _pg_user->tpsSensor = ((_pg_data[_pg_byteindex + 3] >> 2) & 0x1);
     280             : 
     281             :     // Cylinder head temperature sensor error
     282           0 :     _pg_user->chtSensor = ((_pg_data[_pg_byteindex + 3] >> 1) & 0x1);
     283             : 
     284             :     // Manifold pressure sensor error
     285           0 :     _pg_user->matSensor = ((_pg_data[_pg_byteindex + 3]) & 0x1);
     286           0 :     _pg_byteindex += 4; // close bit field
     287             : 
     288           0 :     *_pg_bytecount = _pg_byteindex;
     289             : 
     290           0 :     return 1;
     291             : 
     292             : }// decodeECU_AutronicErrorBits_t
     293             : 
     294             : /*!
     295             :  * \brief Encode a ECU_ErrorBits_t into a byte array
     296             :  *
     297             : 
     298             :  * \param _pg_data points to the byte array to add encoded data to
     299             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     300             :  * \param _pg_user is the data to encode in the byte array
     301             :  */
     302           0 : void encodeECU_ErrorBits_t(uint8_t* _pg_data, int* _pg_bytecount, const ECU_ErrorBits_t* _pg_user)
     303             : {
     304           0 :     int _pg_byteindex = *_pg_bytecount;
     305             : 
     306             :     // Error information for autronic processor
     307           0 :     encodeECU_AutronicErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->autronic);
     308             : 
     309             :     // Error information for auxiliary processor
     310           0 :     encodeECU_AuxiliaryErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->auxiliary);
     311             : 
     312           0 :     *_pg_bytecount = _pg_byteindex;
     313             : 
     314           0 : }// encodeECU_ErrorBits_t
     315             : 
     316             : /*!
     317             :  * \brief Decode a ECU_ErrorBits_t from a byte array
     318             :  *
     319             : 
     320             :  * \param _pg_data points to the byte array to decoded data from
     321             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     322             :  * \param _pg_user is the data to decode from the byte array
     323             :  * \return 1 if the data are decoded, else 0.
     324             :  */
     325           0 : int decodeECU_ErrorBits_t(const uint8_t* _pg_data, int* _pg_bytecount, ECU_ErrorBits_t* _pg_user)
     326             : {
     327           0 :     int _pg_byteindex = *_pg_bytecount;
     328             : 
     329             :     // Error information for autronic processor
     330           0 :     if(decodeECU_AutronicErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->autronic) == 0)
     331           0 :         return 0;
     332             : 
     333             :     // Error information for auxiliary processor
     334           0 :     if(decodeECU_AuxiliaryErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->auxiliary) == 0)
     335           0 :         return 0;
     336             : 
     337           0 :     *_pg_bytecount = _pg_byteindex;
     338             : 
     339           0 :     return 1;
     340             : 
     341             : }// decodeECU_ErrorBits_t
     342             : 
     343             : /*!
     344             :  * \brief Encode a ECU_ThrottleDelayConfigBits_t into a byte array
     345             :  *
     346             : 
     347             :  * \param _pg_data points to the byte array to add encoded data to
     348             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     349             :  * \param _pg_user is the data to encode in the byte array
     350             :  */
     351           0 : void encodeECU_ThrottleDelayConfigBits_t(uint8_t* _pg_data, int* _pg_bytecount, const ECU_ThrottleDelayConfigBits_t* _pg_user)
     352             : {
     353           0 :     int _pg_byteindex = *_pg_bytecount;
     354             : 
     355             :     // reserved for future use
     356             :     // Range of reserved is 0 to 127.
     357           0 :     _pg_data[_pg_byteindex] = (uint8_t)_pg_user->reserved << 1;
     358             : 
     359             :     // Set to base the delay on temperature, else the delay is manually set
     360           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->delayOnTemp == true) ? 1 : 0);
     361           0 :     _pg_byteindex += 1; // close bit field
     362             : 
     363           0 :     *_pg_bytecount = _pg_byteindex;
     364             : 
     365           0 : }// encodeECU_ThrottleDelayConfigBits_t
     366             : 
     367             : /*!
     368             :  * \brief Decode a ECU_ThrottleDelayConfigBits_t from a byte array
     369             :  *
     370             : 
     371             :  * \param _pg_data points to the byte array to decoded data from
     372             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     373             :  * \param _pg_user is the data to decode from the byte array
     374             :  * \return 1 if the data are decoded, else 0.
     375             :  */
     376           0 : int decodeECU_ThrottleDelayConfigBits_t(const uint8_t* _pg_data, int* _pg_bytecount, ECU_ThrottleDelayConfigBits_t* _pg_user)
     377             : {
     378           0 :     int _pg_byteindex = *_pg_bytecount;
     379             : 
     380             :     // reserved for future use
     381             :     // Range of reserved is 0 to 127.
     382           0 :     _pg_user->reserved = (_pg_data[_pg_byteindex] >> 1);
     383             : 
     384             :     // Set to base the delay on temperature, else the delay is manually set
     385           0 :     _pg_user->delayOnTemp = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
     386           0 :     _pg_byteindex += 1; // close bit field
     387             : 
     388           0 :     *_pg_bytecount = _pg_byteindex;
     389             : 
     390           0 :     return 1;
     391             : 
     392             : }// decodeECU_ThrottleDelayConfigBits_t
     393             : 
     394             : /*!
     395             :  * \brief Encode a ECU_ThrottleConfigBits_t into a byte array
     396             :  *
     397             : 
     398             :  * \param _pg_data points to the byte array to add encoded data to
     399             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     400             :  * \param _pg_user is the data to encode in the byte array
     401             :  */
     402           0 : void encodeECU_ThrottleConfigBits_t(uint8_t* _pg_data, int* _pg_bytecount, const ECU_ThrottleConfigBits_t* _pg_user)
     403             : {
     404           0 :     int _pg_byteindex = *_pg_bytecount;
     405             : 
     406             :     // Enable pass-through of CAN servo data over serial link
     407           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->servoPassthrough == true) ? 1 : 0) << 7;
     408             : 
     409             :     // Reserved for future use
     410             : 
     411             :     // Set if the CAN throttle is detected
     412           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->canThrottleDetected == true) ? 1 : 0) << 1;
     413             : 
     414             :     // Set if CAN throttle is enabled. This bit is ignored when this packet is sent to the ECU. To enable CAN throttle you must use system commands
     415           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->canThrottle == true) ? 1 : 0);
     416           0 :     _pg_byteindex += 1; // close bit field
     417             : 
     418           0 :     *_pg_bytecount = _pg_byteindex;
     419             : 
     420           0 : }// encodeECU_ThrottleConfigBits_t
     421             : 
     422             : /*!
     423             :  * \brief Decode a ECU_ThrottleConfigBits_t from a byte array
     424             :  *
     425             : 
     426             :  * \param _pg_data points to the byte array to decoded data from
     427             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     428             :  * \param _pg_user is the data to decode from the byte array
     429             :  * \return 1 if the data are decoded, else 0.
     430             :  */
     431           0 : int decodeECU_ThrottleConfigBits_t(const uint8_t* _pg_data, int* _pg_bytecount, ECU_ThrottleConfigBits_t* _pg_user)
     432             : {
     433           0 :     int _pg_byteindex = *_pg_bytecount;
     434             : 
     435             :     // Enable pass-through of CAN servo data over serial link
     436           0 :     _pg_user->servoPassthrough = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
     437             : 
     438             :     // Reserved for future use
     439             : 
     440             :     // Set if the CAN throttle is detected
     441           0 :     _pg_user->canThrottleDetected = (((_pg_data[_pg_byteindex] >> 1) & 0x1)) ? true : false;
     442             : 
     443             :     // Set if CAN throttle is enabled. This bit is ignored when this packet is sent to the ECU. To enable CAN throttle you must use system commands
     444           0 :     _pg_user->canThrottle = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
     445           0 :     _pg_byteindex += 1; // close bit field
     446             : 
     447           0 :     *_pg_bytecount = _pg_byteindex;
     448             : 
     449           0 :     return 1;
     450             : 
     451             : }// decodeECU_ThrottleConfigBits_t
     452             : 
     453             : /*!
     454             :  * \brief Encode a ECU_ThrottleCurveConfigBits_t into a byte array
     455             :  *
     456             : 
     457             :  * \param _pg_data points to the byte array to add encoded data to
     458             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     459             :  * \param _pg_user is the data to encode in the byte array
     460             :  */
     461           0 : void encodeECU_ThrottleCurveConfigBits_t(uint8_t* _pg_data, int* _pg_bytecount, const ECU_ThrottleCurveConfigBits_t* _pg_user)
     462             : {
     463           0 :     int _pg_byteindex = *_pg_bytecount;
     464             : 
     465             :     // Reserved for future use
     466           0 :     _pg_data[_pg_byteindex] = 0;
     467             : 
     468             :     // Throttle curve is active
     469           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->curveActive == true) ? 1 : 0);
     470           0 :     _pg_byteindex += 1; // close bit field
     471             : 
     472           0 :     *_pg_bytecount = _pg_byteindex;
     473             : 
     474           0 : }// encodeECU_ThrottleCurveConfigBits_t
     475             : 
     476             : /*!
     477             :  * \brief Decode a ECU_ThrottleCurveConfigBits_t from a byte array
     478             :  *
     479             : 
     480             :  * \param _pg_data points to the byte array to decoded data from
     481             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     482             :  * \param _pg_user is the data to decode from the byte array
     483             :  * \return 1 if the data are decoded, else 0.
     484             :  */
     485           0 : int decodeECU_ThrottleCurveConfigBits_t(const uint8_t* _pg_data, int* _pg_bytecount, ECU_ThrottleCurveConfigBits_t* _pg_user)
     486             : {
     487           0 :     int _pg_byteindex = *_pg_bytecount;
     488             : 
     489             :     // Reserved for future use
     490             : 
     491             :     // Throttle curve is active
     492           0 :     _pg_user->curveActive = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
     493           0 :     _pg_byteindex += 1; // close bit field
     494             : 
     495           0 :     *_pg_bytecount = _pg_byteindex;
     496             : 
     497           0 :     return 1;
     498             : 
     499             : }// decodeECU_ThrottleCurveConfigBits_t
     500             : 
     501             : /*!
     502             :  * \brief Encode a ECU_ECUSettings_t into a byte array
     503             :  *
     504             : 
     505             :  * \param _pg_data points to the byte array to add encoded data to
     506             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     507             :  * \param _pg_user is the data to encode in the byte array
     508             :  */
     509           0 : void encodeECU_ECUSettings_t(uint8_t* _pg_data, int* _pg_bytecount, const ECU_ECUSettings_t* _pg_user)
     510             : {
     511           0 :     int _pg_byteindex = *_pg_bytecount;
     512             : 
     513             :     // Range of powerCycles is 0 to 65535.
     514           0 :     uint16ToBeBytes(_pg_user->powerCycles, _pg_data, &_pg_byteindex);
     515             : 
     516             :     // Deprecated - DO NOT USE
     517             :     // Range of customerID_deprecated is 0 to 65535.
     518           0 :     uint16ToBeBytes(_pg_user->customerID_deprecated, _pg_data, &_pg_byteindex);
     519             : 
     520             :     // Range of versionHardware is 0 to 255.
     521           0 :     uint8ToBytes(_pg_user->versionHardware, _pg_data, &_pg_byteindex);
     522             : 
     523             :     // reserved for future use
     524             :     // Range of reservedA is 0 to 255.
     525           0 :     uint8ToBytes(_pg_user->reservedA, _pg_data, &_pg_byteindex);
     526             : 
     527             :     // reserved for future use
     528             :     // Range of reservedB is 0 to 255.
     529           0 :     uint8ToBytes(_pg_user->reservedB, _pg_data, &_pg_byteindex);
     530             : 
     531           0 :     *_pg_bytecount = _pg_byteindex;
     532             : 
     533           0 : }// encodeECU_ECUSettings_t
     534             : 
     535             : /*!
     536             :  * \brief Decode a ECU_ECUSettings_t from a byte array
     537             :  *
     538             : 
     539             :  * \param _pg_data points to the byte array to decoded data from
     540             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     541             :  * \param _pg_user is the data to decode from the byte array
     542             :  * \return 1 if the data are decoded, else 0.
     543             :  */
     544           0 : int decodeECU_ECUSettings_t(const uint8_t* _pg_data, int* _pg_bytecount, ECU_ECUSettings_t* _pg_user)
     545             : {
     546           0 :     int _pg_byteindex = *_pg_bytecount;
     547             : 
     548             :     // Range of powerCycles is 0 to 65535.
     549           0 :     _pg_user->powerCycles = uint16FromBeBytes(_pg_data, &_pg_byteindex);
     550             : 
     551             :     // Deprecated - DO NOT USE
     552             :     // Range of customerID_deprecated is 0 to 65535.
     553           0 :     _pg_user->customerID_deprecated = uint16FromBeBytes(_pg_data, &_pg_byteindex);
     554             : 
     555             :     // Range of versionHardware is 0 to 255.
     556           0 :     _pg_user->versionHardware = uint8FromBytes(_pg_data, &_pg_byteindex);
     557             : 
     558             :     // reserved for future use
     559             :     // Range of reservedA is 0 to 255.
     560           0 :     _pg_user->reservedA = uint8FromBytes(_pg_data, &_pg_byteindex);
     561             : 
     562             :     // reserved for future use
     563             :     // Range of reservedB is 0 to 255.
     564           0 :     _pg_user->reservedB = uint8FromBytes(_pg_data, &_pg_byteindex);
     565             : 
     566           0 :     *_pg_bytecount = _pg_byteindex;
     567             : 
     568           0 :     return 1;
     569             : 
     570             : }// decodeECU_ECUSettings_t
     571             : 
     572             : /*!
     573             :  * \brief Encode a ECU_CompileOptions_t into a byte array
     574             :  *
     575             : 
     576             :  * \param _pg_data points to the byte array to add encoded data to
     577             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     578             :  * \param _pg_user is the data to encode in the byte array
     579             :  */
     580           0 : void encodeECU_CompileOptions_t(uint8_t* _pg_data, int* _pg_bytecount, const ECU_CompileOptions_t* _pg_user)
     581             : {
     582           0 :     int _pg_byteindex = *_pg_bytecount;
     583             : 
     584             :     // If set, the ECU will pass servo CAN packet data over the serial link
     585           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->servoPassthrough == true) ? 1 : 0) << 7;
     586             : 
     587             :     // If set, the ECU will decode CAN messages in the PICCOLO_DATA_UP group
     588           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->piccoloUplink == true) ? 1 : 0) << 6;
     589             : 
     590             :     // If set, the ECU supports Autronic message passthrough
     591           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->autronicRelay == true) ? 1 : 0) << 5;
     592             : 
     593             :     // If set, the ECU supports redundant fuel pump control
     594           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->dualPump == true) ? 1 : 0) << 4;
     595             : 
     596             :     // If set, the ECU runs a PI controller for fuel pressure. If not set, it uses bang-bang control
     597           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->piPump == true) ? 1 : 0) << 3;
     598             : 
     599             :     // If set, the ECU will automatically compensate for degredation of the MAP sensor over time
     600           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->mapCorrection == true) ? 1 : 0) << 2;
     601             : 
     602             :     // If set, the ECU watchdog timer is enabled
     603           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->watchdog == true) ? 1 : 0) << 1;
     604             : 
     605             :     // If set, the ECU is compiled with extra debug functionality enabled
     606           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->debug == true) ? 1 : 0);
     607           0 :     _pg_byteindex += 1; // close bit field
     608             : 
     609             :     // Reserved for future use
     610           0 :     uint8ToBytes((uint8_t)(0), _pg_data, &_pg_byteindex);
     611             : 
     612           0 :     *_pg_bytecount = _pg_byteindex;
     613             : 
     614           0 : }// encodeECU_CompileOptions_t
     615             : 
     616             : /*!
     617             :  * \brief Decode a ECU_CompileOptions_t from a byte array
     618             :  *
     619             : 
     620             :  * \param _pg_data points to the byte array to decoded data from
     621             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     622             :  * \param _pg_user is the data to decode from the byte array
     623             :  * \return 1 if the data are decoded, else 0.
     624             :  */
     625           0 : int decodeECU_CompileOptions_t(const uint8_t* _pg_data, int* _pg_bytecount, ECU_CompileOptions_t* _pg_user)
     626             : {
     627           0 :     int _pg_byteindex = *_pg_bytecount;
     628             : 
     629             :     // If set, the ECU will pass servo CAN packet data over the serial link
     630           0 :     _pg_user->servoPassthrough = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
     631             : 
     632             :     // If set, the ECU will decode CAN messages in the PICCOLO_DATA_UP group
     633           0 :     _pg_user->piccoloUplink = (((_pg_data[_pg_byteindex] >> 6) & 0x1)) ? true : false;
     634             : 
     635             :     // If set, the ECU supports Autronic message passthrough
     636           0 :     _pg_user->autronicRelay = (((_pg_data[_pg_byteindex] >> 5) & 0x1)) ? true : false;
     637             : 
     638             :     // If set, the ECU supports redundant fuel pump control
     639           0 :     _pg_user->dualPump = (((_pg_data[_pg_byteindex] >> 4) & 0x1)) ? true : false;
     640             : 
     641             :     // If set, the ECU runs a PI controller for fuel pressure. If not set, it uses bang-bang control
     642           0 :     _pg_user->piPump = (((_pg_data[_pg_byteindex] >> 3) & 0x1)) ? true : false;
     643             : 
     644             :     // If set, the ECU will automatically compensate for degredation of the MAP sensor over time
     645           0 :     _pg_user->mapCorrection = (((_pg_data[_pg_byteindex] >> 2) & 0x1)) ? true : false;
     646             : 
     647             :     // If set, the ECU watchdog timer is enabled
     648           0 :     _pg_user->watchdog = (((_pg_data[_pg_byteindex] >> 1) & 0x1)) ? true : false;
     649             : 
     650             :     // If set, the ECU is compiled with extra debug functionality enabled
     651           0 :     _pg_user->debug = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
     652           0 :     _pg_byteindex += 1; // close bit field
     653             : 
     654             :     // Reserved for future use
     655           0 :     _pg_byteindex += 1;
     656             : 
     657           0 :     *_pg_bytecount = _pg_byteindex;
     658             : 
     659           0 :     return 1;
     660             : 
     661             : }// decodeECU_CompileOptions_t
     662             : 
     663             : // end of ECUDefines.c

Generated by: LCOV version 1.14