Updated structure packages for CAN1
This commit is contained in:
@@ -62,78 +62,103 @@ bool get_dummy_soc(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void transmitCan1Packet() {
|
void transmitCan1Packet() {
|
||||||
if ((TIM_Clock - can1_transmit_clock) < 1000) {
|
if ((TIM_Clock - can1_transmit_clock) < 500)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t data1[8] = {0x45};
|
|
||||||
CAN_Transmit(300, data1, 8, &hcan1);
|
|
||||||
can1_transmit_clock = TIM_Clock;
|
can1_transmit_clock = TIM_Clock;
|
||||||
return;
|
|
||||||
|
|
||||||
CAN_TxHeaderTypeDef header;
|
// SOC and SOH (TODO)
|
||||||
header.IDE = CAN_ID_STD;
|
can1_buf.id = 0x101;
|
||||||
header.RTR = CAN_RTR_DATA;
|
can1_buf.len = 8;
|
||||||
header.StdId = 0x444;
|
memcpy(can1_buf.msg, &packState.SoC, sizeof(packState.SoC));
|
||||||
header.DLC = 1;
|
memcpy(can1_buf.msg + 4, &packState.SoCCapacityAh, sizeof(packState.SoCCapacityAh));
|
||||||
|
RingBuf_CellPut(&can1_buf, &can1_ring);
|
||||||
|
|
||||||
uint8_t data[32] = {};
|
// pack voltage and current
|
||||||
uint32_t mailbox = 0;
|
can1_buf.id = 0x102;
|
||||||
|
can1_buf.len = 8;
|
||||||
|
memcpy(can1_buf.msg, &packState.packVoltage, sizeof(packState.packVoltage));
|
||||||
|
memcpy(can1_buf.msg + 4, &packState.packCurrent, sizeof(packState.packCurrent));
|
||||||
|
RingBuf_CellPut(&can1_buf, &can1_ring);
|
||||||
|
|
||||||
// sending SOC, SOH and number of cells
|
// inputs and outputs state
|
||||||
uint16_t id = 0x101;
|
can1_buf.id = 0x103;
|
||||||
memcpy(data, &id, sizeof(id));
|
can1_buf.len = 8;
|
||||||
memcpy(data + 2, &packState.SoC, sizeof(packState.SoC));
|
|
||||||
memcpy(data + 6, &packState.SoCCapacityAh, sizeof(packState.SoCCapacityAh));
|
|
||||||
memcpy(data + 10, &generalConfig->noOfCellsSeries, sizeof(generalConfig->noOfCellsSeries));
|
|
||||||
header.DLC = 11;
|
|
||||||
HAL_CAN_AddTxMessage(&hcan1, &header, data, &mailbox);
|
|
||||||
|
|
||||||
// sending charge current, discharge current // TODO
|
const uint8_t input0 = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_7);
|
||||||
id = 0x102;
|
const uint8_t input1 = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_8);
|
||||||
memcpy(data, &id, sizeof(id));
|
const uint8_t input2 = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_9);
|
||||||
memcpy(data + 2, &packState.packCurrent, sizeof(packState.packCurrent));
|
|
||||||
memcpy(data + 6, &packState.loCurrentLoadCurrent, sizeof(packState.loCurrentLoadCurrent));
|
|
||||||
header.DLC = 10;
|
|
||||||
HAL_CAN_AddTxMessage(&hcan1, &header, data, &mailbox);
|
|
||||||
|
|
||||||
// sending BMS state, input state, output state // TODO
|
const uint8_t output0 = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_0);
|
||||||
id = 0x103;
|
const uint8_t output1 = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_1);
|
||||||
memcpy(data, &id, sizeof(id));
|
const uint8_t output2 = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_2);
|
||||||
memcpy(data + 2, &packState.cellVoltageLow, sizeof(packState.cellVoltageLow));
|
const uint8_t output3 = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_3);
|
||||||
memcpy(data + 6, &packState.cellVoltageAverage, sizeof(packState.cellVoltageAverage));
|
|
||||||
memcpy(data + 10, &packState.cellVoltageHigh, sizeof(packState.cellVoltageHigh));
|
|
||||||
header.DLC = 12;
|
|
||||||
HAL_CAN_AddTxMessage(&hcan1, &header, data, &mailbox);
|
|
||||||
|
|
||||||
// sending cell voltages
|
memcpy(can1_buf.msg + 0, &input0, sizeof(input0));
|
||||||
id = 0x200;
|
memcpy(can1_buf.msg + 1, &input1, sizeof(input1));
|
||||||
for (int cellPointer = 0;
|
memcpy(can1_buf.msg + 2, &input2, sizeof(input2));
|
||||||
cellPointer < generalConfig->noOfCellsSeries * generalConfig->noOfParallelModules; ++cellPointer) {
|
|
||||||
++id;
|
memcpy(can1_buf.msg + 4, &output0, sizeof(output0));
|
||||||
memcpy(data, &id, sizeof(id));
|
memcpy(can1_buf.msg + 5, &output1, sizeof(output1));
|
||||||
float voltage = 0;
|
memcpy(can1_buf.msg + 6, &output2, sizeof(output2));
|
||||||
if (packState.cellVoltagesIndividual[cellPointer].cellBleedActive)
|
memcpy(can1_buf.msg + 7, &output3, sizeof(output3));
|
||||||
voltage = packState.cellVoltagesIndividual[cellPointer].cellVoltage * -1000;
|
|
||||||
else
|
RingBuf_CellPut(&can1_buf, &can1_ring);
|
||||||
voltage = packState.cellVoltagesIndividual[cellPointer].cellVoltage * 1000;
|
|
||||||
memcpy(data + 2, &voltage, sizeof(voltage));
|
// number of cells and temperature sensors
|
||||||
header.DLC = 6;
|
can1_buf.id = 0x104;
|
||||||
HAL_CAN_AddTxMessage(&hcan1, &header, data, &mailbox);
|
can1_buf.len = 8;
|
||||||
|
const uint32_t numberOfCells = generalConfig->noOfCellsSeries * generalConfig->noOfParallelModules;
|
||||||
|
const uint32_t numberOfTemperatures = generalConfig->cellMonitorICCount * generalConfig->noOfTempSensorPerModule;
|
||||||
|
memcpy(can1_buf.msg, &numberOfCells, sizeof(numberOfCells));
|
||||||
|
memcpy(can1_buf.msg + 4, &numberOfTemperatures, sizeof(numberOfTemperatures));
|
||||||
|
RingBuf_CellPut(&can1_buf, &can1_ring);
|
||||||
|
|
||||||
|
// cell voltages
|
||||||
|
can1_buf.id = 0x201;
|
||||||
|
can1_buf.len = 8;
|
||||||
|
|
||||||
|
for (int i = 0; i < numberOfCells; i += 2)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 2; ++j)
|
||||||
|
{
|
||||||
|
const int index = i + j;
|
||||||
|
float voltage = 0;
|
||||||
|
if (packState.cellVoltagesIndividual[index].cellBleedActive)
|
||||||
|
voltage = packState.cellVoltagesIndividual[index].cellVoltage * -1000;
|
||||||
|
else
|
||||||
|
voltage = packState.cellVoltagesIndividual[index].cellVoltage * 1000;
|
||||||
|
|
||||||
|
memcpy(can1_buf.msg + j * 4, &voltage, sizeof(voltage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i + 2 > numberOfCells)
|
||||||
|
can1_buf.len = 4;
|
||||||
|
|
||||||
|
RingBuf_CellPut(&can1_buf, &can1_ring);
|
||||||
|
can1_buf.id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sending temperatures
|
// temperatures
|
||||||
id = 0x300;
|
can1_buf.id = 0x301;
|
||||||
for (int sensorPointer = 0; sensorPointer < NoOfTempSensors; ++sensorPointer) {
|
can1_buf.len = 8;
|
||||||
++id;
|
|
||||||
memcpy(data, &id, sizeof(id));
|
|
||||||
float temperature = packState.temperatures[sensorPointer];
|
|
||||||
memcpy(data + 2, &temperature, sizeof(temperature));
|
|
||||||
header.DLC = 6;
|
|
||||||
HAL_CAN_AddTxMessage(&hcan1, &header, data, &mailbox);
|
|
||||||
}
|
|
||||||
|
|
||||||
can1_transmit_clock = TIM_Clock;
|
for (int i = 0; i < numberOfTemperatures; i += 2)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 2; ++j)
|
||||||
|
{
|
||||||
|
float temperature = packState.temperatures[i + j];
|
||||||
|
memcpy(can1_buf.msg + j * 4, &temperature, sizeof(temperature));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i + 2 > numberOfTemperatures)
|
||||||
|
can1_buf.len = 4;
|
||||||
|
|
||||||
|
RingBuf_CellPut(&can1_buf, &can1_ring);
|
||||||
|
can1_buf.id++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getIndexBySoc() {
|
int getIndexBySoc() {
|
||||||
|
|||||||
Reference in New Issue
Block a user