foxBMS  1.1.0
The foxBMS Battery Management System API Documentation
can_cbs_tx_minmax.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file can_cbs_tx_minmax.c
44  * @author foxBMS Team
45  * @date 2021-04-20 (date of creation)
46  * @updated 2021-07-21 (date of last update)
47  * @ingroup DRIVER
48  * @prefix CAN
49  *
50  * @brief CAN driver Tx callback implementation
51  * @details CAN Tx callback for min/max values
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "bms.h"
56 #include "can_cbs.h"
57 #include "can_helper.h"
58 
59 /*========== Macros and Definitions =========================================*/
60 
61 /*========== Static Constant and Variable Definitions =======================*/
62 
63 /*========== Extern Constant and Variable Definitions =======================*/
64 
65 /*========== Static Function Prototypes =====================================*/
66 
67 /*========== Static Function Implementations ================================*/
68 
69 /*========== Extern Function Implementations ================================*/
71  uint32_t id,
72  uint8_t dlc,
73  CAN_ENDIANNESS_e endianness,
74  uint8_t *pCanData,
75  uint8_t *pMuxId,
76  const CAN_SHIM_s *const kpkCanShim) {
77  /* pMuxId is not used here, therefore has to be NULL_PTR */
78  FAS_ASSERT(pMuxId == NULL_PTR);
79 
80  FAS_ASSERT(id < CAN_MAX_11BIT_ID); /* Currently standard ID, 11 bit */
81  FAS_ASSERT(dlc <= CAN_MAX_DLC); /* Currently max 8 bytes in a CAN frame */
82  FAS_ASSERT(pCanData != NULL_PTR);
83  FAS_ASSERT(kpkCanShim != NULL_PTR);
84  uint64_t message = 0;
85  float signalData = 0.0f;
86  float offset = 0.0f;
87  float factor = 0.0f;
88  uint64_t data = 0u;
89 
90  DATA_READ_DATA(kpkCanShim->pTableMinMax);
91 
92  int16_t packMaximumVoltage_mV = INT16_MIN;
93  int16_t packMinimumVoltage_mV = INT16_MAX;
94  int16_t packMaximumTemperature_ddegC = INT16_MIN;
95  int16_t packMinimumTemperature_ddegC = INT16_MAX;
96 
97  if (0u == BMS_GetNumberOfConnectedStrings()) {
98  /* Calculate min/max values of complete pack if all slice switches are open */
99  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
100  if (kpkCanShim->pTableMinMax->maximumCellVoltage_mV[stringNumber] >= packMaximumVoltage_mV) {
101  packMaximumVoltage_mV = kpkCanShim->pTableMinMax->maximumCellVoltage_mV[stringNumber];
102  }
103  if (kpkCanShim->pTableMinMax->minimumCellVoltage_mV[stringNumber] <= packMinimumVoltage_mV) {
104  packMinimumVoltage_mV = kpkCanShim->pTableMinMax->minimumCellVoltage_mV[stringNumber];
105  }
106  if (kpkCanShim->pTableMinMax->maximumTemperature_ddegC[stringNumber] >= packMaximumTemperature_ddegC) {
107  packMaximumTemperature_ddegC = kpkCanShim->pTableMinMax->maximumTemperature_ddegC[stringNumber];
108  }
109  if (kpkCanShim->pTableMinMax->minimumTemperature_ddegC[stringNumber] <= packMinimumTemperature_ddegC) {
110  packMinimumTemperature_ddegC = kpkCanShim->pTableMinMax->minimumTemperature_ddegC[stringNumber];
111  }
112  }
113  } else {
114  /* Calculate min/max values of connected slices */
115  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
116  if (true == BMS_IsStringClosed(stringNumber)) {
117  if (kpkCanShim->pTableMinMax->maximumCellVoltage_mV[stringNumber] >= packMaximumVoltage_mV) {
118  packMaximumVoltage_mV = kpkCanShim->pTableMinMax->maximumCellVoltage_mV[stringNumber];
119  }
120  if (kpkCanShim->pTableMinMax->minimumCellVoltage_mV[stringNumber] <= packMinimumVoltage_mV) {
121  packMinimumVoltage_mV = kpkCanShim->pTableMinMax->minimumCellVoltage_mV[stringNumber];
122  }
123  if (kpkCanShim->pTableMinMax->maximumTemperature_ddegC[stringNumber] >= packMaximumTemperature_ddegC) {
124  packMaximumTemperature_ddegC = kpkCanShim->pTableMinMax->maximumTemperature_ddegC[stringNumber];
125  }
126  if (kpkCanShim->pTableMinMax->minimumTemperature_ddegC[stringNumber] <= packMinimumTemperature_ddegC) {
127  packMinimumTemperature_ddegC = kpkCanShim->pTableMinMax->minimumTemperature_ddegC[stringNumber];
128  }
129  }
130  }
131  }
132 
133  /* AXIVION Disable Style Generic-NoMagicNumbers: Signal data defined in .dbc file. */
134  /* Minimum cell voltage */
135  signalData = (float)packMinimumVoltage_mV;
136  offset = 0.0f;
137  factor = 1.0f;
138  signalData = (signalData + offset) * factor;
139  data = (int64_t)signalData;
140  /* set data in CAN frame */
141  CAN_TxSetMessageDataWithSignalData(&message, 10u, 13u, data, endianness);
142 
143  /* Maximum cell voltage */
144  signalData = (float)packMaximumVoltage_mV;
145  offset = 0.0f;
146  factor = 1.0f;
147  signalData = (signalData + offset) * factor;
148  data = (int64_t)signalData;
149  /* set data in CAN frame */
150  CAN_TxSetMessageDataWithSignalData(&message, 7u, 13u, data, endianness);
151 
152  /* Minimum cell temperature */
153  signalData = (float)packMinimumTemperature_ddegC;
154  offset = 0.0f;
155  factor = 0.1f; /* convert ddegC to degC */
156  signalData = (signalData + offset) * factor;
157  data = (int64_t)signalData;
158  /* set data in CAN frame */
159  CAN_TxSetMessageDataWithSignalData(&message, 63u, 8u, data, endianness);
160 
161  /* Maximum cell temperature */
162  signalData = (float)packMaximumTemperature_ddegC;
163  offset = 0.0f;
164  factor = 0.1f; /* convert ddegC to degC */
165  signalData = (signalData + offset) * factor;
166  data = (int64_t)signalData;
167  /* set data in CAN frame */
168  CAN_TxSetMessageDataWithSignalData(&message, 55u, 8u, data, endianness);
169  /* AXIVION Enable Style Generic-NoMagicNumbers: */
170 
171  /* now copy data in the buffer that will be used to send data */
172  CAN_TxSetCanDataWithMessageData(message, pCanData, endianness);
173 
174  return 0;
175 }
176 
178  uint32_t id,
179  uint8_t dlc,
180  CAN_ENDIANNESS_e endianness,
181  uint8_t *pCanData,
182  uint8_t *pMuxId,
183  const CAN_SHIM_s *const kpkCanShim) {
184  FAS_ASSERT(id < CAN_MAX_11BIT_ID); /* Currently standard ID, 11 bit */
185  FAS_ASSERT(dlc <= CAN_MAX_DLC); /* Currently max 8 bytes in a CAN frame */
186  FAS_ASSERT(pCanData != NULL_PTR);
187  FAS_ASSERT(pMuxId != NULL_PTR);
188  FAS_ASSERT(*pMuxId < BS_NR_OF_STRINGS);
189  FAS_ASSERT(kpkCanShim != NULL_PTR);
190  uint64_t message = 0;
191 
192  /* STUB IMPLEMENTATION */
193 
194  /* now copy data in the buffer that will be use to send data */
195  CAN_TxSetCanDataWithMessageData(message, pCanData, endianness);
196 
197  return 0;
198 }
199 
200 /*========== Externalized Static Function Implementations (Unit Test) =======*/
201 #ifdef UNITY_UNIT_TEST
202 
203 #endif
#define BS_NR_OF_STRINGS
uint8_t BMS_GetNumberOfConnectedStrings(void)
Returns number of connected strings.
Definition: bms.c:1317
bool BMS_IsStringClosed(uint8_t stringNumber)
Returns string state (closed or open)
Definition: bms.c:1299
bms driver header
CAN callbacks header.
uint32_t CAN_TxMinimumMaximumValues(uint32_t id, uint8_t dlc, CAN_ENDIANNESS_e endianness, uint8_t *pCanData, uint8_t *pMuxId, const CAN_SHIM_s *const kpkCanShim)
can tx callback function for min/max values
uint32_t CAN_TxStringMinimumMaximumValues(uint32_t id, uint8_t dlc, CAN_ENDIANNESS_e endianness, uint8_t *pCanData, uint8_t *pMuxId, const CAN_SHIM_s *const kpkCanShim)
can tx callback function for string minimum and maximum values
#define CAN_MAX_11BIT_ID
Definition: can_cfg.h:68
enum CAN_ENDIANNESS CAN_ENDIANNESS_e
#define CAN_MAX_DLC
Definition: can_cfg.h:70
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....
Definition: can_helper.c:166
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 t...
Definition: can_helper.c:205
Headers for the helper functions for the CAN module.
#define DATA_READ_DATA(...)
Definition: database.h:76
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
DATA_BLOCK_MIN_MAX_s * pTableMinMax
Definition: can_cfg.h:298
int16_t maximumTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:179
int16_t minimumTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:176
int16_t maximumCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:168
int16_t minimumCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:166