CAN Packet fix, CAN benchmark

This commit is contained in:
Dmitriy Semenov
2023-04-02 01:22:45 +03:00
parent 51b12ac970
commit 389d3d23b8
4 changed files with 50 additions and 19 deletions

View File

@@ -372,6 +372,8 @@ void usbTIM(uint8_t OnOff) {
}
}
u8_t TestData[8] = {1,2,3,4,5,6,7,8};
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM2)
@@ -381,15 +383,19 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
}
else if (htim->Instance == TIM3)
{
CAN_TransmitRTR(0x500, 8, &hcan2);
if (!(TIM3_Clock % 10)){
CAN_TransmitRTR(0x500, 8, &hcan2);
}
if (TIM3_Clock % 2)
{
transmitCanPacketFromQueue(&can1_transmit_queue, &can1_transmit_queue_size, &hcan1);
// transmitCanPacketFromQueue(&can1_transmit_queue, &can1_transmit_queue_size, &hcan1);
}
else
if (!(TIM3_Clock % 3))
{
transmitCanPacketFromQueue(&can2_transmit_queue, &can2_transmit_queue_size, &hcan2);
CAN_Transmit(0x501, TestData, 8, &hcan2);
// transmitCanPacketFromQueue(&can2_transmit_queue, &can2_transmit_queue_size, &hcan2);
}
TIM3_Clock++;
@@ -1302,19 +1308,14 @@ void transmitCan2Packet()
memcpy(buffer + 4, &endFaultVoltage, sizeof(endFaultVoltage));
addCanPacketToQueue(0x503, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
// sending charge starting and ending command
// sending charge start current
float chargeStartingCurrent = 15; // TODO move to generalConfig
float chargeEndingCurrent = 5; // TODO move to generalConfig
u32_t chargeStartingCurrentInterval = 20; // in seconds TODO move to generalConfig
memcpy(buffer, &chargeStartingCurrent, sizeof(chargeStartingCurrent));
memcpy(buffer + 4, &chargeEndingCurrent, sizeof(chargeEndingCurrent));
addCanPacketToQueue(0x504, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
// sending charge permission, charge ending, charge/discharge state and table current command
const uint8_t chargeAllowed = packState.chargeAllowed ? 0xFF : 0x00;
const uint8_t chargeEnding = packState.SoC > 95 ? 0xFF : 0x00;
const uint8_t chargeSwitchState = charge_switch_state ? 0xFF : 0x00;
memcpy(buffer + 4, &chargeStartingCurrentInterval, sizeof(chargeStartingCurrentInterval));
addCanPacketToQueue(0x504, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
// sending table current and end-of-charge current command
const int socIndex = getIndexBySoc();
const int temperatureIndex = getIndexByTemperature();
float tableCurrent = 0;
@@ -1326,16 +1327,25 @@ void transmitCan2Packet()
tableCurrent = pureCurrent ? tableValue : generalConfig->batteryCapacity * tableValue;
}
float chargeEndingCurrent = 5; // TODO move to generalConfig
memcpy(buffer + 0, &tableCurrent, sizeof(tableCurrent));
memcpy(buffer + 4, &chargeEndingCurrent, sizeof(chargeEndingCurrent));
addCanPacketToQueue(0x505, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
// sending charge permission, charge ending, charge/discharge state command
const uint8_t chargeAllowed = packState.chargeAllowed ? 0xFF : 0x00;
const uint8_t chargeEnding = packState.SoC > 95 ? 0xFF : 0x00;
const uint8_t chargeSwitchState = charge_switch_state ? 0xFF : 0x00;
memset(buffer, '\0', sizeof(buffer));
memcpy(buffer + 0, &chargeAllowed, sizeof(chargeAllowed));
memcpy(buffer + 1, &chargeEnding, sizeof(chargeEnding));
memcpy(buffer + 2, &chargeSwitchState, sizeof(chargeSwitchState));
memcpy(buffer + 4, &tableCurrent, sizeof(tableCurrent));
addCanPacketToQueue(0x505, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
addCanPacketToQueue(0x506, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
}
void addCanPacketToQueue(uint16_t id, uint8_t* data, uint8_t** queue, uint16_t* queueSize)
{
return;
*queueSize += 10;
*queue = (uint8_t*)realloc(*queue, *queueSize);