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

          Line data    Source code
       1             : // CortexPackets.c was generated by ProtoGen version 3.5.c
       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             : #include "CortexPackets.h"
      21             : #include "fielddecode.h"
      22             : #include "fieldencode.h"
      23             : #include "scaleddecode.h"
      24             : #include "scaledencode.h"
      25             : #include "CortexDefines.h"
      26             : 
      27             : /*!
      28             :  * \brief Create the Cortex_Standby packet
      29             :  *
      30             :  * Command the Cortex into standby mode
      31             :  * \param _pg_pkt points to the packet which will be created by this function
      32             :  */
      33           0 : void encodeCortex_StandbyPacket(void* _pg_pkt)
      34             : {
      35           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
      36           0 :     int _pg_byteindex = 0;
      37             : 
      38             :     // Constant value required for standby sequence
      39           0 :     uint8ToBytes((uint8_t)(0xA0), _pg_data, &_pg_byteindex);
      40             : 
      41             :     // Constant value required for standby sequence
      42           0 :     uint8ToBytes((uint8_t)(0xB0), _pg_data, &_pg_byteindex);
      43             : 
      44             :     // complete the process of creating the packet
      45           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_StandbyPacketID());
      46             : 
      47           0 : }// encodeCortex_StandbyPacket
      48             : 
      49             : /*!
      50             :  * \brief Decode the Cortex_Standby packet
      51             :  *
      52             :  * Command the Cortex into standby mode
      53             :  * \param _pg_pkt points to the packet being decoded by this function
      54             :  * \return 0 is returned if the packet ID or size is wrong, else 1
      55             :  */
      56           0 : int decodeCortex_StandbyPacket(const void* _pg_pkt)
      57             : {
      58           0 :     int _pg_byteindex = 0;
      59           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
      60           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
      61             : 
      62             :     // Verify the packet identifier
      63           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_StandbyPacketID())
      64           0 :         return 0;
      65             : 
      66           0 :     if(_pg_numbytes < getCortex_StandbyMinDataLength())
      67           0 :         return 0;
      68             : 
      69             :     // Constant value required for standby sequence
      70           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xA0)
      71           0 :         return 0;
      72             : 
      73             :     // Constant value required for standby sequence
      74           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xB0)
      75           0 :         return 0;
      76             : 
      77           0 :     return 1;
      78             : 
      79             : }// decodeCortex_StandbyPacket
      80             : 
      81             : /*!
      82             :  * \brief Create the Cortex_Preflight packet
      83             :  *
      84             :  * Command the Cortex to enter preflight mode
      85             :  * \param _pg_pkt points to the packet which will be created by this function
      86             :  */
      87           0 : void encodeCortex_PreflightPacket(void* _pg_pkt)
      88             : {
      89           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
      90           0 :     int _pg_byteindex = 0;
      91             : 
      92             :     // Constant value required for preflight sequence
      93           0 :     uint8ToBytes((uint8_t)(0x3C), _pg_data, &_pg_byteindex);
      94             : 
      95             :     // Constant value required for preflight sequence
      96           0 :     uint8ToBytes((uint8_t)(0xC3), _pg_data, &_pg_byteindex);
      97             : 
      98             :     // complete the process of creating the packet
      99           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_PreflightPacketID());
     100             : 
     101           0 : }// encodeCortex_PreflightPacket
     102             : 
     103             : /*!
     104             :  * \brief Decode the Cortex_Preflight packet
     105             :  *
     106             :  * Command the Cortex to enter preflight mode
     107             :  * \param _pg_pkt points to the packet being decoded by this function
     108             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     109             :  */
     110           0 : int decodeCortex_PreflightPacket(const void* _pg_pkt)
     111             : {
     112           0 :     int _pg_byteindex = 0;
     113           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
     114           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
     115             : 
     116             :     // Verify the packet identifier
     117           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_PreflightPacketID())
     118           0 :         return 0;
     119             : 
     120           0 :     if(_pg_numbytes < getCortex_PreflightMinDataLength())
     121           0 :         return 0;
     122             : 
     123             :     // Constant value required for preflight sequence
     124           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0x3C)
     125           0 :         return 0;
     126             : 
     127             :     // Constant value required for preflight sequence
     128           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xC3)
     129           0 :         return 0;
     130             : 
     131           0 :     return 1;
     132             : 
     133             : }// decodeCortex_PreflightPacket
     134             : 
     135             : /*!
     136             :  * \brief Create the Cortex_StartCranking packet
     137             :  *
     138             :  * Command the Cortex to start cranking the engine
     139             :  * \param _pg_pkt points to the packet which will be created by this function
     140             :  */
     141           0 : void encodeCortex_StartCrankingPacket(void* _pg_pkt)
     142             : {
     143           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     144           0 :     int _pg_byteindex = 0;
     145             : 
     146             :     // Constant value required for cranking sequence
     147           0 :     uint8ToBytes((uint8_t)(0x5A), _pg_data, &_pg_byteindex);
     148             : 
     149             :     // Constant value required for cranking sequence
     150           0 :     uint8ToBytes((uint8_t)(0xA5), _pg_data, &_pg_byteindex);
     151             : 
     152             :     // complete the process of creating the packet
     153           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_StartCrankingPacketID());
     154             : 
     155           0 : }// encodeCortex_StartCrankingPacket
     156             : 
     157             : /*!
     158             :  * \brief Decode the Cortex_StartCranking packet
     159             :  *
     160             :  * Command the Cortex to start cranking the engine
     161             :  * \param _pg_pkt points to the packet being decoded by this function
     162             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     163             :  */
     164           0 : int decodeCortex_StartCrankingPacket(const void* _pg_pkt)
     165             : {
     166           0 :     int _pg_byteindex = 0;
     167           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
     168           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
     169             : 
     170             :     // Verify the packet identifier
     171           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_StartCrankingPacketID())
     172           0 :         return 0;
     173             : 
     174           0 :     if(_pg_numbytes < getCortex_StartCrankingMinDataLength())
     175           0 :         return 0;
     176             : 
     177             :     // Constant value required for cranking sequence
     178           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0x5A)
     179           0 :         return 0;
     180             : 
     181             :     // Constant value required for cranking sequence
     182           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xA5)
     183           0 :         return 0;
     184             : 
     185           0 :     return 1;
     186             : 
     187             : }// decodeCortex_StartCrankingPacket
     188             : 
     189             : /*!
     190             :  * \brief Create the Cortex_TelemetryStatus packet
     191             :  *
     192             :  * Overall system status information
     193             :  * \param _pg_pkt points to the packet which will be created by this function
     194             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     195             :  */
     196           0 : void encodeCortex_TelemetryStatusPacketStructure(void* _pg_pkt, const Cortex_TelemetryStatus_t* _pg_user)
     197             : {
     198           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     199           0 :     int _pg_byteindex = 0;
     200             : 
     201             :     // System status bits
     202           0 :     encodeCortex_StatusBits_t(_pg_data, &_pg_byteindex, &_pg_user->status);
     203             : 
     204             :     // System warning bits
     205           0 :     encodeCortex_WarningBits_t(_pg_data, &_pg_byteindex, &_pg_user->warning);
     206             : 
     207             :     // System error bits
     208           0 :     encodeCortex_ErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->error);
     209             : 
     210             :     // complete the process of creating the packet
     211           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryStatusPacketID());
     212             : 
     213           0 : }// encodeCortex_TelemetryStatusPacketStructure
     214             : 
     215             : /*!
     216             :  * \brief Decode the Cortex_TelemetryStatus packet
     217             :  *
     218             :  * Overall system status information
     219             :  * \param _pg_pkt points to the packet being decoded by this function
     220             :  * \param _pg_user receives the data decoded from the packet
     221             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     222             :  */
     223           0 : int decodeCortex_TelemetryStatusPacketStructure(const void* _pg_pkt, Cortex_TelemetryStatus_t* _pg_user)
     224             : {
     225             :     int _pg_numbytes;
     226           0 :     int _pg_byteindex = 0;
     227             :     const uint8_t* _pg_data;
     228             : 
     229             :     // Verify the packet identifier
     230           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryStatusPacketID())
     231           0 :         return 0;
     232             : 
     233             :     // Verify the packet size
     234           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
     235           0 :     if(_pg_numbytes < getCortex_TelemetryStatusMinDataLength())
     236           0 :         return 0;
     237             : 
     238             :     // The raw data from the packet
     239           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
     240             : 
     241             :     // System status bits
     242           0 :     if(decodeCortex_StatusBits_t(_pg_data, &_pg_byteindex, &_pg_user->status) == 0)
     243           0 :         return 0;
     244             : 
     245             :     // System warning bits
     246           0 :     if(decodeCortex_WarningBits_t(_pg_data, &_pg_byteindex, &_pg_user->warning) == 0)
     247           0 :         return 0;
     248             : 
     249             :     // System error bits
     250           0 :     if(decodeCortex_ErrorBits_t(_pg_data, &_pg_byteindex, &_pg_user->error) == 0)
     251           0 :         return 0;
     252             : 
     253           0 :     return 1;
     254             : 
     255             : }// decodeCortex_TelemetryStatusPacketStructure
     256             : 
     257             : /*!
     258             :  * \brief Create the Cortex_TelemetryStatus packet
     259             :  *
     260             :  * Overall system status information
     261             :  * \param _pg_pkt points to the packet which will be created by this function
     262             :  * \param status is System status bits
     263             :  * \param warning is System warning bits
     264             :  * \param error is System error bits
     265             :  */
     266           0 : void encodeCortex_TelemetryStatusPacket(void* _pg_pkt, const Cortex_StatusBits_t* status, const Cortex_WarningBits_t* warning, const Cortex_ErrorBits_t* error)
     267             : {
     268           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     269           0 :     int _pg_byteindex = 0;
     270             : 
     271             :     // System status bits
     272           0 :     encodeCortex_StatusBits_t(_pg_data, &_pg_byteindex, status);
     273             : 
     274             :     // System warning bits
     275           0 :     encodeCortex_WarningBits_t(_pg_data, &_pg_byteindex, warning);
     276             : 
     277             :     // System error bits
     278           0 :     encodeCortex_ErrorBits_t(_pg_data, &_pg_byteindex, error);
     279             : 
     280             :     // complete the process of creating the packet
     281           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryStatusPacketID());
     282             : 
     283           0 : }// encodeCortex_TelemetryStatusPacket
     284             : 
     285             : /*!
     286             :  * \brief Decode the Cortex_TelemetryStatus packet
     287             :  *
     288             :  * Overall system status information
     289             :  * \param _pg_pkt points to the packet being decoded by this function
     290             :  * \param status receives System status bits
     291             :  * \param warning receives System warning bits
     292             :  * \param error receives System error bits
     293             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     294             :  */
     295           0 : int decodeCortex_TelemetryStatusPacket(const void* _pg_pkt, Cortex_StatusBits_t* status, Cortex_WarningBits_t* warning, Cortex_ErrorBits_t* error)
     296             : {
     297           0 :     int _pg_byteindex = 0;
     298           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
     299           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
     300             : 
     301             :     // Verify the packet identifier
     302           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryStatusPacketID())
     303           0 :         return 0;
     304             : 
     305           0 :     if(_pg_numbytes < getCortex_TelemetryStatusMinDataLength())
     306           0 :         return 0;
     307             : 
     308             :     // System status bits
     309           0 :     if(decodeCortex_StatusBits_t(_pg_data, &_pg_byteindex, status) == 0)
     310           0 :         return 0;
     311             : 
     312             :     // System warning bits
     313           0 :     if(decodeCortex_WarningBits_t(_pg_data, &_pg_byteindex, warning) == 0)
     314           0 :         return 0;
     315             : 
     316             :     // System error bits
     317           0 :     if(decodeCortex_ErrorBits_t(_pg_data, &_pg_byteindex, error) == 0)
     318           0 :         return 0;
     319             : 
     320           0 :     return 1;
     321             : 
     322             : }// decodeCortex_TelemetryStatusPacket
     323             : 
     324             : /*!
     325             :  * \brief Create the Cortex_TelemetryGenerator packet
     326             :  *
     327             :  * Generator status information
     328             :  * \param _pg_pkt points to the packet which will be created by this function
     329             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     330             :  */
     331           0 : void encodeCortex_TelemetryGeneratorPacketStructure(void* _pg_pkt, const Cortex_TelemetryGenerator_t* _pg_user)
     332             : {
     333           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     334           0 :     int _pg_byteindex = 0;
     335             : 
     336             :     // Generator speed
     337             :     // Range of rpm is -32768 to 32767.
     338           0 :     int16ToBeBytes(_pg_user->rpm, _pg_data, &_pg_byteindex);
     339             : 
     340             :     // Generator duty cycle
     341             :     // Range of dutyCycle is 0 to 255.
     342           0 :     uint8ToBytes(_pg_user->dutyCycle, _pg_data, &_pg_byteindex);
     343             : 
     344             :     // Generator voltage
     345             :     // Range of voltage is 0.0f to 255.0f.
     346           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->voltage, _pg_data, &_pg_byteindex, 0.0f, 257.0f);
     347             : 
     348             :     // Generator current
     349             :     // Range of current is -255.0f to 255.0f.
     350           0 :     float32ScaledTo2SignedBeBytes(_pg_user->current, _pg_data, &_pg_byteindex, 128.498039f);
     351             : 
     352             :     // Generator temperature
     353             :     // Range of temperature is -55.0f to 200.0f.
     354           0 :     float32ScaledTo1UnsignedBytes(_pg_user->temperature, _pg_data, &_pg_byteindex, -55.0f, 1.0f);
     355             : 
     356             :     // complete the process of creating the packet
     357           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryGeneratorPacketID());
     358             : 
     359           0 : }// encodeCortex_TelemetryGeneratorPacketStructure
     360             : 
     361             : /*!
     362             :  * \brief Decode the Cortex_TelemetryGenerator packet
     363             :  *
     364             :  * Generator status information
     365             :  * \param _pg_pkt points to the packet being decoded by this function
     366             :  * \param _pg_user receives the data decoded from the packet
     367             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     368             :  */
     369           0 : int decodeCortex_TelemetryGeneratorPacketStructure(const void* _pg_pkt, Cortex_TelemetryGenerator_t* _pg_user)
     370             : {
     371             :     int _pg_numbytes;
     372           0 :     int _pg_byteindex = 0;
     373             :     const uint8_t* _pg_data;
     374             : 
     375             :     // Verify the packet identifier
     376           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryGeneratorPacketID())
     377           0 :         return 0;
     378             : 
     379             :     // Verify the packet size
     380           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
     381           0 :     if(_pg_numbytes < getCortex_TelemetryGeneratorMinDataLength())
     382           0 :         return 0;
     383             : 
     384             :     // The raw data from the packet
     385           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
     386             : 
     387             :     // Generator speed
     388             :     // Range of rpm is -32768 to 32767.
     389           0 :     _pg_user->rpm = int16FromBeBytes(_pg_data, &_pg_byteindex);
     390             : 
     391             :     // Generator duty cycle
     392             :     // Range of dutyCycle is 0 to 255.
     393           0 :     _pg_user->dutyCycle = uint8FromBytes(_pg_data, &_pg_byteindex);
     394             : 
     395             :     // Generator voltage
     396             :     // Range of voltage is 0.0f to 255.0f.
     397           0 :     _pg_user->voltage = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/257.0f);
     398             : 
     399             :     // Generator current
     400             :     // Range of current is -255.0f to 255.0f.
     401           0 :     _pg_user->current = float32ScaledFrom2SignedBeBytes(_pg_data, &_pg_byteindex, 1.0f/128.498039f);
     402             : 
     403             :     // Generator temperature
     404             :     // Range of temperature is -55.0f to 200.0f.
     405           0 :     _pg_user->temperature = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -55.0f, 1.0f/1.0f);
     406             : 
     407           0 :     return 1;
     408             : 
     409             : }// decodeCortex_TelemetryGeneratorPacketStructure
     410             : 
     411             : /*!
     412             :  * \brief Create the Cortex_TelemetryGenerator packet
     413             :  *
     414             :  * Generator status information
     415             :  * \param _pg_pkt points to the packet which will be created by this function
     416             :  * \param rpm is Generator speed
     417             :  * \param dutyCycle is Generator duty cycle
     418             :  * \param voltage is Generator voltage
     419             :  * \param current is Generator current
     420             :  * \param temperature is Generator temperature
     421             :  */
     422           0 : void encodeCortex_TelemetryGeneratorPacket(void* _pg_pkt, int16_t rpm, uint8_t dutyCycle, float voltage, float current, float temperature)
     423             : {
     424           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     425           0 :     int _pg_byteindex = 0;
     426             : 
     427             :     // Generator speed
     428             :     // Range of rpm is -32768 to 32767.
     429           0 :     int16ToBeBytes(rpm, _pg_data, &_pg_byteindex);
     430             : 
     431             :     // Generator duty cycle
     432             :     // Range of dutyCycle is 0 to 255.
     433           0 :     uint8ToBytes(dutyCycle, _pg_data, &_pg_byteindex);
     434             : 
     435             :     // Generator voltage
     436             :     // Range of voltage is 0.0f to 255.0f.
     437           0 :     float32ScaledTo2UnsignedBeBytes(voltage, _pg_data, &_pg_byteindex, 0.0f, 257.0f);
     438             : 
     439             :     // Generator current
     440             :     // Range of current is -255.0f to 255.0f.
     441           0 :     float32ScaledTo2SignedBeBytes(current, _pg_data, &_pg_byteindex, 128.498039f);
     442             : 
     443             :     // Generator temperature
     444             :     // Range of temperature is -55.0f to 200.0f.
     445           0 :     float32ScaledTo1UnsignedBytes(temperature, _pg_data, &_pg_byteindex, -55.0f, 1.0f);
     446             : 
     447             :     // complete the process of creating the packet
     448           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryGeneratorPacketID());
     449             : 
     450           0 : }// encodeCortex_TelemetryGeneratorPacket
     451             : 
     452             : /*!
     453             :  * \brief Decode the Cortex_TelemetryGenerator packet
     454             :  *
     455             :  * Generator status information
     456             :  * \param _pg_pkt points to the packet being decoded by this function
     457             :  * \param rpm receives Generator speed
     458             :  * \param dutyCycle receives Generator duty cycle
     459             :  * \param voltage receives Generator voltage
     460             :  * \param current receives Generator current
     461             :  * \param temperature receives Generator temperature
     462             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     463             :  */
     464           0 : int decodeCortex_TelemetryGeneratorPacket(const void* _pg_pkt, int16_t* rpm, uint8_t* dutyCycle, float* voltage, float* current, float* temperature)
     465             : {
     466           0 :     int _pg_byteindex = 0;
     467           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
     468           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
     469             : 
     470             :     // Verify the packet identifier
     471           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryGeneratorPacketID())
     472           0 :         return 0;
     473             : 
     474           0 :     if(_pg_numbytes < getCortex_TelemetryGeneratorMinDataLength())
     475           0 :         return 0;
     476             : 
     477             :     // Generator speed
     478             :     // Range of rpm is -32768 to 32767.
     479           0 :     (*rpm) = int16FromBeBytes(_pg_data, &_pg_byteindex);
     480             : 
     481             :     // Generator duty cycle
     482             :     // Range of dutyCycle is 0 to 255.
     483           0 :     (*dutyCycle) = uint8FromBytes(_pg_data, &_pg_byteindex);
     484             : 
     485             :     // Generator voltage
     486             :     // Range of voltage is 0.0f to 255.0f.
     487           0 :     (*voltage) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/257.0f);
     488             : 
     489             :     // Generator current
     490             :     // Range of current is -255.0f to 255.0f.
     491           0 :     (*current) = float32ScaledFrom2SignedBeBytes(_pg_data, &_pg_byteindex, 1.0f/128.498039f);
     492             : 
     493             :     // Generator temperature
     494             :     // Range of temperature is -55.0f to 200.0f.
     495           0 :     (*temperature) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -55.0f, 1.0f/1.0f);
     496             : 
     497           0 :     return 1;
     498             : 
     499             : }// decodeCortex_TelemetryGeneratorPacket
     500             : 
     501             : /*!
     502             :  * \brief Create the Cortex_TelemetryBattery packet
     503             :  *
     504             :  * Battery status information
     505             :  * \param _pg_pkt points to the packet which will be created by this function
     506             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     507             :  */
     508           0 : void encodeCortex_TelemetryBatteryPacketStructure(void* _pg_pkt, const Cortex_TelemetryBattery_t* _pg_user)
     509             : {
     510           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     511           0 :     int _pg_byteindex = 0;
     512             : 
     513             :     // Battery voltage
     514             :     // Range of voltage is 0.0f to 255.0f.
     515           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->voltage, _pg_data, &_pg_byteindex, 0.0f, 257.0f);
     516             : 
     517             :     // Battery current
     518             :     // Range of current is -255.0f to 255.0f.
     519           0 :     float32ScaledTo2SignedBeBytes(_pg_user->current, _pg_data, &_pg_byteindex, 128.498039f);
     520             : 
     521             :     // Battery temperature
     522             :     // Range of temperature is -55.0f to 200.0f.
     523           0 :     float32ScaledTo1UnsignedBytes(_pg_user->temperature, _pg_data, &_pg_byteindex, -55.0f, 1.0f);
     524             : 
     525             :     // complete the process of creating the packet
     526           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryBatteryPacketID());
     527             : 
     528           0 : }// encodeCortex_TelemetryBatteryPacketStructure
     529             : 
     530             : /*!
     531             :  * \brief Decode the Cortex_TelemetryBattery packet
     532             :  *
     533             :  * Battery status information
     534             :  * \param _pg_pkt points to the packet being decoded by this function
     535             :  * \param _pg_user receives the data decoded from the packet
     536             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     537             :  */
     538           0 : int decodeCortex_TelemetryBatteryPacketStructure(const void* _pg_pkt, Cortex_TelemetryBattery_t* _pg_user)
     539             : {
     540             :     int _pg_numbytes;
     541           0 :     int _pg_byteindex = 0;
     542             :     const uint8_t* _pg_data;
     543             : 
     544             :     // Verify the packet identifier
     545           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryBatteryPacketID())
     546           0 :         return 0;
     547             : 
     548             :     // Verify the packet size
     549           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
     550           0 :     if(_pg_numbytes < getCortex_TelemetryBatteryMinDataLength())
     551           0 :         return 0;
     552             : 
     553             :     // The raw data from the packet
     554           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
     555             : 
     556             :     // Battery voltage
     557             :     // Range of voltage is 0.0f to 255.0f.
     558           0 :     _pg_user->voltage = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/257.0f);
     559             : 
     560             :     // Battery current
     561             :     // Range of current is -255.0f to 255.0f.
     562           0 :     _pg_user->current = float32ScaledFrom2SignedBeBytes(_pg_data, &_pg_byteindex, 1.0f/128.498039f);
     563             : 
     564             :     // Battery temperature
     565             :     // Range of temperature is -55.0f to 200.0f.
     566           0 :     _pg_user->temperature = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -55.0f, 1.0f/1.0f);
     567             : 
     568           0 :     return 1;
     569             : 
     570             : }// decodeCortex_TelemetryBatteryPacketStructure
     571             : 
     572             : /*!
     573             :  * \brief Create the Cortex_TelemetryBattery packet
     574             :  *
     575             :  * Battery status information
     576             :  * \param _pg_pkt points to the packet which will be created by this function
     577             :  * \param voltage is Battery voltage
     578             :  * \param current is Battery current
     579             :  * \param temperature is Battery temperature
     580             :  */
     581           0 : void encodeCortex_TelemetryBatteryPacket(void* _pg_pkt, float voltage, float current, float temperature)
     582             : {
     583           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     584           0 :     int _pg_byteindex = 0;
     585             : 
     586             :     // Battery voltage
     587             :     // Range of voltage is 0.0f to 255.0f.
     588           0 :     float32ScaledTo2UnsignedBeBytes(voltage, _pg_data, &_pg_byteindex, 0.0f, 257.0f);
     589             : 
     590             :     // Battery current
     591             :     // Range of current is -255.0f to 255.0f.
     592           0 :     float32ScaledTo2SignedBeBytes(current, _pg_data, &_pg_byteindex, 128.498039f);
     593             : 
     594             :     // Battery temperature
     595             :     // Range of temperature is -55.0f to 200.0f.
     596           0 :     float32ScaledTo1UnsignedBytes(temperature, _pg_data, &_pg_byteindex, -55.0f, 1.0f);
     597             : 
     598             :     // complete the process of creating the packet
     599           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryBatteryPacketID());
     600             : 
     601           0 : }// encodeCortex_TelemetryBatteryPacket
     602             : 
     603             : /*!
     604             :  * \brief Decode the Cortex_TelemetryBattery packet
     605             :  *
     606             :  * Battery status information
     607             :  * \param _pg_pkt points to the packet being decoded by this function
     608             :  * \param voltage receives Battery voltage
     609             :  * \param current receives Battery current
     610             :  * \param temperature receives Battery temperature
     611             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     612             :  */
     613           0 : int decodeCortex_TelemetryBatteryPacket(const void* _pg_pkt, float* voltage, float* current, float* temperature)
     614             : {
     615           0 :     int _pg_byteindex = 0;
     616           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
     617           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
     618             : 
     619             :     // Verify the packet identifier
     620           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryBatteryPacketID())
     621           0 :         return 0;
     622             : 
     623           0 :     if(_pg_numbytes < getCortex_TelemetryBatteryMinDataLength())
     624           0 :         return 0;
     625             : 
     626             :     // Battery voltage
     627             :     // Range of voltage is 0.0f to 255.0f.
     628           0 :     (*voltage) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/257.0f);
     629             : 
     630             :     // Battery current
     631             :     // Range of current is -255.0f to 255.0f.
     632           0 :     (*current) = float32ScaledFrom2SignedBeBytes(_pg_data, &_pg_byteindex, 1.0f/128.498039f);
     633             : 
     634             :     // Battery temperature
     635             :     // Range of temperature is -55.0f to 200.0f.
     636           0 :     (*temperature) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -55.0f, 1.0f/1.0f);
     637             : 
     638           0 :     return 1;
     639             : 
     640             : }// decodeCortex_TelemetryBatteryPacket
     641             : 
     642             : /*!
     643             :  * \brief Create the Cortex_TelemetryController packet
     644             :  *
     645             :  * Controller status information
     646             :  * \param _pg_pkt points to the packet which will be created by this function
     647             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     648             :  */
     649           0 : void encodeCortex_TelemetryControllerPacketStructure(void* _pg_pkt, const Cortex_TelemetryController_t* _pg_user)
     650             : {
     651           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     652           0 :     int _pg_byteindex = 0;
     653             : 
     654             :     // Generator rectifier temperature
     655             :     // Range of rectifierTemperature is -55.0f to 200.0f.
     656           0 :     float32ScaledTo1UnsignedBytes(_pg_user->rectifierTemperature, _pg_data, &_pg_byteindex, -55.0f, 1.0f);
     657             : 
     658             :     // Voltage regulator temperature
     659             :     // Range of regulatorTemperature is -55.0f to 200.0f.
     660           0 :     float32ScaledTo1UnsignedBytes(_pg_user->regulatorTemperature, _pg_data, &_pg_byteindex, -55.0f, 1.0f);
     661             : 
     662             :     // Generator run time
     663             :     // Range of runTime is 0 to 16777215.
     664           0 :     uint24ToBeBytes((uint32_t)(limitMax(_pg_user->runTime, 16777215)), _pg_data, &_pg_byteindex);
     665             : 
     666             :     // complete the process of creating the packet
     667           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryControllerPacketID());
     668             : 
     669           0 : }// encodeCortex_TelemetryControllerPacketStructure
     670             : 
     671             : /*!
     672             :  * \brief Decode the Cortex_TelemetryController packet
     673             :  *
     674             :  * Controller status information
     675             :  * \param _pg_pkt points to the packet being decoded by this function
     676             :  * \param _pg_user receives the data decoded from the packet
     677             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     678             :  */
     679           0 : int decodeCortex_TelemetryControllerPacketStructure(const void* _pg_pkt, Cortex_TelemetryController_t* _pg_user)
     680             : {
     681             :     int _pg_numbytes;
     682           0 :     int _pg_byteindex = 0;
     683             :     const uint8_t* _pg_data;
     684             : 
     685             :     // Verify the packet identifier
     686           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryControllerPacketID())
     687           0 :         return 0;
     688             : 
     689             :     // Verify the packet size
     690           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
     691           0 :     if(_pg_numbytes < getCortex_TelemetryControllerMinDataLength())
     692           0 :         return 0;
     693             : 
     694             :     // The raw data from the packet
     695           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
     696             : 
     697             :     // Generator rectifier temperature
     698             :     // Range of rectifierTemperature is -55.0f to 200.0f.
     699           0 :     _pg_user->rectifierTemperature = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -55.0f, 1.0f/1.0f);
     700             : 
     701             :     // Voltage regulator temperature
     702             :     // Range of regulatorTemperature is -55.0f to 200.0f.
     703           0 :     _pg_user->regulatorTemperature = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -55.0f, 1.0f/1.0f);
     704             : 
     705             :     // Generator run time
     706             :     // Range of runTime is 0 to 16777215.
     707           0 :     _pg_user->runTime = (uint32_t)uint24FromBeBytes(_pg_data, &_pg_byteindex);
     708             : 
     709           0 :     return 1;
     710             : 
     711             : }// decodeCortex_TelemetryControllerPacketStructure
     712             : 
     713             : /*!
     714             :  * \brief Create the Cortex_TelemetryController packet
     715             :  *
     716             :  * Controller status information
     717             :  * \param _pg_pkt points to the packet which will be created by this function
     718             :  * \param rectifierTemperature is Generator rectifier temperature
     719             :  * \param regulatorTemperature is Voltage regulator temperature
     720             :  * \param runTime is Generator run time
     721             :  */
     722           0 : void encodeCortex_TelemetryControllerPacket(void* _pg_pkt, float rectifierTemperature, float regulatorTemperature, uint32_t runTime)
     723             : {
     724           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     725           0 :     int _pg_byteindex = 0;
     726             : 
     727             :     // Generator rectifier temperature
     728             :     // Range of rectifierTemperature is -55.0f to 200.0f.
     729           0 :     float32ScaledTo1UnsignedBytes(rectifierTemperature, _pg_data, &_pg_byteindex, -55.0f, 1.0f);
     730             : 
     731             :     // Voltage regulator temperature
     732             :     // Range of regulatorTemperature is -55.0f to 200.0f.
     733           0 :     float32ScaledTo1UnsignedBytes(regulatorTemperature, _pg_data, &_pg_byteindex, -55.0f, 1.0f);
     734             : 
     735             :     // Generator run time
     736             :     // Range of runTime is 0 to 16777215.
     737           0 :     uint24ToBeBytes((uint32_t)(limitMax(runTime, 16777215)), _pg_data, &_pg_byteindex);
     738             : 
     739             :     // complete the process of creating the packet
     740           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryControllerPacketID());
     741             : 
     742           0 : }// encodeCortex_TelemetryControllerPacket
     743             : 
     744             : /*!
     745             :  * \brief Decode the Cortex_TelemetryController packet
     746             :  *
     747             :  * Controller status information
     748             :  * \param _pg_pkt points to the packet being decoded by this function
     749             :  * \param rectifierTemperature receives Generator rectifier temperature
     750             :  * \param regulatorTemperature receives Voltage regulator temperature
     751             :  * \param runTime receives Generator run time
     752             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     753             :  */
     754           0 : int decodeCortex_TelemetryControllerPacket(const void* _pg_pkt, float* rectifierTemperature, float* regulatorTemperature, uint32_t* runTime)
     755             : {
     756           0 :     int _pg_byteindex = 0;
     757           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
     758           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
     759             : 
     760             :     // Verify the packet identifier
     761           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryControllerPacketID())
     762           0 :         return 0;
     763             : 
     764           0 :     if(_pg_numbytes < getCortex_TelemetryControllerMinDataLength())
     765           0 :         return 0;
     766             : 
     767             :     // Generator rectifier temperature
     768             :     // Range of rectifierTemperature is -55.0f to 200.0f.
     769           0 :     (*rectifierTemperature) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -55.0f, 1.0f/1.0f);
     770             : 
     771             :     // Voltage regulator temperature
     772             :     // Range of regulatorTemperature is -55.0f to 200.0f.
     773           0 :     (*regulatorTemperature) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, -55.0f, 1.0f/1.0f);
     774             : 
     775             :     // Generator run time
     776             :     // Range of runTime is 0 to 16777215.
     777           0 :     (*runTime) = (uint32_t)uint24FromBeBytes(_pg_data, &_pg_byteindex);
     778             : 
     779           0 :     return 1;
     780             : 
     781             : }// decodeCortex_TelemetryControllerPacket
     782             : 
     783             : /*!
     784             :  * \brief Create the Cortex_TelemetryEngine packet
     785             :  *
     786             :  * Engine control status information. Note that this packet is only available
     787             :  * for Cortex devices which support external engine control.
     788             :  * \param _pg_pkt points to the packet which will be created by this function
     789             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     790             :  */
     791           0 : void encodeCortex_TelemetryEnginePacketStructure(void* _pg_pkt, const Cortex_TelemetryEngine_t* _pg_user)
     792             : {
     793           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     794           0 :     int _pg_byteindex = 0;
     795             : 
     796             :     // Throttle voltage target
     797             :     // Range of voltageTarget is 0.0f to 655.35f.
     798           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->voltageTarget, _pg_data, &_pg_byteindex, 0.0f, 100.0f);
     799             : 
     800             :     // Current throttle target
     801             :     // Range of throttleTarget is 0.0f to 100.0f.
     802           0 :     float32ScaledTo1UnsignedBytes(_pg_user->throttleTarget, _pg_data, &_pg_byteindex, 0.0f, 2.55f);
     803             : 
     804             :     // Engine power demand
     805             :     // Range of powerTarget is -32767.0f to 32767.0f.
     806           0 :     float32ScaledTo2SignedBeBytes(_pg_user->powerTarget, _pg_data, &_pg_byteindex, 1.0f);
     807             : 
     808             :     // complete the process of creating the packet
     809           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryEnginePacketID());
     810             : 
     811           0 : }// encodeCortex_TelemetryEnginePacketStructure
     812             : 
     813             : /*!
     814             :  * \brief Decode the Cortex_TelemetryEngine packet
     815             :  *
     816             :  * Engine control status information. Note that this packet is only available
     817             :  * for Cortex devices which support external engine control.
     818             :  * \param _pg_pkt points to the packet being decoded by this function
     819             :  * \param _pg_user receives the data decoded from the packet
     820             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     821             :  */
     822           0 : int decodeCortex_TelemetryEnginePacketStructure(const void* _pg_pkt, Cortex_TelemetryEngine_t* _pg_user)
     823             : {
     824             :     int _pg_numbytes;
     825           0 :     int _pg_byteindex = 0;
     826             :     const uint8_t* _pg_data;
     827             : 
     828             :     // Verify the packet identifier
     829           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryEnginePacketID())
     830           0 :         return 0;
     831             : 
     832             :     // Verify the packet size
     833           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
     834           0 :     if(_pg_numbytes < getCortex_TelemetryEngineMinDataLength())
     835           0 :         return 0;
     836             : 
     837             :     // The raw data from the packet
     838           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
     839             : 
     840             :     // Throttle voltage target
     841             :     // Range of voltageTarget is 0.0f to 655.35f.
     842           0 :     _pg_user->voltageTarget = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/100.0f);
     843             : 
     844             :     // Current throttle target
     845             :     // Range of throttleTarget is 0.0f to 100.0f.
     846           0 :     _pg_user->throttleTarget = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/2.55f);
     847             : 
     848             :     // Engine power demand
     849             :     // Range of powerTarget is -32767.0f to 32767.0f.
     850           0 :     _pg_user->powerTarget = float32ScaledFrom2SignedBeBytes(_pg_data, &_pg_byteindex, 1.0f/1.0f);
     851             : 
     852           0 :     return 1;
     853             : 
     854             : }// decodeCortex_TelemetryEnginePacketStructure
     855             : 
     856             : /*!
     857             :  * \brief Create the Cortex_TelemetryEngine packet
     858             :  *
     859             :  * Engine control status information. Note that this packet is only available
     860             :  * for Cortex devices which support external engine control.
     861             :  * \param _pg_pkt points to the packet which will be created by this function
     862             :  * \param voltageTarget is Throttle voltage target
     863             :  * \param throttleTarget is Current throttle target
     864             :  * \param powerTarget is Engine power demand
     865             :  */
     866           0 : void encodeCortex_TelemetryEnginePacket(void* _pg_pkt, float voltageTarget, float throttleTarget, float powerTarget)
     867             : {
     868           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     869           0 :     int _pg_byteindex = 0;
     870             : 
     871             :     // Throttle voltage target
     872             :     // Range of voltageTarget is 0.0f to 655.35f.
     873           0 :     float32ScaledTo2UnsignedBeBytes(voltageTarget, _pg_data, &_pg_byteindex, 0.0f, 100.0f);
     874             : 
     875             :     // Current throttle target
     876             :     // Range of throttleTarget is 0.0f to 100.0f.
     877           0 :     float32ScaledTo1UnsignedBytes(throttleTarget, _pg_data, &_pg_byteindex, 0.0f, 2.55f);
     878             : 
     879             :     // Engine power demand
     880             :     // Range of powerTarget is -32767.0f to 32767.0f.
     881           0 :     float32ScaledTo2SignedBeBytes(powerTarget, _pg_data, &_pg_byteindex, 1.0f);
     882             : 
     883             :     // complete the process of creating the packet
     884           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryEnginePacketID());
     885             : 
     886           0 : }// encodeCortex_TelemetryEnginePacket
     887             : 
     888             : /*!
     889             :  * \brief Decode the Cortex_TelemetryEngine packet
     890             :  *
     891             :  * Engine control status information. Note that this packet is only available
     892             :  * for Cortex devices which support external engine control.
     893             :  * \param _pg_pkt points to the packet being decoded by this function
     894             :  * \param voltageTarget receives Throttle voltage target
     895             :  * \param throttleTarget receives Current throttle target
     896             :  * \param powerTarget receives Engine power demand
     897             :  * \return 0 is returned if the packet ID or size is wrong, else 1
     898             :  */
     899           0 : int decodeCortex_TelemetryEnginePacket(const void* _pg_pkt, float* voltageTarget, float* throttleTarget, float* powerTarget)
     900             : {
     901           0 :     int _pg_byteindex = 0;
     902           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
     903           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
     904             : 
     905             :     // Verify the packet identifier
     906           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryEnginePacketID())
     907           0 :         return 0;
     908             : 
     909           0 :     if(_pg_numbytes < getCortex_TelemetryEngineMinDataLength())
     910           0 :         return 0;
     911             : 
     912             :     // Throttle voltage target
     913             :     // Range of voltageTarget is 0.0f to 655.35f.
     914           0 :     (*voltageTarget) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/100.0f);
     915             : 
     916             :     // Current throttle target
     917             :     // Range of throttleTarget is 0.0f to 100.0f.
     918           0 :     (*throttleTarget) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/2.55f);
     919             : 
     920             :     // Engine power demand
     921             :     // Range of powerTarget is -32767.0f to 32767.0f.
     922           0 :     (*powerTarget) = float32ScaledFrom2SignedBeBytes(_pg_data, &_pg_byteindex, 1.0f/1.0f);
     923             : 
     924           0 :     return 1;
     925             : 
     926             : }// decodeCortex_TelemetryEnginePacket
     927             : 
     928             : /*!
     929             :  * \brief Create the Cortex_TelemetryOutputRail packet
     930             :  *
     931             :  * Output rail status information
     932             :  * \param _pg_pkt points to the packet which will be created by this function
     933             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
     934             :  */
     935           0 : void encodeCortex_TelemetryOutputRailPacketStructure(void* _pg_pkt, const Cortex_TelemetryOutputRail_t* _pg_user)
     936             : {
     937           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
     938           0 :     int _pg_byteindex = 0;
     939           0 :     unsigned int _pg_tempbitfield = 0;
     940             : 
     941             :     // Avionics rail voltage
     942             :     // Range of avionicsVoltage is 0.0f to 102.3f.
     943           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)_pg_user->avionicsVoltage, 0.0f, 10.0f, 10);
     944           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)(_pg_tempbitfield << 6);
     945             : 
     946           0 :     _pg_tempbitfield >>= 2;
     947           0 :     _pg_data[_pg_byteindex] = (uint8_t)_pg_tempbitfield;
     948             : 
     949             : 
     950             :     // Avionics rail current
     951             :     // Range of avionicsCurrent is 0.0f to 20.46f.
     952           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)_pg_user->avionicsCurrent, 0.0f, 50.0f, 10);
     953           0 :     _pg_data[_pg_byteindex + 2] = (uint8_t)(_pg_tempbitfield << 4);
     954             : 
     955           0 :     _pg_tempbitfield >>= 4;
     956           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_tempbitfield;
     957             : 
     958             :     // Payload rail voltage
     959             :     // Range of payloadVoltage is 0.0f to 102.3f.
     960           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)_pg_user->payloadVoltage, 0.0f, 10.0f, 10);
     961           0 :     _pg_data[_pg_byteindex + 3] = (uint8_t)(_pg_tempbitfield << 2);
     962             : 
     963           0 :     _pg_tempbitfield >>= 6;
     964           0 :     _pg_data[_pg_byteindex + 2] |= (uint8_t)_pg_tempbitfield;
     965             : 
     966             :     // Payload rail current
     967             :     // Range of payloadCurrent is 0.0f to 20.46f.
     968           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)_pg_user->payloadCurrent, 0.0f, 50.0f, 10);
     969           0 :     _pg_data[_pg_byteindex + 4] = (uint8_t)_pg_tempbitfield;
     970             : 
     971           0 :     _pg_tempbitfield >>= 8;
     972           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)_pg_tempbitfield;
     973             : 
     974             :     // Servo rail voltage
     975             :     // Range of servoVoltage is 0.0f to 102.3f.
     976           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)_pg_user->servoVoltage, 0.0f, 10.0f, 10);
     977           0 :     _pg_data[_pg_byteindex + 6] = (uint8_t)(_pg_tempbitfield << 6);
     978             : 
     979           0 :     _pg_tempbitfield >>= 2;
     980           0 :     _pg_data[_pg_byteindex + 5] = (uint8_t)_pg_tempbitfield;
     981             : 
     982             : 
     983             :     // Servo rail current
     984             :     // Range of servoCurrent is 0.0f to 20.46f.
     985           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)_pg_user->servoCurrent, 0.0f, 50.0f, 10);
     986           0 :     _pg_data[_pg_byteindex + 7] = (uint8_t)(_pg_tempbitfield << 4);
     987             : 
     988           0 :     _pg_tempbitfield >>= 4;
     989           0 :     _pg_data[_pg_byteindex + 6] |= (uint8_t)_pg_tempbitfield;
     990             : 
     991             :     // Reserved for future use
     992           0 :     _pg_byteindex += 8; // close bit field
     993             : 
     994             :     // complete the process of creating the packet
     995           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryOutputRailPacketID());
     996             : 
     997           0 : }// encodeCortex_TelemetryOutputRailPacketStructure
     998             : 
     999             : /*!
    1000             :  * \brief Decode the Cortex_TelemetryOutputRail packet
    1001             :  *
    1002             :  * Output rail status information
    1003             :  * \param _pg_pkt points to the packet being decoded by this function
    1004             :  * \param _pg_user receives the data decoded from the packet
    1005             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1006             :  */
    1007           0 : int decodeCortex_TelemetryOutputRailPacketStructure(const void* _pg_pkt, Cortex_TelemetryOutputRail_t* _pg_user)
    1008             : {
    1009             :     int _pg_numbytes;
    1010           0 :     int _pg_byteindex = 0;
    1011             :     const uint8_t* _pg_data;
    1012           0 :     unsigned int _pg_tempbitfield = 0;
    1013             : 
    1014             :     // Verify the packet identifier
    1015           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryOutputRailPacketID())
    1016           0 :         return 0;
    1017             : 
    1018             :     // Verify the packet size
    1019           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1020           0 :     if(_pg_numbytes < getCortex_TelemetryOutputRailMinDataLength())
    1021           0 :         return 0;
    1022             : 
    1023             :     // The raw data from the packet
    1024           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    1025             : 
    1026             :     // Avionics rail voltage
    1027             :     // Range of avionicsVoltage is 0.0f to 102.3f.
    1028           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex] & 0xFF);
    1029             : 
    1030           0 :     _pg_tempbitfield <<= 2;
    1031           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 1] >> 6);
    1032             : 
    1033           0 :     _pg_user->avionicsVoltage = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/10.0f);
    1034             : 
    1035             :     // Avionics rail current
    1036             :     // Range of avionicsCurrent is 0.0f to 20.46f.
    1037           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 1] & 0x3F);
    1038             : 
    1039           0 :     _pg_tempbitfield <<= 4;
    1040           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 2] >> 4);
    1041             : 
    1042           0 :     _pg_user->avionicsCurrent = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/50.0f);
    1043             : 
    1044             :     // Payload rail voltage
    1045             :     // Range of payloadVoltage is 0.0f to 102.3f.
    1046           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 2] & 0xF);
    1047             : 
    1048           0 :     _pg_tempbitfield <<= 6;
    1049           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 3] >> 2);
    1050             : 
    1051           0 :     _pg_user->payloadVoltage = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/10.0f);
    1052             : 
    1053             :     // Payload rail current
    1054             :     // Range of payloadCurrent is 0.0f to 20.46f.
    1055           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 3] & 0x3);
    1056             : 
    1057           0 :     _pg_tempbitfield <<= 8;
    1058           0 :     _pg_tempbitfield |= _pg_data[_pg_byteindex + 4];
    1059             : 
    1060           0 :     _pg_user->payloadCurrent = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/50.0f);
    1061             : 
    1062             :     // Servo rail voltage
    1063             :     // Range of servoVoltage is 0.0f to 102.3f.
    1064           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 5] & 0xFF);
    1065             : 
    1066           0 :     _pg_tempbitfield <<= 2;
    1067           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 6] >> 6);
    1068             : 
    1069           0 :     _pg_user->servoVoltage = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/10.0f);
    1070             : 
    1071             :     // Servo rail current
    1072             :     // Range of servoCurrent is 0.0f to 20.46f.
    1073           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 6] & 0x3F);
    1074             : 
    1075           0 :     _pg_tempbitfield <<= 4;
    1076           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 7] >> 4);
    1077             : 
    1078           0 :     _pg_user->servoCurrent = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/50.0f);
    1079             : 
    1080             :     // Reserved for future use
    1081           0 :     _pg_byteindex += 8; // close bit field
    1082             : 
    1083           0 :     return 1;
    1084             : 
    1085             : }// decodeCortex_TelemetryOutputRailPacketStructure
    1086             : 
    1087             : /*!
    1088             :  * \brief Create the Cortex_TelemetryOutputRail packet
    1089             :  *
    1090             :  * Output rail status information
    1091             :  * \param _pg_pkt points to the packet which will be created by this function
    1092             :  * \param avionicsVoltage is Avionics rail voltage
    1093             :  * \param avionicsCurrent is Avionics rail current
    1094             :  * \param payloadVoltage is Payload rail voltage
    1095             :  * \param payloadCurrent is Payload rail current
    1096             :  * \param servoVoltage is Servo rail voltage
    1097             :  * \param servoCurrent is Servo rail current
    1098             :  */
    1099           0 : void encodeCortex_TelemetryOutputRailPacket(void* _pg_pkt, float avionicsVoltage, float avionicsCurrent, float payloadVoltage, float payloadCurrent, float servoVoltage, float servoCurrent)
    1100             : {
    1101           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1102           0 :     int _pg_byteindex = 0;
    1103           0 :     unsigned int _pg_tempbitfield = 0;
    1104             : 
    1105             :     // Avionics rail voltage
    1106             :     // Range of avionicsVoltage is 0.0f to 102.3f.
    1107           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)avionicsVoltage, 0.0f, 10.0f, 10);
    1108           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)(_pg_tempbitfield << 6);
    1109             : 
    1110           0 :     _pg_tempbitfield >>= 2;
    1111           0 :     _pg_data[_pg_byteindex] = (uint8_t)_pg_tempbitfield;
    1112             : 
    1113             :     // Avionics rail current
    1114             :     // Range of avionicsCurrent is 0.0f to 20.46f.
    1115           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)avionicsCurrent, 0.0f, 50.0f, 10);
    1116           0 :     _pg_data[_pg_byteindex + 2] = (uint8_t)(_pg_tempbitfield << 4);
    1117             : 
    1118           0 :     _pg_tempbitfield >>= 4;
    1119           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)_pg_tempbitfield;
    1120             : 
    1121             :     // Payload rail voltage
    1122             :     // Range of payloadVoltage is 0.0f to 102.3f.
    1123           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)payloadVoltage, 0.0f, 10.0f, 10);
    1124           0 :     _pg_data[_pg_byteindex + 3] = (uint8_t)(_pg_tempbitfield << 2);
    1125             : 
    1126           0 :     _pg_tempbitfield >>= 6;
    1127           0 :     _pg_data[_pg_byteindex + 2] |= (uint8_t)_pg_tempbitfield;
    1128             : 
    1129             :     // Payload rail current
    1130             :     // Range of payloadCurrent is 0.0f to 20.46f.
    1131           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)payloadCurrent, 0.0f, 50.0f, 10);
    1132           0 :     _pg_data[_pg_byteindex + 4] = (uint8_t)_pg_tempbitfield;
    1133             : 
    1134           0 :     _pg_tempbitfield >>= 8;
    1135           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)_pg_tempbitfield;
    1136             : 
    1137             :     // Servo rail voltage
    1138             :     // Range of servoVoltage is 0.0f to 102.3f.
    1139           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)servoVoltage, 0.0f, 10.0f, 10);
    1140           0 :     _pg_data[_pg_byteindex + 6] = (uint8_t)(_pg_tempbitfield << 6);
    1141             : 
    1142           0 :     _pg_tempbitfield >>= 2;
    1143           0 :     _pg_data[_pg_byteindex + 5] = (uint8_t)_pg_tempbitfield;
    1144             : 
    1145             :     // Servo rail current
    1146             :     // Range of servoCurrent is 0.0f to 20.46f.
    1147           0 :     _pg_tempbitfield = (unsigned int)float32ScaledToBitfield((float)servoCurrent, 0.0f, 50.0f, 10);
    1148           0 :     _pg_data[_pg_byteindex + 7] = (uint8_t)(_pg_tempbitfield << 4);
    1149             : 
    1150           0 :     _pg_tempbitfield >>= 4;
    1151           0 :     _pg_data[_pg_byteindex + 6] |= (uint8_t)_pg_tempbitfield;
    1152             : 
    1153             :     // Reserved for future use
    1154           0 :     _pg_byteindex += 8; // close bit field
    1155             : 
    1156             :     // complete the process of creating the packet
    1157           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetryOutputRailPacketID());
    1158             : 
    1159           0 : }// encodeCortex_TelemetryOutputRailPacket
    1160             : 
    1161             : /*!
    1162             :  * \brief Decode the Cortex_TelemetryOutputRail packet
    1163             :  *
    1164             :  * Output rail status information
    1165             :  * \param _pg_pkt points to the packet being decoded by this function
    1166             :  * \param avionicsVoltage receives Avionics rail voltage
    1167             :  * \param avionicsCurrent receives Avionics rail current
    1168             :  * \param payloadVoltage receives Payload rail voltage
    1169             :  * \param payloadCurrent receives Payload rail current
    1170             :  * \param servoVoltage receives Servo rail voltage
    1171             :  * \param servoCurrent receives Servo rail current
    1172             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1173             :  */
    1174           0 : int decodeCortex_TelemetryOutputRailPacket(const void* _pg_pkt, float* avionicsVoltage, float* avionicsCurrent, float* payloadVoltage, float* payloadCurrent, float* servoVoltage, float* servoCurrent)
    1175             : {
    1176           0 :     unsigned int _pg_tempbitfield = 0;
    1177           0 :     int _pg_byteindex = 0;
    1178           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
    1179           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1180             : 
    1181             :     // Verify the packet identifier
    1182           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetryOutputRailPacketID())
    1183           0 :         return 0;
    1184             : 
    1185           0 :     if(_pg_numbytes < getCortex_TelemetryOutputRailMinDataLength())
    1186           0 :         return 0;
    1187             : 
    1188             :     // Avionics rail voltage
    1189             :     // Range of avionicsVoltage is 0.0f to 102.3f.
    1190           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex] & 0xFF);
    1191             : 
    1192           0 :     _pg_tempbitfield <<= 2;
    1193           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 1] >> 6);
    1194             : 
    1195           0 :     (*avionicsVoltage) = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/10.0f);
    1196             : 
    1197             :     // Avionics rail current
    1198             :     // Range of avionicsCurrent is 0.0f to 20.46f.
    1199           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 1] & 0x3F);
    1200             : 
    1201           0 :     _pg_tempbitfield <<= 4;
    1202           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 2] >> 4);
    1203             : 
    1204           0 :     (*avionicsCurrent) = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/50.0f);
    1205             : 
    1206             :     // Payload rail voltage
    1207             :     // Range of payloadVoltage is 0.0f to 102.3f.
    1208           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 2] & 0xF);
    1209             : 
    1210           0 :     _pg_tempbitfield <<= 6;
    1211           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 3] >> 2);
    1212             : 
    1213           0 :     (*payloadVoltage) = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/10.0f);
    1214             : 
    1215             :     // Payload rail current
    1216             :     // Range of payloadCurrent is 0.0f to 20.46f.
    1217           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 3] & 0x3);
    1218             : 
    1219           0 :     _pg_tempbitfield <<= 8;
    1220           0 :     _pg_tempbitfield |= _pg_data[_pg_byteindex + 4];
    1221             : 
    1222           0 :     (*payloadCurrent) = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/50.0f);
    1223             : 
    1224             :     // Servo rail voltage
    1225             :     // Range of servoVoltage is 0.0f to 102.3f.
    1226           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 5] & 0xFF);
    1227             : 
    1228           0 :     _pg_tempbitfield <<= 2;
    1229           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 6] >> 6);
    1230             : 
    1231           0 :     (*servoVoltage) = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/10.0f);
    1232             : 
    1233             :     // Servo rail current
    1234             :     // Range of servoCurrent is 0.0f to 20.46f.
    1235           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex + 6] & 0x3F);
    1236             : 
    1237           0 :     _pg_tempbitfield <<= 4;
    1238           0 :     _pg_tempbitfield |= (_pg_data[_pg_byteindex + 7] >> 4);
    1239             : 
    1240           0 :     (*servoCurrent) = float32ScaledFromBitfield(_pg_tempbitfield, 0.0f, 1.0f/50.0f);
    1241             : 
    1242             :     // Reserved for future use
    1243           0 :     _pg_byteindex += 8; // close bit field
    1244             : 
    1245           0 :     return 1;
    1246             : 
    1247             : }// decodeCortex_TelemetryOutputRailPacket
    1248             : 
    1249             : /*!
    1250             :  * \brief Create the Cortex_TelemetrySettings packet
    1251             :  *
    1252             :  * Telemetry settings
    1253             :  * \param _pg_pkt points to the packet which will be created by this function
    1254             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1255             :  */
    1256           0 : void encodeCortex_TelemetrySettingsPacketStructure(void* _pg_pkt, const Cortex_TelemetrySettings_t* _pg_user)
    1257             : {
    1258           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1259           0 :     int _pg_byteindex = 0;
    1260             : 
    1261             :     // Telemetry packet selection
    1262           0 :     encodeCortex_TelemetryPackets_t(_pg_data, &_pg_byteindex, &_pg_user->packets);
    1263             : 
    1264             :     // complete the process of creating the packet
    1265           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_TelemetrySettingsPacketID());
    1266             : 
    1267           0 : }// encodeCortex_TelemetrySettingsPacketStructure
    1268             : 
    1269             : /*!
    1270             :  * \brief Decode the Cortex_TelemetrySettings packet
    1271             :  *
    1272             :  * Telemetry settings
    1273             :  * \param _pg_pkt points to the packet being decoded by this function
    1274             :  * \param _pg_user receives the data decoded from the packet
    1275             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1276             :  */
    1277           0 : int decodeCortex_TelemetrySettingsPacketStructure(const void* _pg_pkt, Cortex_TelemetrySettings_t* _pg_user)
    1278             : {
    1279             :     int _pg_numbytes;
    1280           0 :     int _pg_byteindex = 0;
    1281             :     const uint8_t* _pg_data;
    1282             : 
    1283             :     // Verify the packet identifier
    1284           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_TelemetrySettingsPacketID())
    1285           0 :         return 0;
    1286             : 
    1287             :     // Verify the packet size
    1288           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1289           0 :     if(_pg_numbytes < getCortex_TelemetrySettingsMinDataLength())
    1290           0 :         return 0;
    1291             : 
    1292             :     // The raw data from the packet
    1293           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    1294             : 
    1295             :     // Telemetry packet selection
    1296           0 :     if(decodeCortex_TelemetryPackets_t(_pg_data, &_pg_byteindex, &_pg_user->packets) == 0)
    1297           0 :         return 0;
    1298             : 
    1299           0 :     return 1;
    1300             : 
    1301             : }// decodeCortex_TelemetrySettingsPacketStructure
    1302             : 
    1303             : /*!
    1304             :  * \brief Create the Cortex_GeneratorSettings packet
    1305             :  *
    1306             :  * Generator settings
    1307             :  * \param _pg_pkt points to the packet which will be created by this function
    1308             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1309             :  */
    1310           0 : void encodeCortex_GeneratorSettingsPacketStructure(void* _pg_pkt, const Cortex_GeneratorSettings_t* _pg_user)
    1311             : {
    1312           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1313           0 :     int _pg_byteindex = 0;
    1314             : 
    1315             :     // Timeout for power loss detection
    1316             :     // Range of powerLossTimeout is 0 to 255.
    1317           0 :     uint8ToBytes(_pg_user->powerLossTimeout, _pg_data, &_pg_byteindex);
    1318             : 
    1319             :     // Minimum engine speed for running.
    1320             :     // Range of minRunningRpm is 0 to 65535.
    1321           0 :     uint16ToBeBytes(_pg_user->minRunningRpm, _pg_data, &_pg_byteindex);
    1322             : 
    1323             :     // Generator drive belt ratio
    1324             :     // Range of beltRatio is 0.0f to 65.535f.
    1325           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->beltRatio, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1326             : 
    1327             :     // complete the process of creating the packet
    1328           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_GeneratorSettingsPacketID());
    1329             : 
    1330           0 : }// encodeCortex_GeneratorSettingsPacketStructure
    1331             : 
    1332             : /*!
    1333             :  * \brief Decode the Cortex_GeneratorSettings packet
    1334             :  *
    1335             :  * Generator settings
    1336             :  * \param _pg_pkt points to the packet being decoded by this function
    1337             :  * \param _pg_user receives the data decoded from the packet
    1338             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1339             :  */
    1340           0 : int decodeCortex_GeneratorSettingsPacketStructure(const void* _pg_pkt, Cortex_GeneratorSettings_t* _pg_user)
    1341             : {
    1342             :     int _pg_numbytes;
    1343           0 :     int _pg_byteindex = 0;
    1344             :     const uint8_t* _pg_data;
    1345             : 
    1346             :     // Verify the packet identifier
    1347           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_GeneratorSettingsPacketID())
    1348           0 :         return 0;
    1349             : 
    1350             :     // Verify the packet size
    1351           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1352           0 :     if(_pg_numbytes < getCortex_GeneratorSettingsMinDataLength())
    1353           0 :         return 0;
    1354             : 
    1355             :     // The raw data from the packet
    1356           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    1357             : 
    1358             :     // Timeout for power loss detection
    1359             :     // Range of powerLossTimeout is 0 to 255.
    1360           0 :     _pg_user->powerLossTimeout = uint8FromBytes(_pg_data, &_pg_byteindex);
    1361             : 
    1362             :     // Minimum engine speed for running.
    1363             :     // Range of minRunningRpm is 0 to 65535.
    1364           0 :     _pg_user->minRunningRpm = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1365             : 
    1366             :     // Generator drive belt ratio
    1367             :     // Range of beltRatio is 0.0f to 65.535f.
    1368           0 :     _pg_user->beltRatio = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1369             : 
    1370           0 :     return 1;
    1371             : 
    1372             : }// decodeCortex_GeneratorSettingsPacketStructure
    1373             : 
    1374             : /*!
    1375             :  * \brief Create the Cortex_StartingSettings packet
    1376             :  *
    1377             :  * System starting settings
    1378             :  * \param _pg_pkt points to the packet which will be created by this function
    1379             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1380             :  */
    1381           0 : void encodeCortex_StartingSettingsPacketStructure(void* _pg_pkt, const Cortex_StartingSettings_t* _pg_user)
    1382             : {
    1383           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1384           0 :     int _pg_byteindex = 0;
    1385             : 
    1386             :     // Engine pre-compression duration
    1387             :     // Range of compressionTime is 0 to 255.
    1388           0 :     uint8ToBytes(_pg_user->compressionTime, _pg_data, &_pg_byteindex);
    1389             : 
    1390             :     // Motor pre-compression duty cycle
    1391             :     // Range of compressionDuty is 0 to 255.
    1392           0 :     uint8ToBytes(_pg_user->compressionDuty, _pg_data, &_pg_byteindex);
    1393             : 
    1394             :     // Set this bit to disable manual engine cranking
    1395           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->disableManualCranking == true) ? 1 : 0) << 7;
    1396             : 
    1397             :     // Reserved bits
    1398           0 :     _pg_byteindex += 1; // close bit field
    1399             : 
    1400             :     // complete the process of creating the packet
    1401           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_StartingSettingsPacketID());
    1402             : 
    1403           0 : }// encodeCortex_StartingSettingsPacketStructure
    1404             : 
    1405             : /*!
    1406             :  * \brief Decode the Cortex_StartingSettings packet
    1407             :  *
    1408             :  * System starting settings
    1409             :  * \param _pg_pkt points to the packet being decoded by this function
    1410             :  * \param _pg_user receives the data decoded from the packet
    1411             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1412             :  */
    1413           0 : int decodeCortex_StartingSettingsPacketStructure(const void* _pg_pkt, Cortex_StartingSettings_t* _pg_user)
    1414             : {
    1415             :     int _pg_numbytes;
    1416           0 :     int _pg_byteindex = 0;
    1417             :     const uint8_t* _pg_data;
    1418             : 
    1419             :     // Verify the packet identifier
    1420           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_StartingSettingsPacketID())
    1421           0 :         return 0;
    1422             : 
    1423             :     // Verify the packet size
    1424           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1425           0 :     if(_pg_numbytes < getCortex_StartingSettingsMinDataLength())
    1426           0 :         return 0;
    1427             : 
    1428             :     // The raw data from the packet
    1429           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    1430             : 
    1431             :     // this packet has default fields, make sure they are set
    1432           0 :     _pg_user->disableManualCranking = 0;
    1433           0 :     _pg_user->reservedBits = 0;
    1434             : 
    1435             :     // Engine pre-compression duration
    1436             :     // Range of compressionTime is 0 to 255.
    1437           0 :     _pg_user->compressionTime = uint8FromBytes(_pg_data, &_pg_byteindex);
    1438             : 
    1439             :     // Motor pre-compression duty cycle
    1440             :     // Range of compressionDuty is 0 to 255.
    1441           0 :     _pg_user->compressionDuty = uint8FromBytes(_pg_data, &_pg_byteindex);
    1442             : 
    1443           0 :     if(_pg_byteindex + 1 > _pg_numbytes)
    1444           0 :         return 1;
    1445             : 
    1446             :     // Set this bit to disable manual engine cranking
    1447           0 :     _pg_user->disableManualCranking = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
    1448             : 
    1449             :     // Reserved bits
    1450             :     // Range of reservedBits is 0 to 127.
    1451           0 :     _pg_user->reservedBits = ((_pg_data[_pg_byteindex]) & 0x7F);
    1452           0 :     _pg_byteindex += 1; // close bit field
    1453             : 
    1454           0 :     return 1;
    1455             : 
    1456             : }// decodeCortex_StartingSettingsPacketStructure
    1457             : 
    1458             : /*!
    1459             :  * \brief Create the Cortex_PowerLimitSettings packet
    1460             :  *
    1461             :  * System power limit settings
    1462             :  * \param _pg_pkt points to the packet which will be created by this function
    1463             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1464             :  */
    1465           0 : void encodeCortex_PowerLimitSettingsPacketStructure(void* _pg_pkt, const Cortex_PowerLimitSettings_t* _pg_user)
    1466             : {
    1467           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1468           0 :     int _pg_byteindex = 0;
    1469             : 
    1470             :     // Enable over-temperature power limit
    1471           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->enableTempLimit == true) ? 1 : 0) << 7;
    1472             : 
    1473             :     // Enable motor current power limit
    1474           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->enableCurrentLimit == true) ? 1 : 0) << 6;
    1475             : 
    1476             :     // Enable power map power limit
    1477           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->enablePowerLimit == true) ? 1 : 0) << 5;
    1478             : 
    1479             :     // Enable battery charging current limit
    1480           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->enableBatteryLimit == true) ? 1 : 0) << 4;
    1481             : 
    1482             :     // Reserved bits
    1483           0 :     _pg_byteindex += 1; // close bit field
    1484             : 
    1485             : 
    1486             :     // Generator winding current limit
    1487             :     // Range of generatorCurrentLimit is 0.0f to 655.35f.
    1488           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->generatorCurrentLimit, _pg_data, &_pg_byteindex, 0.0f, 100.0f);
    1489             : 
    1490             :     // Generator temperature limit value
    1491             :     // Range of generatorTempLimit is 0 to 255.
    1492           0 :     uint8ToBytes(_pg_user->generatorTempLimit, _pg_data, &_pg_byteindex);
    1493             : 
    1494             :     // Power limit filter frequency
    1495             :     // Range of filter is 0.0f to 10.0f.
    1496           0 :     float32ScaledTo1UnsignedBytes(_pg_user->filter, _pg_data, &_pg_byteindex, 0.0f, 25.5f);
    1497             : 
    1498             :     // Power limit controller proportional gain
    1499             :     // Range of Kp is 0.0f to 100.0f.
    1500           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Kp, _pg_data, &_pg_byteindex, 0.0f, 655.35f);
    1501             : 
    1502             :     // Power limit controller integral gain
    1503             :     // Range of Ki is 0.0f to 100.0f.
    1504           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Ki, _pg_data, &_pg_byteindex, 0.0f, 655.35f);
    1505             : 
    1506             :     // complete the process of creating the packet
    1507           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_PowerLimitSettingsPacketID());
    1508             : 
    1509           0 : }// encodeCortex_PowerLimitSettingsPacketStructure
    1510             : 
    1511             : /*!
    1512             :  * \brief Decode the Cortex_PowerLimitSettings packet
    1513             :  *
    1514             :  * System power limit settings
    1515             :  * \param _pg_pkt points to the packet being decoded by this function
    1516             :  * \param _pg_user receives the data decoded from the packet
    1517             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1518             :  */
    1519           0 : int decodeCortex_PowerLimitSettingsPacketStructure(const void* _pg_pkt, Cortex_PowerLimitSettings_t* _pg_user)
    1520             : {
    1521             :     int _pg_numbytes;
    1522           0 :     int _pg_byteindex = 0;
    1523             :     const uint8_t* _pg_data;
    1524             : 
    1525             :     // Verify the packet identifier
    1526           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_PowerLimitSettingsPacketID())
    1527           0 :         return 0;
    1528             : 
    1529             :     // Verify the packet size
    1530           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1531           0 :     if(_pg_numbytes < getCortex_PowerLimitSettingsMinDataLength())
    1532           0 :         return 0;
    1533             : 
    1534             :     // The raw data from the packet
    1535           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    1536             : 
    1537             :     // Enable over-temperature power limit
    1538           0 :     _pg_user->enableTempLimit = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
    1539             : 
    1540             :     // Enable motor current power limit
    1541           0 :     _pg_user->enableCurrentLimit = (((_pg_data[_pg_byteindex] >> 6) & 0x1)) ? true : false;
    1542             : 
    1543             :     // Enable power map power limit
    1544           0 :     _pg_user->enablePowerLimit = (((_pg_data[_pg_byteindex] >> 5) & 0x1)) ? true : false;
    1545             : 
    1546             :     // Enable battery charging current limit
    1547           0 :     _pg_user->enableBatteryLimit = (((_pg_data[_pg_byteindex] >> 4) & 0x1)) ? true : false;
    1548             : 
    1549             :     // Reserved bits
    1550           0 :     _pg_byteindex += 1; // close bit field
    1551             : 
    1552             :     // Generator winding current limit
    1553             :     // Range of generatorCurrentLimit is 0.0f to 655.35f.
    1554           0 :     _pg_user->generatorCurrentLimit = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/100.0f);
    1555             : 
    1556             :     // Generator temperature limit value
    1557             :     // Range of generatorTempLimit is 0 to 255.
    1558           0 :     _pg_user->generatorTempLimit = uint8FromBytes(_pg_data, &_pg_byteindex);
    1559             : 
    1560             :     // Power limit filter frequency
    1561             :     // Range of filter is 0.0f to 10.0f.
    1562           0 :     _pg_user->filter = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/25.5f);
    1563             : 
    1564             :     // Power limit controller proportional gain
    1565             :     // Range of Kp is 0.0f to 100.0f.
    1566           0 :     _pg_user->Kp = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/655.35f);
    1567             : 
    1568             :     // Power limit controller integral gain
    1569             :     // Range of Ki is 0.0f to 100.0f.
    1570           0 :     _pg_user->Ki = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/655.35f);
    1571             : 
    1572           0 :     return 1;
    1573             : 
    1574             : }// decodeCortex_PowerLimitSettingsPacketStructure
    1575             : 
    1576             : /*!
    1577             :  * \brief Create the Cortex_PowerMap packet
    1578             :  *
    1579             :  * Engine power map settings
    1580             :  * \param _pg_pkt points to the packet which will be created by this function
    1581             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1582             :  */
    1583           0 : void encodeCortex_PowerMapPacketStructure(void* _pg_pkt, const Cortex_PowerMap_t* _pg_user)
    1584             : {
    1585           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1586           0 :     int _pg_byteindex = 0;
    1587           0 :     unsigned _pg_i = 0;
    1588             : 
    1589             :     // Engine RPM values for power map.
    1590             :     // Range of rpm is 0.0f to 25500.0f.
    1591           0 :     for(_pg_i = 0; _pg_i < 5; _pg_i++)
    1592           0 :         float32ScaledTo1UnsignedBytes(_pg_user->rpm[_pg_i], _pg_data, &_pg_byteindex, 0.0f, 0.01f);
    1593             : 
    1594             :     // Engine power values for power map
    1595             :     // Range of power is 0.0f to 2550.0f.
    1596           0 :     for(_pg_i = 0; _pg_i < 5; _pg_i++)
    1597           0 :         float32ScaledTo1UnsignedBytes(_pg_user->power[_pg_i], _pg_data, &_pg_byteindex, 0.0f, 0.1f);
    1598             : 
    1599             :     // complete the process of creating the packet
    1600           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_PowerMapPacketID());
    1601             : 
    1602           0 : }// encodeCortex_PowerMapPacketStructure
    1603             : 
    1604             : /*!
    1605             :  * \brief Decode the Cortex_PowerMap packet
    1606             :  *
    1607             :  * Engine power map settings
    1608             :  * \param _pg_pkt points to the packet being decoded by this function
    1609             :  * \param _pg_user receives the data decoded from the packet
    1610             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1611             :  */
    1612           0 : int decodeCortex_PowerMapPacketStructure(const void* _pg_pkt, Cortex_PowerMap_t* _pg_user)
    1613             : {
    1614             :     int _pg_numbytes;
    1615           0 :     int _pg_byteindex = 0;
    1616             :     const uint8_t* _pg_data;
    1617           0 :     unsigned _pg_i = 0;
    1618             : 
    1619             :     // Verify the packet identifier
    1620           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_PowerMapPacketID())
    1621           0 :         return 0;
    1622             : 
    1623             :     // Verify the packet size
    1624           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1625           0 :     if(_pg_numbytes < getCortex_PowerMapMinDataLength())
    1626           0 :         return 0;
    1627             : 
    1628             :     // The raw data from the packet
    1629           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    1630             : 
    1631             :     // Engine RPM values for power map.
    1632             :     // Range of rpm is 0.0f to 25500.0f.
    1633           0 :     for(_pg_i = 0; _pg_i < 5; _pg_i++)
    1634           0 :         _pg_user->rpm[_pg_i] = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/0.01f);
    1635             : 
    1636             :     // Engine power values for power map
    1637             :     // Range of power is 0.0f to 2550.0f.
    1638           0 :     for(_pg_i = 0; _pg_i < 5; _pg_i++)
    1639           0 :         _pg_user->power[_pg_i] = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/0.1f);
    1640             : 
    1641           0 :     return 1;
    1642             : 
    1643             : }// decodeCortex_PowerMapPacketStructure
    1644             : 
    1645             : /*!
    1646             :  * \brief Create the Cortex_EngineControlSettings packet
    1647             :  *
    1648             :  * Engine control settings. This packet only has effect when Cortex device
    1649             :  * regulates engine RPM.
    1650             :  * \param _pg_pkt points to the packet which will be created by this function
    1651             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1652             :  */
    1653           0 : void encodeCortex_EngineControlSettingsPacketStructure(void* _pg_pkt, const Cortex_EngineControlSettings_t* _pg_user)
    1654             : {
    1655           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1656           0 :     int _pg_byteindex = 0;
    1657             : 
    1658             :     // Engine ID / address
    1659             :     // Range of address is 0 to 255.
    1660           0 :     uint8ToBytes(_pg_user->address, _pg_data, &_pg_byteindex);
    1661             : 
    1662             :     // Engine speed input filter
    1663             :     // Range of rpmFilter is 0.0f to 10.0f.
    1664           0 :     float32ScaledTo1UnsignedBytes(_pg_user->rpmFilter, _pg_data, &_pg_byteindex, 0.0f, 25.5f);
    1665             : 
    1666             :     // Maximum engine speed limit
    1667             :     // Range of rpmLimit is 0 to 65535.
    1668           0 :     uint16ToBeBytes(_pg_user->rpmLimit, _pg_data, &_pg_byteindex);
    1669             : 
    1670             :     // Engine RPM setpoint controller proportional gain
    1671             :     // Range of Kp is 0.0f to 65.535f.
    1672           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Kp, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1673             : 
    1674             :     // Engine RPM setpoint controller integral gain
    1675             :     // Range of Ki is 0.0f to 65.535f.
    1676           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Ki, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1677             : 
    1678             :     // Engine RPM setpoint controller derivative gain
    1679             :     // Range of Kd is 0.0f to 65.535f.
    1680           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Kd, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1681             : 
    1682             :     // Engine RPM setpoint controller feedforward gain
    1683             :     // Range of Kf is 0.0f to 65.535f.
    1684           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Kf, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1685             : 
    1686             :     // complete the process of creating the packet
    1687           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_EngineControlSettingsPacketID());
    1688             : 
    1689           0 : }// encodeCortex_EngineControlSettingsPacketStructure
    1690             : 
    1691             : /*!
    1692             :  * \brief Decode the Cortex_EngineControlSettings packet
    1693             :  *
    1694             :  * Engine control settings. This packet only has effect when Cortex device
    1695             :  * regulates engine RPM.
    1696             :  * \param _pg_pkt points to the packet being decoded by this function
    1697             :  * \param _pg_user receives the data decoded from the packet
    1698             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1699             :  */
    1700           0 : int decodeCortex_EngineControlSettingsPacketStructure(const void* _pg_pkt, Cortex_EngineControlSettings_t* _pg_user)
    1701             : {
    1702             :     int _pg_numbytes;
    1703           0 :     int _pg_byteindex = 0;
    1704             :     const uint8_t* _pg_data;
    1705             : 
    1706             :     // Verify the packet identifier
    1707           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_EngineControlSettingsPacketID())
    1708           0 :         return 0;
    1709             : 
    1710             :     // Verify the packet size
    1711           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1712           0 :     if(_pg_numbytes < getCortex_EngineControlSettingsMinDataLength())
    1713           0 :         return 0;
    1714             : 
    1715             :     // The raw data from the packet
    1716           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    1717             : 
    1718             :     // Engine ID / address
    1719             :     // Range of address is 0 to 255.
    1720           0 :     _pg_user->address = uint8FromBytes(_pg_data, &_pg_byteindex);
    1721             : 
    1722             :     // Engine speed input filter
    1723             :     // Range of rpmFilter is 0.0f to 10.0f.
    1724           0 :     _pg_user->rpmFilter = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/25.5f);
    1725             : 
    1726             :     // Maximum engine speed limit
    1727             :     // Range of rpmLimit is 0 to 65535.
    1728           0 :     _pg_user->rpmLimit = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1729             : 
    1730             :     // Engine RPM setpoint controller proportional gain
    1731             :     // Range of Kp is 0.0f to 65.535f.
    1732           0 :     _pg_user->Kp = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1733             : 
    1734             :     // Engine RPM setpoint controller integral gain
    1735             :     // Range of Ki is 0.0f to 65.535f.
    1736           0 :     _pg_user->Ki = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1737             : 
    1738             :     // Engine RPM setpoint controller derivative gain
    1739             :     // Range of Kd is 0.0f to 65.535f.
    1740           0 :     _pg_user->Kd = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1741             : 
    1742             :     // Engine RPM setpoint controller feedforward gain
    1743             :     // Range of Kf is 0.0f to 65.535f.
    1744           0 :     _pg_user->Kf = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1745             : 
    1746           0 :     return 1;
    1747             : 
    1748             : }// decodeCortex_EngineControlSettingsPacketStructure
    1749             : 
    1750             : /*!
    1751             :  * \brief Create the Cortex_ThrottleControlSettings packet
    1752             :  *
    1753             :  * Throttle control loop settings. This packet only has effect when Cortex
    1754             :  * device regulates engine throttle.
    1755             :  * \param _pg_pkt points to the packet which will be created by this function
    1756             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1757             :  */
    1758           0 : void encodeCortex_ThrottleControlSettingsPacketStructure(void* _pg_pkt, const Cortex_ThrottleControlSettings_t* _pg_user)
    1759             : {
    1760           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1761           0 :     int _pg_byteindex = 0;
    1762             : 
    1763             :     // Throttle control loop input filter
    1764             :     // Range of filter is 0.0f to 10.0f.
    1765           0 :     float32ScaledTo1UnsignedBytes(_pg_user->filter, _pg_data, &_pg_byteindex, 0.0f, 25.5f);
    1766             : 
    1767             :     // Initial throttle setting during engine start/cranking
    1768             :     // Range of startingThrottle is 0 to 255.
    1769           0 :     uint8ToBytes(_pg_user->startingThrottle, _pg_data, &_pg_byteindex);
    1770             : 
    1771             :     // Minimum throttle setting
    1772             :     // Range of minThrottle is 0 to 255.
    1773           0 :     uint8ToBytes(_pg_user->minThrottle, _pg_data, &_pg_byteindex);
    1774             : 
    1775             :     // Maximum throttle setting
    1776             :     // Range of maxThrottle is 0 to 255.
    1777           0 :     uint8ToBytes(_pg_user->maxThrottle, _pg_data, &_pg_byteindex);
    1778             : 
    1779             :     // Throttle controller proportional gain
    1780             :     // Range of Kp is 0.0f to 65.535f.
    1781           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Kp, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1782             : 
    1783             :     // Throttle controller integral gain
    1784             :     // Range of Ki is 0.0f to 65.535f.
    1785           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Ki, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1786             : 
    1787             :     // Throttle controller derivative gain
    1788             :     // Range of Kd is 0.0f to 65.535f.
    1789           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Kd, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1790             : 
    1791             :     // Throttle controller feedforward gain
    1792             :     // Range of Kf is 0.0f to 65.535f.
    1793           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->Kf, _pg_data, &_pg_byteindex, 0.0f, 1000.0f);
    1794             : 
    1795             :     // complete the process of creating the packet
    1796           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_ThrottleControlSettingsPacketID());
    1797             : 
    1798           0 : }// encodeCortex_ThrottleControlSettingsPacketStructure
    1799             : 
    1800             : /*!
    1801             :  * \brief Decode the Cortex_ThrottleControlSettings packet
    1802             :  *
    1803             :  * Throttle control loop settings. This packet only has effect when Cortex
    1804             :  * device regulates engine throttle.
    1805             :  * \param _pg_pkt points to the packet being decoded by this function
    1806             :  * \param _pg_user receives the data decoded from the packet
    1807             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1808             :  */
    1809           0 : int decodeCortex_ThrottleControlSettingsPacketStructure(const void* _pg_pkt, Cortex_ThrottleControlSettings_t* _pg_user)
    1810             : {
    1811             :     int _pg_numbytes;
    1812           0 :     int _pg_byteindex = 0;
    1813             :     const uint8_t* _pg_data;
    1814             : 
    1815             :     // Verify the packet identifier
    1816           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_ThrottleControlSettingsPacketID())
    1817           0 :         return 0;
    1818             : 
    1819             :     // Verify the packet size
    1820           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1821           0 :     if(_pg_numbytes < getCortex_ThrottleControlSettingsMinDataLength())
    1822           0 :         return 0;
    1823             : 
    1824             :     // The raw data from the packet
    1825           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    1826             : 
    1827             :     // Throttle control loop input filter
    1828             :     // Range of filter is 0.0f to 10.0f.
    1829           0 :     _pg_user->filter = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/25.5f);
    1830             : 
    1831             :     // Initial throttle setting during engine start/cranking
    1832             :     // Range of startingThrottle is 0 to 255.
    1833           0 :     _pg_user->startingThrottle = uint8FromBytes(_pg_data, &_pg_byteindex);
    1834             : 
    1835             :     // Minimum throttle setting
    1836             :     // Range of minThrottle is 0 to 255.
    1837           0 :     _pg_user->minThrottle = uint8FromBytes(_pg_data, &_pg_byteindex);
    1838             : 
    1839             :     // Maximum throttle setting
    1840             :     // Range of maxThrottle is 0 to 255.
    1841           0 :     _pg_user->maxThrottle = uint8FromBytes(_pg_data, &_pg_byteindex);
    1842             : 
    1843             :     // Throttle controller proportional gain
    1844             :     // Range of Kp is 0.0f to 65.535f.
    1845           0 :     _pg_user->Kp = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1846             : 
    1847             :     // Throttle controller integral gain
    1848             :     // Range of Ki is 0.0f to 65.535f.
    1849           0 :     _pg_user->Ki = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1850             : 
    1851             :     // Throttle controller derivative gain
    1852             :     // Range of Kd is 0.0f to 65.535f.
    1853           0 :     _pg_user->Kd = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1854             : 
    1855             :     // Throttle controller feedforward gain
    1856             :     // Range of Kf is 0.0f to 65.535f.
    1857           0 :     _pg_user->Kf = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/1000.0f);
    1858             : 
    1859           0 :     return 1;
    1860             : 
    1861             : }// decodeCortex_ThrottleControlSettingsPacketStructure
    1862             : 
    1863             : /*!
    1864             :  * \brief Create the Cortex_BatterySettings packet
    1865             :  *
    1866             :  * Battery settings
    1867             :  * \param _pg_pkt points to the packet which will be created by this function
    1868             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1869             :  */
    1870           0 : void encodeCortex_BatterySettingsPacketStructure(void* _pg_pkt, const Cortex_BatterySettings_t* _pg_user)
    1871             : {
    1872           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1873           0 :     int _pg_byteindex = 0;
    1874             : 
    1875             :     // Unused, reserved for future use
    1876           0 :     uint16ToBeBytes((uint16_t)(0), _pg_data, &_pg_byteindex);
    1877             : 
    1878             :     // Minimum engine speed required for battery charging
    1879             :     // Range of minChargingRpm is 0 to 65535.
    1880           0 :     uint16ToBeBytes(_pg_user->minChargingRpm, _pg_data, &_pg_byteindex);
    1881             : 
    1882             :     // Nominal battery voltage
    1883             :     // Range of nominalVoltage is 0.0f to 655.35f.
    1884           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->nominalVoltage, _pg_data, &_pg_byteindex, 0.0f, 100.0f);
    1885             : 
    1886             :     // Maximum battery charging current limit
    1887             :     // Range of chargeCurrentLimit is 0.0f to 25.5f.
    1888           0 :     float32ScaledTo1UnsignedBytes(_pg_user->chargeCurrentLimit, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    1889             : 
    1890             :     // Filter frequency for battery current measurement
    1891             :     // Range of currentFilter is 0.0f to 5.1f.
    1892           0 :     float32ScaledTo1UnsignedBytes(_pg_user->currentFilter, _pg_data, &_pg_byteindex, 0.0f, 50.0f);
    1893             : 
    1894             :     // complete the process of creating the packet
    1895           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_BatterySettingsPacketID());
    1896             : 
    1897           0 : }// encodeCortex_BatterySettingsPacketStructure
    1898             : 
    1899             : /*!
    1900             :  * \brief Decode the Cortex_BatterySettings packet
    1901             :  *
    1902             :  * Battery settings
    1903             :  * \param _pg_pkt points to the packet being decoded by this function
    1904             :  * \param _pg_user receives the data decoded from the packet
    1905             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1906             :  */
    1907           0 : int decodeCortex_BatterySettingsPacketStructure(const void* _pg_pkt, Cortex_BatterySettings_t* _pg_user)
    1908             : {
    1909             :     int _pg_numbytes;
    1910           0 :     int _pg_byteindex = 0;
    1911             :     const uint8_t* _pg_data;
    1912             : 
    1913             :     // Verify the packet identifier
    1914           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_BatterySettingsPacketID())
    1915           0 :         return 0;
    1916             : 
    1917             :     // Verify the packet size
    1918           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    1919           0 :     if(_pg_numbytes < getCortex_BatterySettingsMinDataLength())
    1920           0 :         return 0;
    1921             : 
    1922             :     // The raw data from the packet
    1923           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    1924             : 
    1925             :     // this packet has default fields, make sure they are set
    1926           0 :     _pg_user->nominalVoltage = 48;
    1927           0 :     _pg_user->chargeCurrentLimit = 5;
    1928           0 :     _pg_user->currentFilter = 1;
    1929             : 
    1930             :     // Unused, reserved for future use
    1931           0 :     _pg_byteindex += 2;
    1932             : 
    1933             :     // Minimum engine speed required for battery charging
    1934             :     // Range of minChargingRpm is 0 to 65535.
    1935           0 :     _pg_user->minChargingRpm = uint16FromBeBytes(_pg_data, &_pg_byteindex);
    1936             : 
    1937           0 :     if(_pg_byteindex + 2 > _pg_numbytes)
    1938           0 :         return 1;
    1939             : 
    1940             :     // Nominal battery voltage
    1941             :     // Range of nominalVoltage is 0.0f to 655.35f.
    1942           0 :     _pg_user->nominalVoltage = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/100.0f);
    1943             : 
    1944           0 :     if(_pg_byteindex + 1 > _pg_numbytes)
    1945           0 :         return 1;
    1946             : 
    1947             :     // Maximum battery charging current limit
    1948             :     // Range of chargeCurrentLimit is 0.0f to 25.5f.
    1949           0 :     _pg_user->chargeCurrentLimit = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    1950             : 
    1951           0 :     if(_pg_byteindex + 1 > _pg_numbytes)
    1952           0 :         return 1;
    1953             : 
    1954             :     // Filter frequency for battery current measurement
    1955             :     // Range of currentFilter is 0.0f to 5.1f.
    1956           0 :     _pg_user->currentFilter = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/50.0f);
    1957             : 
    1958           0 :     return 1;
    1959             : 
    1960             : }// decodeCortex_BatterySettingsPacketStructure
    1961             : 
    1962             : /*!
    1963             :  * \brief Create the Cortex_RailSettings packet
    1964             :  *
    1965             :  * Output rail settings
    1966             :  * \param _pg_pkt points to the packet which will be created by this function
    1967             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    1968             :  */
    1969           0 : void encodeCortex_RailSettingsPacketStructure(void* _pg_pkt, const Cortex_RailSettings_t* _pg_user)
    1970             : {
    1971           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    1972           0 :     int _pg_byteindex = 0;
    1973             : 
    1974             :     // Settings for avionics output rail
    1975           0 :     encodeCortex_OutputRailSettings_t(_pg_data, &_pg_byteindex, &_pg_user->AvionicsRail);
    1976             : 
    1977             :     // Settings for payload output rail
    1978           0 :     encodeCortex_OutputRailSettings_t(_pg_data, &_pg_byteindex, &_pg_user->PayloadRail);
    1979             : 
    1980             :     // Settings for servo output rail
    1981           0 :     encodeCortex_OutputRailSettings_t(_pg_data, &_pg_byteindex, &_pg_user->ServoRail);
    1982             : 
    1983             :     // Settings for battery charger output rail
    1984           0 :     encodeCortex_OutputRailSettings_t(_pg_data, &_pg_byteindex, &_pg_user->BatteryCharger);
    1985             : 
    1986             :     // complete the process of creating the packet
    1987           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_RailSettingsPacketID());
    1988             : 
    1989           0 : }// encodeCortex_RailSettingsPacketStructure
    1990             : 
    1991             : /*!
    1992             :  * \brief Decode the Cortex_RailSettings packet
    1993             :  *
    1994             :  * Output rail settings
    1995             :  * \param _pg_pkt points to the packet being decoded by this function
    1996             :  * \param _pg_user receives the data decoded from the packet
    1997             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    1998             :  */
    1999           0 : int decodeCortex_RailSettingsPacketStructure(const void* _pg_pkt, Cortex_RailSettings_t* _pg_user)
    2000             : {
    2001             :     int _pg_numbytes;
    2002           0 :     int _pg_byteindex = 0;
    2003             :     const uint8_t* _pg_data;
    2004             : 
    2005             :     // Verify the packet identifier
    2006           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_RailSettingsPacketID())
    2007           0 :         return 0;
    2008             : 
    2009             :     // Verify the packet size
    2010           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    2011           0 :     if(_pg_numbytes < getCortex_RailSettingsMinDataLength())
    2012           0 :         return 0;
    2013             : 
    2014             :     // The raw data from the packet
    2015           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    2016             : 
    2017             :     // Settings for avionics output rail
    2018           0 :     if(decodeCortex_OutputRailSettings_t(_pg_data, &_pg_byteindex, &_pg_user->AvionicsRail) == 0)
    2019           0 :         return 0;
    2020             : 
    2021             :     // Settings for payload output rail
    2022           0 :     if(decodeCortex_OutputRailSettings_t(_pg_data, &_pg_byteindex, &_pg_user->PayloadRail) == 0)
    2023           0 :         return 0;
    2024             : 
    2025             :     // Settings for servo output rail
    2026           0 :     if(decodeCortex_OutputRailSettings_t(_pg_data, &_pg_byteindex, &_pg_user->ServoRail) == 0)
    2027           0 :         return 0;
    2028             : 
    2029             :     // Settings for battery charger output rail
    2030           0 :     if(decodeCortex_OutputRailSettings_t(_pg_data, &_pg_byteindex, &_pg_user->BatteryCharger) == 0)
    2031           0 :         return 0;
    2032             : 
    2033           0 :     return 1;
    2034             : 
    2035             : }// decodeCortex_RailSettingsPacketStructure
    2036             : 
    2037             : /*!
    2038             :  * \brief Create the Cortex_ExtraTelltaleValues packet
    2039             :  *
    2040             :  * Cortex telltale values
    2041             :  * \param _pg_pkt points to the packet which will be created by this function
    2042             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    2043             :  */
    2044           0 : void encodeCortex_ExtraTelltaleValuesPacketStructure(void* _pg_pkt, const Cortex_ExtraTelltaleValues_t* _pg_user)
    2045             : {
    2046           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    2047           0 :     int _pg_byteindex = 0;
    2048             : 
    2049             :     // Maximum recorded battery current. ESC Telltale corresponds to maximum generator current.
    2050             :     // Range of maxBatteryCurrent is 0.0f to 6553.5f.
    2051           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->maxBatteryCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2052             : 
    2053             :     // Maximum recorded battery voltage. ESC Telltale corresponds to maximum generator voltage.
    2054             :     // Range of maxBatteryVoltage is 0.0f to 6553.5f.
    2055           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->maxBatteryVoltage, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2056             : 
    2057             :     // Maximum recorded avionics rail voltage
    2058             :     // Range of maxAvionicsVoltage is 0.0f to 6553.5f.
    2059           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->maxAvionicsVoltage, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2060             : 
    2061             :     // Maximum recorded payload rail voltage
    2062             :     // Range of maxPayloadVoltage is 0.0f to 6553.5f.
    2063           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->maxPayloadVoltage, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2064             : 
    2065             :     // Maximum recorded servo rail voltage
    2066             :     // Range of maxServoVoltage is 0.0f to 6553.5f.
    2067           0 :     float32ScaledTo2UnsignedBeBytes(_pg_user->maxServoVoltage, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2068             : 
    2069             :     // Maximum recorded battery charging current
    2070             :     // Range of maxChargeCurrent is 0.0f to 25.5f.
    2071           0 :     float32ScaledTo1UnsignedBytes(_pg_user->maxChargeCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2072             : 
    2073             :     // Maximum recorded avionics rail current
    2074             :     // Range of maxAvionicsCurrent is 0.0f to 25.5f.
    2075           0 :     float32ScaledTo1UnsignedBytes(_pg_user->maxAvionicsCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2076             : 
    2077             :     // Maximum recorded payload rail current
    2078             :     // Range of maxPayloadCurrent is 0.0f to 25.5f.
    2079           0 :     float32ScaledTo1UnsignedBytes(_pg_user->maxPayloadCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2080             : 
    2081             :     // Maximum recorded servo rail current
    2082             :     // Range of maxServoCurrent is 0.0f to 25.5f.
    2083           0 :     float32ScaledTo1UnsignedBytes(_pg_user->maxServoCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2084             : 
    2085             :     // complete the process of creating the packet
    2086           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_ExtraTelltaleValuesPacketID());
    2087             : 
    2088           0 : }// encodeCortex_ExtraTelltaleValuesPacketStructure
    2089             : 
    2090             : /*!
    2091             :  * \brief Decode the Cortex_ExtraTelltaleValues packet
    2092             :  *
    2093             :  * Cortex telltale values
    2094             :  * \param _pg_pkt points to the packet being decoded by this function
    2095             :  * \param _pg_user receives the data decoded from the packet
    2096             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2097             :  */
    2098           0 : int decodeCortex_ExtraTelltaleValuesPacketStructure(const void* _pg_pkt, Cortex_ExtraTelltaleValues_t* _pg_user)
    2099             : {
    2100             :     int _pg_numbytes;
    2101           0 :     int _pg_byteindex = 0;
    2102             :     const uint8_t* _pg_data;
    2103             : 
    2104             :     // Verify the packet identifier
    2105           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_ExtraTelltaleValuesPacketID())
    2106           0 :         return 0;
    2107             : 
    2108             :     // Verify the packet size
    2109           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    2110           0 :     if(_pg_numbytes < getCortex_ExtraTelltaleValuesMinDataLength())
    2111           0 :         return 0;
    2112             : 
    2113             :     // The raw data from the packet
    2114           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    2115             : 
    2116             :     // Maximum recorded battery current. ESC Telltale corresponds to maximum generator current.
    2117             :     // Range of maxBatteryCurrent is 0.0f to 6553.5f.
    2118           0 :     _pg_user->maxBatteryCurrent = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2119             : 
    2120             :     // Maximum recorded battery voltage. ESC Telltale corresponds to maximum generator voltage.
    2121             :     // Range of maxBatteryVoltage is 0.0f to 6553.5f.
    2122           0 :     _pg_user->maxBatteryVoltage = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2123             : 
    2124             :     // Maximum recorded avionics rail voltage
    2125             :     // Range of maxAvionicsVoltage is 0.0f to 6553.5f.
    2126           0 :     _pg_user->maxAvionicsVoltage = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2127             : 
    2128             :     // Maximum recorded payload rail voltage
    2129             :     // Range of maxPayloadVoltage is 0.0f to 6553.5f.
    2130           0 :     _pg_user->maxPayloadVoltage = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2131             : 
    2132             :     // Maximum recorded servo rail voltage
    2133             :     // Range of maxServoVoltage is 0.0f to 6553.5f.
    2134           0 :     _pg_user->maxServoVoltage = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2135             : 
    2136             :     // Maximum recorded battery charging current
    2137             :     // Range of maxChargeCurrent is 0.0f to 25.5f.
    2138           0 :     _pg_user->maxChargeCurrent = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2139             : 
    2140             :     // Maximum recorded avionics rail current
    2141             :     // Range of maxAvionicsCurrent is 0.0f to 25.5f.
    2142           0 :     _pg_user->maxAvionicsCurrent = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2143             : 
    2144             :     // Maximum recorded payload rail current
    2145             :     // Range of maxPayloadCurrent is 0.0f to 25.5f.
    2146           0 :     _pg_user->maxPayloadCurrent = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2147             : 
    2148             :     // Maximum recorded servo rail current
    2149             :     // Range of maxServoCurrent is 0.0f to 25.5f.
    2150           0 :     _pg_user->maxServoCurrent = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2151             : 
    2152           0 :     return 1;
    2153             : 
    2154             : }// decodeCortex_ExtraTelltaleValuesPacketStructure
    2155             : 
    2156             : /*!
    2157             :  * \brief Create the Cortex_ExtraTelltaleValues packet
    2158             :  *
    2159             :  * Cortex telltale values
    2160             :  * \param _pg_pkt points to the packet which will be created by this function
    2161             :  * \param maxBatteryCurrent is Maximum recorded battery current. ESC Telltale corresponds to maximum generator current.
    2162             :  * \param maxBatteryVoltage is Maximum recorded battery voltage. ESC Telltale corresponds to maximum generator voltage.
    2163             :  * \param maxAvionicsVoltage is Maximum recorded avionics rail voltage
    2164             :  * \param maxPayloadVoltage is Maximum recorded payload rail voltage
    2165             :  * \param maxServoVoltage is Maximum recorded servo rail voltage
    2166             :  * \param maxChargeCurrent is Maximum recorded battery charging current
    2167             :  * \param maxAvionicsCurrent is Maximum recorded avionics rail current
    2168             :  * \param maxPayloadCurrent is Maximum recorded payload rail current
    2169             :  * \param maxServoCurrent is Maximum recorded servo rail current
    2170             :  */
    2171           0 : void encodeCortex_ExtraTelltaleValuesPacket(void* _pg_pkt, float maxBatteryCurrent, float maxBatteryVoltage, float maxAvionicsVoltage, float maxPayloadVoltage, float maxServoVoltage, float maxChargeCurrent, float maxAvionicsCurrent, float maxPayloadCurrent, float maxServoCurrent)
    2172             : {
    2173           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    2174           0 :     int _pg_byteindex = 0;
    2175             : 
    2176             :     // Maximum recorded battery current. ESC Telltale corresponds to maximum generator current.
    2177             :     // Range of maxBatteryCurrent is 0.0f to 6553.5f.
    2178           0 :     float32ScaledTo2UnsignedBeBytes(maxBatteryCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2179             : 
    2180             :     // Maximum recorded battery voltage. ESC Telltale corresponds to maximum generator voltage.
    2181             :     // Range of maxBatteryVoltage is 0.0f to 6553.5f.
    2182           0 :     float32ScaledTo2UnsignedBeBytes(maxBatteryVoltage, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2183             : 
    2184             :     // Maximum recorded avionics rail voltage
    2185             :     // Range of maxAvionicsVoltage is 0.0f to 6553.5f.
    2186           0 :     float32ScaledTo2UnsignedBeBytes(maxAvionicsVoltage, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2187             : 
    2188             :     // Maximum recorded payload rail voltage
    2189             :     // Range of maxPayloadVoltage is 0.0f to 6553.5f.
    2190           0 :     float32ScaledTo2UnsignedBeBytes(maxPayloadVoltage, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2191             : 
    2192             :     // Maximum recorded servo rail voltage
    2193             :     // Range of maxServoVoltage is 0.0f to 6553.5f.
    2194           0 :     float32ScaledTo2UnsignedBeBytes(maxServoVoltage, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2195             : 
    2196             :     // Maximum recorded battery charging current
    2197             :     // Range of maxChargeCurrent is 0.0f to 25.5f.
    2198           0 :     float32ScaledTo1UnsignedBytes(maxChargeCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2199             : 
    2200             :     // Maximum recorded avionics rail current
    2201             :     // Range of maxAvionicsCurrent is 0.0f to 25.5f.
    2202           0 :     float32ScaledTo1UnsignedBytes(maxAvionicsCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2203             : 
    2204             :     // Maximum recorded payload rail current
    2205             :     // Range of maxPayloadCurrent is 0.0f to 25.5f.
    2206           0 :     float32ScaledTo1UnsignedBytes(maxPayloadCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2207             : 
    2208             :     // Maximum recorded servo rail current
    2209             :     // Range of maxServoCurrent is 0.0f to 25.5f.
    2210           0 :     float32ScaledTo1UnsignedBytes(maxServoCurrent, _pg_data, &_pg_byteindex, 0.0f, 10.0f);
    2211             : 
    2212             :     // complete the process of creating the packet
    2213           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_ExtraTelltaleValuesPacketID());
    2214             : 
    2215           0 : }// encodeCortex_ExtraTelltaleValuesPacket
    2216             : 
    2217             : /*!
    2218             :  * \brief Decode the Cortex_ExtraTelltaleValues packet
    2219             :  *
    2220             :  * Cortex telltale values
    2221             :  * \param _pg_pkt points to the packet being decoded by this function
    2222             :  * \param maxBatteryCurrent receives Maximum recorded battery current. ESC Telltale corresponds to maximum generator current.
    2223             :  * \param maxBatteryVoltage receives Maximum recorded battery voltage. ESC Telltale corresponds to maximum generator voltage.
    2224             :  * \param maxAvionicsVoltage receives Maximum recorded avionics rail voltage
    2225             :  * \param maxPayloadVoltage receives Maximum recorded payload rail voltage
    2226             :  * \param maxServoVoltage receives Maximum recorded servo rail voltage
    2227             :  * \param maxChargeCurrent receives Maximum recorded battery charging current
    2228             :  * \param maxAvionicsCurrent receives Maximum recorded avionics rail current
    2229             :  * \param maxPayloadCurrent receives Maximum recorded payload rail current
    2230             :  * \param maxServoCurrent receives Maximum recorded servo rail current
    2231             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2232             :  */
    2233           0 : int decodeCortex_ExtraTelltaleValuesPacket(const void* _pg_pkt, float* maxBatteryCurrent, float* maxBatteryVoltage, float* maxAvionicsVoltage, float* maxPayloadVoltage, float* maxServoVoltage, float* maxChargeCurrent, float* maxAvionicsCurrent, float* maxPayloadCurrent, float* maxServoCurrent)
    2234             : {
    2235           0 :     int _pg_byteindex = 0;
    2236           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
    2237           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
    2238             : 
    2239             :     // Verify the packet identifier
    2240           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_ExtraTelltaleValuesPacketID())
    2241           0 :         return 0;
    2242             : 
    2243           0 :     if(_pg_numbytes < getCortex_ExtraTelltaleValuesMinDataLength())
    2244           0 :         return 0;
    2245             : 
    2246             :     // Maximum recorded battery current. ESC Telltale corresponds to maximum generator current.
    2247             :     // Range of maxBatteryCurrent is 0.0f to 6553.5f.
    2248           0 :     (*maxBatteryCurrent) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2249             : 
    2250             :     // Maximum recorded battery voltage. ESC Telltale corresponds to maximum generator voltage.
    2251             :     // Range of maxBatteryVoltage is 0.0f to 6553.5f.
    2252           0 :     (*maxBatteryVoltage) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2253             : 
    2254             :     // Maximum recorded avionics rail voltage
    2255             :     // Range of maxAvionicsVoltage is 0.0f to 6553.5f.
    2256           0 :     (*maxAvionicsVoltage) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2257             : 
    2258             :     // Maximum recorded payload rail voltage
    2259             :     // Range of maxPayloadVoltage is 0.0f to 6553.5f.
    2260           0 :     (*maxPayloadVoltage) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2261             : 
    2262             :     // Maximum recorded servo rail voltage
    2263             :     // Range of maxServoVoltage is 0.0f to 6553.5f.
    2264           0 :     (*maxServoVoltage) = float32ScaledFrom2UnsignedBeBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2265             : 
    2266             :     // Maximum recorded battery charging current
    2267             :     // Range of maxChargeCurrent is 0.0f to 25.5f.
    2268           0 :     (*maxChargeCurrent) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2269             : 
    2270             :     // Maximum recorded avionics rail current
    2271             :     // Range of maxAvionicsCurrent is 0.0f to 25.5f.
    2272           0 :     (*maxAvionicsCurrent) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2273             : 
    2274             :     // Maximum recorded payload rail current
    2275             :     // Range of maxPayloadCurrent is 0.0f to 25.5f.
    2276           0 :     (*maxPayloadCurrent) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2277             : 
    2278             :     // Maximum recorded servo rail current
    2279             :     // Range of maxServoCurrent is 0.0f to 25.5f.
    2280           0 :     (*maxServoCurrent) = float32ScaledFrom1UnsignedBytes(_pg_data, &_pg_byteindex, 0.0f, 1.0f/10.0f);
    2281             : 
    2282           0 :     return 1;
    2283             : 
    2284             : }// decodeCortex_ExtraTelltaleValuesPacket
    2285             : 
    2286             : /*!
    2287             :  * \brief Create the Cortex_EnableRail packet
    2288             :  *
    2289             :  * Example output enable for testing
    2290             :  * \param _pg_pkt points to the packet which will be created by this function
    2291             :  * \param _pg_user points to the user data that will be encoded in _pg_pkt
    2292             :  */
    2293           0 : void encodeCortex_EnableRailPacketStructure(void* _pg_pkt, const Cortex_EnableRail_t* _pg_user)
    2294             : {
    2295           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    2296           0 :     int _pg_byteindex = 0;
    2297             : 
    2298             :     // SERVO = 0, BATTERY_CHARGER = 1, PAYLOAD = 2, AVIONICS = 3
    2299             :     // Range of index is 0 to 15.
    2300           0 :     _pg_data[_pg_byteindex] = (uint8_t)limitMax(_pg_user->index, 15) << 4;
    2301             : 
    2302             :     // 1 = enabled. 0 = disabled.
    2303           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->enable == true) ? 1 : 0) << 3;
    2304             : 
    2305             :     // Reserved bits
    2306           0 :     _pg_byteindex += 1; // close bit field
    2307             : 
    2308             :     // complete the process of creating the packet
    2309           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_EnableRailPacketID());
    2310             : 
    2311           0 : }// encodeCortex_EnableRailPacketStructure
    2312             : 
    2313             : /*!
    2314             :  * \brief Decode the Cortex_EnableRail packet
    2315             :  *
    2316             :  * Example output enable for testing
    2317             :  * \param _pg_pkt points to the packet being decoded by this function
    2318             :  * \param _pg_user receives the data decoded from the packet
    2319             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2320             :  */
    2321           0 : int decodeCortex_EnableRailPacketStructure(const void* _pg_pkt, Cortex_EnableRail_t* _pg_user)
    2322             : {
    2323             :     int _pg_numbytes;
    2324           0 :     int _pg_byteindex = 0;
    2325             :     const uint8_t* _pg_data;
    2326             : 
    2327             :     // Verify the packet identifier
    2328           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_EnableRailPacketID())
    2329           0 :         return 0;
    2330             : 
    2331             :     // Verify the packet size
    2332           0 :     _pg_numbytes = getCortexPacketSize(_pg_pkt);
    2333           0 :     if(_pg_numbytes < getCortex_EnableRailMinDataLength())
    2334           0 :         return 0;
    2335             : 
    2336             :     // The raw data from the packet
    2337           0 :     _pg_data = getCortexPacketDataConst(_pg_pkt);
    2338             : 
    2339             :     // SERVO = 0, BATTERY_CHARGER = 1, PAYLOAD = 2, AVIONICS = 3
    2340             :     // Range of index is 0 to 15.
    2341           0 :     _pg_user->index = (_pg_data[_pg_byteindex] >> 4);
    2342             : 
    2343             :     // 1 = enabled. 0 = disabled.
    2344           0 :     _pg_user->enable = (((_pg_data[_pg_byteindex] >> 3) & 0x1)) ? true : false;
    2345             : 
    2346             :     // Reserved bits
    2347           0 :     _pg_byteindex += 1; // close bit field
    2348             : 
    2349           0 :     return 1;
    2350             : 
    2351             : }// decodeCortex_EnableRailPacketStructure
    2352             : 
    2353             : /*!
    2354             :  * \brief Create the Cortex_EnableRail packet
    2355             :  *
    2356             :  * Example output enable for testing
    2357             :  * \param _pg_pkt points to the packet which will be created by this function
    2358             :  * \param index is SERVO = 0, BATTERY_CHARGER = 1, PAYLOAD = 2, AVIONICS = 3
    2359             :  * \param enable is 1 = enabled. 0 = disabled.
    2360             :  */
    2361           0 : void encodeCortex_EnableRailPacket(void* _pg_pkt, uint8_t index, bool enable)
    2362             : {
    2363           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    2364           0 :     int _pg_byteindex = 0;
    2365             : 
    2366             :     // SERVO = 0, BATTERY_CHARGER = 1, PAYLOAD = 2, AVIONICS = 3
    2367             :     // Range of index is 0 to 15.
    2368           0 :     _pg_data[_pg_byteindex] = (uint8_t)limitMax(index, 15) << 4;
    2369             : 
    2370             :     // 1 = enabled. 0 = disabled.
    2371           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((enable == true) ? 1 : 0) << 3;
    2372             : 
    2373             :     // Reserved bits
    2374           0 :     _pg_byteindex += 1; // close bit field
    2375             : 
    2376             :     // complete the process of creating the packet
    2377           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_EnableRailPacketID());
    2378             : 
    2379           0 : }// encodeCortex_EnableRailPacket
    2380             : 
    2381             : /*!
    2382             :  * \brief Decode the Cortex_EnableRail packet
    2383             :  *
    2384             :  * Example output enable for testing
    2385             :  * \param _pg_pkt points to the packet being decoded by this function
    2386             :  * \param index receives SERVO = 0, BATTERY_CHARGER = 1, PAYLOAD = 2, AVIONICS = 3
    2387             :  * \param enable receives 1 = enabled. 0 = disabled.
    2388             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2389             :  */
    2390           0 : int decodeCortex_EnableRailPacket(const void* _pg_pkt, uint8_t* index, bool* enable)
    2391             : {
    2392           0 :     int _pg_byteindex = 0;
    2393           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
    2394           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
    2395             : 
    2396             :     // Verify the packet identifier
    2397           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_EnableRailPacketID())
    2398           0 :         return 0;
    2399             : 
    2400           0 :     if(_pg_numbytes < getCortex_EnableRailMinDataLength())
    2401           0 :         return 0;
    2402             : 
    2403             :     // SERVO = 0, BATTERY_CHARGER = 1, PAYLOAD = 2, AVIONICS = 3
    2404             :     // Range of index is 0 to 15.
    2405           0 :     (*index) = (_pg_data[_pg_byteindex] >> 4);
    2406             : 
    2407             :     // 1 = enabled. 0 = disabled.
    2408           0 :     (*enable) = (((_pg_data[_pg_byteindex] >> 3) & 0x1)) ? true : false;
    2409             : 
    2410             :     // Reserved bits
    2411           0 :     _pg_byteindex += 1; // close bit field
    2412             : 
    2413           0 :     return 1;
    2414             : 
    2415             : }// decodeCortex_EnableRailPacket
    2416             : 
    2417             : /*!
    2418             :  * \brief Create the Cortex_EnterCalibrationMode packet
    2419             :  *
    2420             :  * Enter calibration mode
    2421             :  * \param _pg_pkt points to the packet which will be created by this function
    2422             :  * \param serialNumber is Serial number of the device
    2423             :  */
    2424           0 : void encodeCortex_EnterCalibrationModePacket(void* _pg_pkt, uint32_t serialNumber)
    2425             : {
    2426           0 :     uint8_t* _pg_data = getCortexPacketData(_pg_pkt);
    2427           0 :     int _pg_byteindex = 0;
    2428             : 
    2429             :     // Constant value required for calibration sequence
    2430           0 :     uint8ToBytes((uint8_t)(0xC0), _pg_data, &_pg_byteindex);
    2431             : 
    2432             :     // Constant value required for calibration sequence
    2433           0 :     uint8ToBytes((uint8_t)(0xC1), _pg_data, &_pg_byteindex);
    2434             : 
    2435             :     // Serial number of the device
    2436             :     // Range of serialNumber is 0 to 4294967295.
    2437           0 :     uint32ToBeBytes(serialNumber, _pg_data, &_pg_byteindex);
    2438             : 
    2439             :     // complete the process of creating the packet
    2440           0 :     finishCortexPacket(_pg_pkt, _pg_byteindex, getCortex_EnterCalibrationModePacketID());
    2441             : 
    2442           0 : }// encodeCortex_EnterCalibrationModePacket
    2443             : 
    2444             : /*!
    2445             :  * \brief Decode the Cortex_EnterCalibrationMode packet
    2446             :  *
    2447             :  * Enter calibration mode
    2448             :  * \param _pg_pkt points to the packet being decoded by this function
    2449             :  * \param serialNumber receives Serial number of the device
    2450             :  * \return 0 is returned if the packet ID or size is wrong, else 1
    2451             :  */
    2452           0 : int decodeCortex_EnterCalibrationModePacket(const void* _pg_pkt, uint32_t* serialNumber)
    2453             : {
    2454           0 :     int _pg_byteindex = 0;
    2455           0 :     const uint8_t* _pg_data = getCortexPacketDataConst(_pg_pkt);
    2456           0 :     int _pg_numbytes = getCortexPacketSize(_pg_pkt);
    2457             : 
    2458             :     // Verify the packet identifier
    2459           0 :     if(getCortexPacketID(_pg_pkt) != getCortex_EnterCalibrationModePacketID())
    2460           0 :         return 0;
    2461             : 
    2462           0 :     if(_pg_numbytes < getCortex_EnterCalibrationModeMinDataLength())
    2463           0 :         return 0;
    2464             : 
    2465             :     // Constant value required for calibration sequence
    2466           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xC0)
    2467           0 :         return 0;
    2468             : 
    2469             :     // Constant value required for calibration sequence
    2470           0 :     if (uint8FromBytes(_pg_data, &_pg_byteindex) != (uint8_t) 0xC1)
    2471           0 :         return 0;
    2472             : 
    2473             :     // Serial number of the device
    2474             :     // Range of serialNumber is 0 to 4294967295.
    2475           0 :     (*serialNumber) = uint32FromBeBytes(_pg_data, &_pg_byteindex);
    2476             : 
    2477           0 :     return 1;
    2478             : 
    2479             : }// decodeCortex_EnterCalibrationModePacket
    2480             : // end of CortexPackets.c

Generated by: LCOV version 1.14