foxBMS
1.6.0
The foxBMS Battery Management System API Documentation
|
Helper functions for the CAN module. More...
#include "can_helper.h"
#include "database.h"
#include "foxmath.h"
#include <math.h>
#include <stdint.h>
Go to the source code of this file.
Macros | |
#define | CAN_SIGNAL_MAX_SIZE (64u) |
#define | CAN_MESSAGE_BIT_MASK_ONE_BYTE (0xFFu) |
#define | CAN_BYTE_LENGTH (8u) |
Functions | |
static uint64_t | CAN_ConvertBitStartBigEndian (uint64_t bitStart, uint64_t bitLength) |
Convert bit start in big endian case. In the big endian case for CAN, the bit start is set to the MSB and the bit numbering is not directly usable. This functions converts the bit start to set it to the LSB of the signal and with the usual bit numbering. More... | |
void | CAN_TxPrepareSignalData (float_t *pSignal, CAN_SIGNAL_TYPE_s signalProperties) |
Prepare signal data. This function takes the signal data and applies factor, applies offset and compares with signal minimum and maximum values. More... | |
void | CAN_RxConvertRawSignalData (float_t *pSignalConverted, float_t signalRaw, CAN_SIGNAL_TYPE_s signalProperties) |
Convert raw signal data. This function takes the raw signal data and applies offset and factor to convert the raw value. More... | |
void | CAN_TxSetMessageDataWithSignalData (uint64_t *pMessage, uint64_t bitStart, uint8_t bitLength, uint64_t canSignal, CAN_ENDIANNESS_e endianness) |
Puts CAN signal data in a 64-bit variable. This function is used to compose a 64-bit CAN message. It takes signal data, signal bit start, signal bit length and puts the data in the 64-bit variable. More... | |
void | CAN_TxSetCanDataWithMessageData (uint64_t message, uint8_t *pCanData, CAN_ENDIANNESS_e endianness) |
Copy CAN data from a 64-bit variable to 8 bytes. This function is used to copy a 64-bit CAN message to 8 bytes. More... | |
void | CAN_RxGetSignalDataFromMessageData (uint64_t message, uint64_t bitStart, uint8_t bitLength, uint64_t *pCanSignal, CAN_ENDIANNESS_e endianness) |
Gets CAN signal data from a 64-bit variable. This function is used to get signal data from a 64-bit CAN message. It takes signal bit start, signal bit length and extract signal data from the the 64-bit variable. More... | |
void | CAN_RxGetMessageDataFromCanData (uint64_t *pMessage, const uint8_t *const kpkCanData, CAN_ENDIANNESS_e endianness) |
Copy CAN data from 8 bytes to a 64-bit variable. More... | |
uint8_t | CAN_ConvertBooleanToInteger (bool input) |
Transform a bool to a bit (set if true) More... | |
Variables | |
static const uint8_t | can_bigEndianTable [CAN_SIGNAL_MAX_SIZE] |
Helper functions for the CAN module.
SPDX-License-Identifier: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:
Definition in file can_helper.c.
#define CAN_BYTE_LENGTH (8u) |
length of one CAN byte in bit
Definition at line 73 of file can_helper.c.
#define CAN_MESSAGE_BIT_MASK_ONE_BYTE (0xFFu) |
bitmask for extraction of one byte
Definition at line 70 of file can_helper.c.
#define CAN_SIGNAL_MAX_SIZE (64u) |
Plausibility checking can signals lengths
Definition at line 67 of file can_helper.c.
|
static |
Convert bit start in big endian case. In the big endian case for CAN, the bit start is set to the MSB and the bit numbering is not directly usable. This functions converts the bit start to set it to the LSB of the signal and with the usual bit numbering.
bitStart | bit start in big endian format |
bitLength | signal length |
Example: big endian, bitStart = 53, bitLength = 13 For big endian, bitStart corresponds to MSB. First convert |07 06 05 04 03 02 01 00| to |63 62 61 60 59 58 57 56| |15 14 13 12 11 10 09 08| |55 54 53 52 51 50 49 48| |23 22 21 20 19 18 17 16| |47 46 45 44 43 42 41 40| |31 30 29 28 27 26 25 24| |39 38 37 36 35 34 33 32| |39 38 37 36 35 34 33 32| |31 30 29 28 27 26 25 24| |47 46 45 44 43 42 41 40| |23 22 21 20 19 18 17 16| |55 54 53 52 51 50 49 48| |15 14 13 12 11 10 09 08| |63 62 61 60 59 58 57 56| |07 06 05 04 03 02 01 00| to get MSB position in the usual bit representation (from 0 as LSB to 63 as MSB). In the example, 53 must be converted to 13.
Usual bit position of MSB of signal is now available. Now subtract signal length to get LSB position. In the example, bitStart is converted from 53 to 0 for the length of 13 bits. This corresponds to the usual data access in the little endian case, from bit 0 to bit 12, where bitStart corresponds to LSB.
Definition at line 101 of file can_helper.c.
uint8_t CAN_ConvertBooleanToInteger | ( | bool | input | ) |
Transform a bool to a bit (set if true)
[in] | input | input boolean (true will become 1u) |
Definition at line 342 of file can_helper.c.
void CAN_RxConvertRawSignalData | ( | float_t * | pSignalConverted, |
float_t | signalRaw, | ||
CAN_SIGNAL_TYPE_s | signalProperties | ||
) |
Convert raw signal data. This function takes the raw signal data and applies offset and factor to convert the raw value.
[out] | pSignalConverted | converted signal data |
[in] | signalRaw | raw signal data |
[in] | signalProperties | signal properties (factor, offset, min, max) |
Definition at line 164 of file can_helper.c.
void CAN_RxGetMessageDataFromCanData | ( | uint64_t * | pMessage, |
const uint8_t *const | kpkCanData, | ||
CAN_ENDIANNESS_e | endianness | ||
) |
Copy CAN data from 8 bytes to a 64-bit variable.
This function is used to copy data from a 64-bit variable to 8 bytes.
[in] | pMessage | 64-bit where the data is copied |
[out] | kpkCanData | 8 bytes containing the data |
[in] | endianness | big or little endianness of data |
Definition at line 295 of file can_helper.c.
void CAN_RxGetSignalDataFromMessageData | ( | uint64_t | message, |
uint64_t | bitStart, | ||
uint8_t | bitLength, | ||
uint64_t * | pCanSignal, | ||
CAN_ENDIANNESS_e | endianness | ||
) |
Gets CAN signal data from a 64-bit variable. This function is used to get signal data from a 64-bit CAN message. It takes signal bit start, signal bit length and extract signal data from the the 64-bit variable.
[in] | message | 64-bit variable containing the CAN data |
[in] | bitStart | starting bit were the signal data must be put |
[in] | bitLength | length of the signal data to be put in CAN message |
[out] | pCanSignal | signal data to be retrieved from message |
[in] | endianness | big or little endianness of data |
Definition at line 255 of file can_helper.c.
void CAN_TxPrepareSignalData | ( | float_t * | pSignal, |
CAN_SIGNAL_TYPE_s | signalProperties | ||
) |
Prepare signal data. This function takes the signal data and applies factor, applies offset and compares with signal minimum and maximum values.
[in,out] | pSignal | signal data |
[in] | signalProperties | signal properties (factor, offset, min, max) |
Definition at line 145 of file can_helper.c.
void CAN_TxSetCanDataWithMessageData | ( | uint64_t | message, |
uint8_t * | pCanData, | ||
CAN_ENDIANNESS_e | endianness | ||
) |
Copy CAN data from a 64-bit variable to 8 bytes. This function is used to copy a 64-bit CAN message to 8 bytes.
[in] | message | 64-bit variable containing the CAN data |
[out] | pCanData | 8 bytes where the data is copied |
[in] | endianness | big or little endianness of data |
Definition at line 212 of file can_helper.c.
void CAN_TxSetMessageDataWithSignalData | ( | uint64_t * | pMessage, |
uint64_t | bitStart, | ||
uint8_t | bitLength, | ||
uint64_t | canSignal, | ||
CAN_ENDIANNESS_e | endianness | ||
) |
Puts CAN signal data in a 64-bit variable. This function is used to compose a 64-bit CAN message. It takes signal data, signal bit start, signal bit length and puts the data in the 64-bit variable.
[out] | pMessage | 64-bit variable containing the CAN data |
[in] | bitStart | starting bit were the signal data must be put |
[in] | bitLength | length of the signal data to be put in CAN message |
[in] | canSignal | signal data to be put in message |
[in] | endianness | big or little endianness of data |
Definition at line 173 of file can_helper.c.
|
static |
To convert big endian startbit to usual little endian representation (from 0 as LSB to 63 as MSB)
Definition at line 78 of file can_helper.c.