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

          Line data    Source code
       1             : // CortexDefines.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 "CortexDefines.h"
      21             : #include "fielddecode.h"
      22             : #include "fieldencode.h"
      23             : #include "scaleddecode.h"
      24             : #include "scaledencode.h"
      25             : 
      26             : /*!
      27             :  * \brief Encode a Cortex_StatusBits_t into a byte array
      28             :  *
      29             :  * Status bits for the TelemetryStatus packet
      30             :  * \param _pg_data points to the byte array to add encoded data to
      31             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
      32             :  * \param _pg_user is the data to encode in the byte array
      33             :  */
      34           0 : void encodeCortex_StatusBits_t(uint8_t* _pg_data, int* _pg_bytecount, const Cortex_StatusBits_t* _pg_user)
      35             : {
      36           0 :     int _pg_byteindex = *_pg_bytecount;
      37             : 
      38             :     // Reserved bits
      39           0 :     _pg_data[_pg_byteindex] = 0;
      40             : 
      41             :     // Cortex operational mode
      42             :     // Range of mode is 0 to 15.
      43           0 :     _pg_data[_pg_byteindex] |= (uint8_t)limitMax(_pg_user->mode, 15);
      44             : 
      45             :     // Warning flag (refer to 'warning' structure)
      46           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)((_pg_user->warning == true) ? 1 : 0) << 7;
      47             : 
      48             :     // Error flag (refer to 'error' structure)
      49           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)((_pg_user->error == true) ? 1 : 0) << 6;
      50             : 
      51             :     // Set if generator power limit is currently active
      52           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)((_pg_user->powerLimit == true) ? 1 : 0) << 5;
      53             : 
      54             :     // Set if CHPS is running from shore power
      55           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)((_pg_user->shorePower == true) ? 1 : 0) << 4;
      56             : 
      57             :     // Set if the CHPS is ready to run the engine
      58           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)((_pg_user->readyToRun == true) ? 1 : 0) << 3;
      59             : 
      60             :     // Set if the CHPS is hardware inhibited
      61           0 :     _pg_data[_pg_byteindex + 1] |= (uint8_t)((_pg_user->inhibited == true) ? 1 : 0) << 2;
      62             : 
      63             :     // Reserved bits
      64             : 
      65             :     // Set if the CHPS is in calibration mode
      66           0 :     _pg_data[_pg_byteindex + 2] = (uint8_t)((_pg_user->calibrationMode == true) ? 1 : 0) << 7;
      67             : 
      68             :     // Reserved byte
      69             : 
      70             :     // Battery charger enabled status
      71             :     // Range of batteryCharger is 0 to 3.
      72           0 :     _pg_data[_pg_byteindex + 3] = (uint8_t)limitMax(_pg_user->batteryCharger, 3) << 6;
      73             : 
      74             :     // Avionics output rail enabled status
      75             :     // Range of avionicsRail is 0 to 3.
      76           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)limitMax(_pg_user->avionicsRail, 3) << 4;
      77             : 
      78             :     // Payload output rail enabled status
      79             :     // Range of payloadRail is 0 to 3.
      80           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)limitMax(_pg_user->payloadRail, 3) << 2;
      81             : 
      82             :     // Servo output rail enabled status
      83             :     // Range of servoRail is 0 to 3.
      84           0 :     _pg_data[_pg_byteindex + 3] |= (uint8_t)limitMax(_pg_user->servoRail, 3);
      85           0 :     _pg_byteindex += 4; // close bit field
      86             : 
      87           0 :     *_pg_bytecount = _pg_byteindex;
      88             : 
      89           0 : }// encodeCortex_StatusBits_t
      90             : 
      91             : /*!
      92             :  * \brief Decode a Cortex_StatusBits_t from a byte array
      93             :  *
      94             :  * Status bits for the TelemetryStatus packet
      95             :  * \param _pg_data points to the byte array to decoded data from
      96             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
      97             :  * \param _pg_user is the data to decode from the byte array
      98             :  * \return 1 if the data are decoded, else 0.
      99             :  */
     100           0 : int decodeCortex_StatusBits_t(const uint8_t* _pg_data, int* _pg_bytecount, Cortex_StatusBits_t* _pg_user)
     101             : {
     102           0 :     int _pg_byteindex = *_pg_bytecount;
     103             : 
     104             :     // Reserved bits
     105             : 
     106             :     // Cortex operational mode
     107             :     // Range of mode is 0 to 15.
     108           0 :     _pg_user->mode = ((_pg_data[_pg_byteindex]) & 0xF);
     109             : 
     110             :     // Warning flag (refer to 'warning' structure)
     111           0 :     _pg_user->warning = ((_pg_data[_pg_byteindex + 1] >> 7)) ? true : false;
     112             : 
     113             :     // Error flag (refer to 'error' structure)
     114           0 :     _pg_user->error = (((_pg_data[_pg_byteindex + 1] >> 6) & 0x1)) ? true : false;
     115             : 
     116             :     // Set if generator power limit is currently active
     117           0 :     _pg_user->powerLimit = (((_pg_data[_pg_byteindex + 1] >> 5) & 0x1)) ? true : false;
     118             : 
     119             :     // Set if CHPS is running from shore power
     120           0 :     _pg_user->shorePower = (((_pg_data[_pg_byteindex + 1] >> 4) & 0x1)) ? true : false;
     121             : 
     122             :     // Set if the CHPS is ready to run the engine
     123           0 :     _pg_user->readyToRun = (((_pg_data[_pg_byteindex + 1] >> 3) & 0x1)) ? true : false;
     124             : 
     125             :     // Set if the CHPS is hardware inhibited
     126           0 :     _pg_user->inhibited = (((_pg_data[_pg_byteindex + 1] >> 2) & 0x1)) ? true : false;
     127             : 
     128             :     // Reserved bits
     129             : 
     130             :     // Set if the CHPS is in calibration mode
     131           0 :     _pg_user->calibrationMode = ((_pg_data[_pg_byteindex + 2] >> 7)) ? true : false;
     132             : 
     133             :     // Reserved byte
     134             : 
     135             :     // Battery charger enabled status
     136             :     // Range of batteryCharger is 0 to 3.
     137           0 :     _pg_user->batteryCharger = (_pg_data[_pg_byteindex + 3] >> 6);
     138             : 
     139             :     // Avionics output rail enabled status
     140             :     // Range of avionicsRail is 0 to 3.
     141           0 :     _pg_user->avionicsRail = ((_pg_data[_pg_byteindex + 3] >> 4) & 0x3);
     142             : 
     143             :     // Payload output rail enabled status
     144             :     // Range of payloadRail is 0 to 3.
     145           0 :     _pg_user->payloadRail = ((_pg_data[_pg_byteindex + 3] >> 2) & 0x3);
     146             : 
     147             :     // Servo output rail enabled status
     148             :     // Range of servoRail is 0 to 3.
     149           0 :     _pg_user->servoRail = ((_pg_data[_pg_byteindex + 3]) & 0x3);
     150           0 :     _pg_byteindex += 4; // close bit field
     151             : 
     152           0 :     *_pg_bytecount = _pg_byteindex;
     153             : 
     154           0 :     return 1;
     155             : 
     156             : }// decodeCortex_StatusBits_t
     157             : 
     158             : /*!
     159             :  * \brief Encode a Cortex_WarningBits_t into a byte array
     160             :  *
     161             :  * Warning bits for the TelemetryStatus packet
     162             :  * \param _pg_data points to the byte array to add encoded data to
     163             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     164             :  * \param _pg_user is the data to encode in the byte array
     165             :  */
     166           0 : void encodeCortex_WarningBits_t(uint8_t* _pg_data, int* _pg_bytecount, const Cortex_WarningBits_t* _pg_user)
     167             : {
     168           0 :     int _pg_byteindex = *_pg_bytecount;
     169             : 
     170             :     // Generator warning - refer to the motor warnings packet
     171           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->generator == true) ? 1 : 0) << 7;
     172             : 
     173             :     // Device overtemperature warning
     174           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->temperature == true) ? 1 : 0) << 6;
     175             : 
     176             :     // Generator temperature limit warning
     177           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->generatorTempLimit == true) ? 1 : 0) << 5;
     178             : 
     179             :     // Generator current limit warning
     180           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->generatorCurrentLimit == true) ? 1 : 0) << 4;
     181             : 
     182             :     // Engine power limit warning
     183           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->enginePowerLimit == true) ? 1 : 0) << 3;
     184             : 
     185             :     // Power loss warning (engine is not developing any power)
     186           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->powerLoss == true) ? 1 : 0) << 2;
     187             : 
     188             :     // Low RPM warning (engine speed is below minimum RPM threshold)
     189           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->lowRpm == true) ? 1 : 0) << 1;
     190             : 
     191             :     // Battery charge current limit warning
     192           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->batteryChargeCurrentLimit == true) ? 1 : 0);
     193           0 :     _pg_byteindex += 1; // close bit field
     194             : 
     195             :     // Reserved byte
     196           0 :     uint8ToBytes((uint8_t)(0), _pg_data, &_pg_byteindex);
     197             : 
     198           0 :     *_pg_bytecount = _pg_byteindex;
     199             : 
     200           0 : }// encodeCortex_WarningBits_t
     201             : 
     202             : /*!
     203             :  * \brief Decode a Cortex_WarningBits_t from a byte array
     204             :  *
     205             :  * Warning bits for the TelemetryStatus packet
     206             :  * \param _pg_data points to the byte array to decoded data from
     207             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     208             :  * \param _pg_user is the data to decode from the byte array
     209             :  * \return 1 if the data are decoded, else 0.
     210             :  */
     211           0 : int decodeCortex_WarningBits_t(const uint8_t* _pg_data, int* _pg_bytecount, Cortex_WarningBits_t* _pg_user)
     212             : {
     213           0 :     int _pg_byteindex = *_pg_bytecount;
     214             : 
     215             :     // Generator warning - refer to the motor warnings packet
     216           0 :     _pg_user->generator = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
     217             : 
     218             :     // Device overtemperature warning
     219           0 :     _pg_user->temperature = (((_pg_data[_pg_byteindex] >> 6) & 0x1)) ? true : false;
     220             : 
     221             :     // Generator temperature limit warning
     222           0 :     _pg_user->generatorTempLimit = (((_pg_data[_pg_byteindex] >> 5) & 0x1)) ? true : false;
     223             : 
     224             :     // Generator current limit warning
     225           0 :     _pg_user->generatorCurrentLimit = (((_pg_data[_pg_byteindex] >> 4) & 0x1)) ? true : false;
     226             : 
     227             :     // Engine power limit warning
     228           0 :     _pg_user->enginePowerLimit = (((_pg_data[_pg_byteindex] >> 3) & 0x1)) ? true : false;
     229             : 
     230             :     // Power loss warning (engine is not developing any power)
     231           0 :     _pg_user->powerLoss = (((_pg_data[_pg_byteindex] >> 2) & 0x1)) ? true : false;
     232             : 
     233             :     // Low RPM warning (engine speed is below minimum RPM threshold)
     234           0 :     _pg_user->lowRpm = (((_pg_data[_pg_byteindex] >> 1) & 0x1)) ? true : false;
     235             : 
     236             :     // Battery charge current limit warning
     237           0 :     _pg_user->batteryChargeCurrentLimit = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
     238           0 :     _pg_byteindex += 1; // close bit field
     239             : 
     240             :     // Reserved byte
     241           0 :     _pg_byteindex += 1;
     242             : 
     243           0 :     *_pg_bytecount = _pg_byteindex;
     244             : 
     245           0 :     return 1;
     246             : 
     247             : }// decodeCortex_WarningBits_t
     248             : 
     249             : /*!
     250             :  * \brief Encode a Cortex_ErrorBits_t into a byte array
     251             :  *
     252             :  * Error bits for the TelemetryStatus packet
     253             :  * \param _pg_data points to the byte array to add encoded data to
     254             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     255             :  * \param _pg_user is the data to encode in the byte array
     256             :  */
     257           0 : void encodeCortex_ErrorBits_t(uint8_t* _pg_data, int* _pg_bytecount, const Cortex_ErrorBits_t* _pg_user)
     258             : {
     259           0 :     int _pg_byteindex = *_pg_bytecount;
     260             : 
     261             :     // Critical generator fault - refer to the motor errors packet
     262           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->generator == true) ? 1 : 0) << 7;
     263             : 
     264             :     // Critical error occurred during engine cranking
     265           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->cranking == true) ? 1 : 0) << 6;
     266             : 
     267             :     // Critical error occurred during rail configuration
     268           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->avionicsRail == true) ? 1 : 0) << 5;
     269             : 
     270             :     // Critical error occurred during rail configuration
     271           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->payloadRail == true) ? 1 : 0) << 4;
     272             : 
     273             :     // Critical error occurred during rail configuration
     274           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->servoRail == true) ? 1 : 0) << 3;
     275             : 
     276             :     // Critical error occurred during rail configuration
     277           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->batteryChargerRail == true) ? 1 : 0) << 2;
     278             : 
     279             :     // Power map is improperly configured
     280           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->powerMap == true) ? 1 : 0) << 1;
     281             : 
     282             :     // Engine was disabled due to low RPM
     283           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->lowRpm == true) ? 1 : 0);
     284             : 
     285             :     // Engine was disabled due to loss of power
     286           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)((_pg_user->powerLoss == true) ? 1 : 0) << 7;
     287             : 
     288             :     // Reserved byte
     289           0 :     _pg_byteindex += 2; // close bit field
     290             : 
     291           0 :     *_pg_bytecount = _pg_byteindex;
     292             : 
     293           0 : }// encodeCortex_ErrorBits_t
     294             : 
     295             : /*!
     296             :  * \brief Decode a Cortex_ErrorBits_t from a byte array
     297             :  *
     298             :  * Error bits for the TelemetryStatus packet
     299             :  * \param _pg_data points to the byte array to decoded data from
     300             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     301             :  * \param _pg_user is the data to decode from the byte array
     302             :  * \return 1 if the data are decoded, else 0.
     303             :  */
     304           0 : int decodeCortex_ErrorBits_t(const uint8_t* _pg_data, int* _pg_bytecount, Cortex_ErrorBits_t* _pg_user)
     305             : {
     306           0 :     int _pg_byteindex = *_pg_bytecount;
     307             : 
     308             :     // Critical generator fault - refer to the motor errors packet
     309           0 :     _pg_user->generator = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
     310             : 
     311             :     // Critical error occurred during engine cranking
     312           0 :     _pg_user->cranking = (((_pg_data[_pg_byteindex] >> 6) & 0x1)) ? true : false;
     313             : 
     314             :     // Critical error occurred during rail configuration
     315           0 :     _pg_user->avionicsRail = (((_pg_data[_pg_byteindex] >> 5) & 0x1)) ? true : false;
     316             : 
     317             :     // Critical error occurred during rail configuration
     318           0 :     _pg_user->payloadRail = (((_pg_data[_pg_byteindex] >> 4) & 0x1)) ? true : false;
     319             : 
     320             :     // Critical error occurred during rail configuration
     321           0 :     _pg_user->servoRail = (((_pg_data[_pg_byteindex] >> 3) & 0x1)) ? true : false;
     322             : 
     323             :     // Critical error occurred during rail configuration
     324           0 :     _pg_user->batteryChargerRail = (((_pg_data[_pg_byteindex] >> 2) & 0x1)) ? true : false;
     325             : 
     326             :     // Power map is improperly configured
     327           0 :     _pg_user->powerMap = (((_pg_data[_pg_byteindex] >> 1) & 0x1)) ? true : false;
     328             : 
     329             :     // Engine was disabled due to low RPM
     330           0 :     _pg_user->lowRpm = (((_pg_data[_pg_byteindex]) & 0x1)) ? true : false;
     331             : 
     332             :     // Engine was disabled due to loss of power
     333           0 :     _pg_user->powerLoss = ((_pg_data[_pg_byteindex + 1] >> 7)) ? true : false;
     334             : 
     335             :     // Reserved byte
     336           0 :     _pg_byteindex += 2; // close bit field
     337             : 
     338           0 :     *_pg_bytecount = _pg_byteindex;
     339             : 
     340           0 :     return 1;
     341             : 
     342             : }// decodeCortex_ErrorBits_t
     343             : 
     344             : /*!
     345             :  * \brief Encode a Cortex_TelemetryPackets_t into a byte array
     346             :  *
     347             : 
     348             :  * \param _pg_data points to the byte array to add encoded data to
     349             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     350             :  * \param _pg_user is the data to encode in the byte array
     351             :  */
     352           0 : void encodeCortex_TelemetryPackets_t(uint8_t* _pg_data, int* _pg_bytecount, const Cortex_TelemetryPackets_t* _pg_user)
     353             : {
     354           0 :     int _pg_byteindex = *_pg_bytecount;
     355             : 
     356             :     // Enable TelemetryStatus packet
     357           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->status == true) ? 1 : 0) << 7;
     358             : 
     359             :     // Enable TelemetryGenerator packet
     360           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->generator == true) ? 1 : 0) << 6;
     361             : 
     362             :     // Enable TelemetryBattery packet
     363           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->battery == true) ? 1 : 0) << 5;
     364             : 
     365             :     // Enable TelemetryOutputRail packet
     366           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->outputRail == true) ? 1 : 0) << 4;
     367             : 
     368             :     // Enable TelemetryController packet
     369           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->controller == true) ? 1 : 0) << 3;
     370             : 
     371             :     // Enable TelemetryEngine packet
     372           0 :     _pg_data[_pg_byteindex] |= (uint8_t)((_pg_user->engine == true) ? 1 : 0) << 2;
     373           0 :     _pg_byteindex += 1; // close bit field
     374             : 
     375           0 :     *_pg_bytecount = _pg_byteindex;
     376             : 
     377           0 : }// encodeCortex_TelemetryPackets_t
     378             : 
     379             : /*!
     380             :  * \brief Decode a Cortex_TelemetryPackets_t from a byte array
     381             :  *
     382             : 
     383             :  * \param _pg_data points to the byte array to decoded data from
     384             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     385             :  * \param _pg_user is the data to decode from the byte array
     386             :  * \return 1 if the data are decoded, else 0.
     387             :  */
     388           0 : int decodeCortex_TelemetryPackets_t(const uint8_t* _pg_data, int* _pg_bytecount, Cortex_TelemetryPackets_t* _pg_user)
     389             : {
     390           0 :     int _pg_byteindex = *_pg_bytecount;
     391             : 
     392             :     // Enable TelemetryStatus packet
     393           0 :     _pg_user->status = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
     394             : 
     395             :     // Enable TelemetryGenerator packet
     396           0 :     _pg_user->generator = (((_pg_data[_pg_byteindex] >> 6) & 0x1)) ? true : false;
     397             : 
     398             :     // Enable TelemetryBattery packet
     399           0 :     _pg_user->battery = (((_pg_data[_pg_byteindex] >> 5) & 0x1)) ? true : false;
     400             : 
     401             :     // Enable TelemetryOutputRail packet
     402           0 :     _pg_user->outputRail = (((_pg_data[_pg_byteindex] >> 4) & 0x1)) ? true : false;
     403             : 
     404             :     // Enable TelemetryController packet
     405           0 :     _pg_user->controller = (((_pg_data[_pg_byteindex] >> 3) & 0x1)) ? true : false;
     406             : 
     407             :     // Enable TelemetryEngine packet
     408           0 :     _pg_user->engine = (((_pg_data[_pg_byteindex] >> 2) & 0x1)) ? true : false;
     409           0 :     _pg_byteindex += 1; // close bit field
     410             : 
     411           0 :     *_pg_bytecount = _pg_byteindex;
     412             : 
     413           0 :     return 1;
     414             : 
     415             : }// decodeCortex_TelemetryPackets_t
     416             : 
     417             : /*!
     418             :  * \brief Encode a Cortex_OutputRailSettings_t into a byte array
     419             :  *
     420             : 
     421             :  * \param _pg_data points to the byte array to add encoded data to
     422             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of encoded bytes.
     423             :  * \param _pg_user is the data to encode in the byte array
     424             :  */
     425           0 : void encodeCortex_OutputRailSettings_t(uint8_t* _pg_data, int* _pg_bytecount, const Cortex_OutputRailSettings_t* _pg_user)
     426             : {
     427           0 :     int _pg_byteindex = *_pg_bytecount;
     428           0 :     unsigned int _pg_tempbitfield = 0;
     429             : 
     430             :     // Enable output rail at startup
     431           0 :     _pg_data[_pg_byteindex] = (uint8_t)((_pg_user->enableOnStartup == true) ? 1 : 0) << 7;
     432             : 
     433             :     // Reserved bits
     434             : 
     435             :     // Rail voltage. Invalid values will be clipped.
     436             :     // Range of voltage is 0 to 1023.
     437           0 :     _pg_tempbitfield = (unsigned int)limitMax(_pg_user->voltage, 1023);
     438           0 :     _pg_data[_pg_byteindex + 1] = (uint8_t)_pg_tempbitfield;
     439             : 
     440           0 :     _pg_tempbitfield >>= 8;
     441           0 :     _pg_data[_pg_byteindex] |= (uint8_t)_pg_tempbitfield;
     442           0 :     _pg_byteindex += 2; // close bit field
     443             : 
     444           0 :     *_pg_bytecount = _pg_byteindex;
     445             : 
     446           0 : }// encodeCortex_OutputRailSettings_t
     447             : 
     448             : /*!
     449             :  * \brief Decode a Cortex_OutputRailSettings_t from a byte array
     450             :  *
     451             : 
     452             :  * \param _pg_data points to the byte array to decoded data from
     453             :  * \param _pg_bytecount points to the starting location in the byte array, and will be incremented by the number of bytes decoded
     454             :  * \param _pg_user is the data to decode from the byte array
     455             :  * \return 1 if the data are decoded, else 0.
     456             :  */
     457           0 : int decodeCortex_OutputRailSettings_t(const uint8_t* _pg_data, int* _pg_bytecount, Cortex_OutputRailSettings_t* _pg_user)
     458             : {
     459           0 :     int _pg_byteindex = *_pg_bytecount;
     460           0 :     unsigned int _pg_tempbitfield = 0;
     461             : 
     462             :     // Enable output rail at startup
     463           0 :     _pg_user->enableOnStartup = ((_pg_data[_pg_byteindex] >> 7)) ? true : false;
     464             : 
     465             :     // Reserved bits
     466             : 
     467             :     // Rail voltage. Invalid values will be clipped.
     468             :     // Range of voltage is 0 to 1023.
     469           0 :     _pg_tempbitfield = (_pg_data[_pg_byteindex] & 0x3);
     470             : 
     471           0 :     _pg_tempbitfield <<= 8;
     472           0 :     _pg_tempbitfield |= _pg_data[_pg_byteindex + 1];
     473             : 
     474           0 :     _pg_user->voltage = _pg_tempbitfield;
     475           0 :     _pg_byteindex += 2; // close bit field
     476             : 
     477           0 :     *_pg_bytecount = _pg_byteindex;
     478             : 
     479           0 :     return 1;
     480             : 
     481             : }// decodeCortex_OutputRailSettings_t
     482             : 
     483             : // end of CortexDefines.c

Generated by: LCOV version 1.14