Changed CAN dynamic buffer to static one
This commit is contained in:
@@ -21,8 +21,8 @@
|
|||||||
//#define FW_REAL_VERSION "V1.3"
|
//#define FW_REAL_VERSION "V1.3"
|
||||||
|
|
||||||
#define FW_VERSION_MAJOR 1
|
#define FW_VERSION_MAJOR 1
|
||||||
#define FW_VERSION_MINOR 4
|
#define FW_VERSION_MINOR 5
|
||||||
#define FW_REAL_VERSION "V1.4"
|
#define FW_REAL_VERSION "V1.5"
|
||||||
|
|
||||||
// UUID
|
// UUID
|
||||||
#define STM32_UUID ((uint32_t*)0x1FFFF7E8)
|
#define STM32_UUID ((uint32_t*)0x1FFFF7E8)
|
||||||
|
|||||||
@@ -282,8 +282,8 @@ uint64_t shunt_charging_contractor_clock = 0;
|
|||||||
uint64_t can1_transmit_clock = 0;
|
uint64_t can1_transmit_clock = 0;
|
||||||
uint64_t can2_transmit_clock = 0;
|
uint64_t can2_transmit_clock = 0;
|
||||||
|
|
||||||
uint8_t* can1_transmit_queue = 0;
|
uint8_t can1_transmit_queue[500];
|
||||||
uint8_t* can2_transmit_queue = 0;
|
uint8_t can2_transmit_queue[100];
|
||||||
|
|
||||||
uint16_t can1_transmit_queue_size = 0;
|
uint16_t can1_transmit_queue_size = 0;
|
||||||
uint16_t can2_transmit_queue_size = 0;
|
uint16_t can2_transmit_queue_size = 0;
|
||||||
@@ -315,8 +315,8 @@ void Save_data_to_Backup();
|
|||||||
void Restore_shutdown_data();
|
void Restore_shutdown_data();
|
||||||
void updateLimitsFromMem();
|
void updateLimitsFromMem();
|
||||||
|
|
||||||
void addCanPacketToQueue(uint16_t id, uint8_t* data, uint8_t** queue, uint16_t* queueSize);
|
void addCanPacketToQueue(uint16_t id, uint8_t* data, uint8_t* queue, uint16_t* queueSize);
|
||||||
void transmitCanPacketFromQueue(uint8_t** queue, uint16_t* queueSize, CAN_HandleTypeDef* hcan);
|
void transmitCanPacketFromQueue(uint8_t* queue, uint16_t* queueSize, CAN_HandleTypeDef* hcan);
|
||||||
|
|
||||||
void modem_init();
|
void modem_init();
|
||||||
|
|
||||||
@@ -383,19 +383,17 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|||||||
}
|
}
|
||||||
else if (htim->Instance == TIM3)
|
else if (htim->Instance == TIM3)
|
||||||
{
|
{
|
||||||
if (!(TIM3_Clock % 10)){
|
if (TIM3_Clock % 3 == 0)
|
||||||
CAN_TransmitRTR(0x500, 8, &hcan2);
|
{
|
||||||
|
//transmitCanPacketFromQueue(can1_transmit_queue, &can1_transmit_queue_size, &hcan1);
|
||||||
}
|
}
|
||||||
|
else if (TIM3_Clock % 3 == 1)
|
||||||
|
{
|
||||||
if (TIM3_Clock % 2)
|
//transmitCanPacketFromQueue(can2_transmit_queue, &can2_transmit_queue_size, &hcan2);
|
||||||
|
}
|
||||||
|
else if (TIM3_Clock % 10 == 0)
|
||||||
{
|
{
|
||||||
// transmitCanPacketFromQueue(&can1_transmit_queue, &can1_transmit_queue_size, &hcan1);
|
CAN_TransmitRTR(0x500, 8, &hcan2);
|
||||||
}
|
|
||||||
if (!(TIM3_Clock % 3))
|
|
||||||
{
|
|
||||||
CAN_Transmit(0x501, TestData, 8, &hcan2);
|
|
||||||
// transmitCanPacketFromQueue(&can2_transmit_queue, &can2_transmit_queue_size, &hcan2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TIM3_Clock++;
|
TIM3_Clock++;
|
||||||
@@ -1187,7 +1185,7 @@ void transmitCan1Packet()
|
|||||||
int getIndexBySoc()
|
int getIndexBySoc()
|
||||||
{
|
{
|
||||||
const float soc = packState.SoC;
|
const float soc = packState.SoC;
|
||||||
if (soc == 0)
|
if (soc <= 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1227,7 +1225,7 @@ int getIndexBySoc()
|
|||||||
{
|
{
|
||||||
return 9;
|
return 9;
|
||||||
}
|
}
|
||||||
else if (soc <= 100 && soc > 95)
|
else if (soc > 95)
|
||||||
{
|
{
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
@@ -1238,7 +1236,7 @@ int getIndexBySoc()
|
|||||||
int getIndexByTemperature()
|
int getIndexByTemperature()
|
||||||
{
|
{
|
||||||
const float temp = packState.tempBatteryAverage;
|
const float temp = packState.tempBatteryAverage;
|
||||||
if (temp > 0)
|
if (temp < 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1292,28 +1290,28 @@ void transmitCan2Packet()
|
|||||||
// sending common current and voltage command
|
// sending common current and voltage command
|
||||||
memcpy(buffer, &packState.packCurrent, sizeof(packState.packCurrent));
|
memcpy(buffer, &packState.packCurrent, sizeof(packState.packCurrent));
|
||||||
memcpy(buffer + 4, &packState.packVoltage, sizeof(packState.packVoltage));
|
memcpy(buffer + 4, &packState.packVoltage, sizeof(packState.packVoltage));
|
||||||
addCanPacketToQueue(0x501, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
|
addCanPacketToQueue(0x501, buffer, can2_transmit_queue, &can2_transmit_queue_size);
|
||||||
|
|
||||||
// sending charge voltages (start, end) command
|
// sending charge voltages (start, end) command
|
||||||
const float startVoltage = generalConfig->cellHardUnderVoltage * generalConfig->noOfCellsSeries;
|
const float startVoltage = generalConfig->cellHardUnderVoltage * generalConfig->noOfCellsSeries;
|
||||||
const float endVoltage = generalConfig->cellHardOverVoltage * generalConfig->noOfCellsSeries;
|
const float endVoltage = generalConfig->cellHardOverVoltage * generalConfig->noOfCellsSeries;
|
||||||
memcpy(buffer, &startVoltage, sizeof(startVoltage));
|
memcpy(buffer, &startVoltage, sizeof(startVoltage));
|
||||||
memcpy(buffer + 4, &endVoltage, sizeof(endVoltage));
|
memcpy(buffer + 4, &endVoltage, sizeof(endVoltage));
|
||||||
addCanPacketToQueue(0x502, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
|
addCanPacketToQueue(0x502, buffer, can2_transmit_queue, &can2_transmit_queue_size);
|
||||||
|
|
||||||
// sending fault voltages (under, over) command
|
// sending fault voltages (under, over) command
|
||||||
const float startFaultVoltage = generalConfig->cellLCSoftUnderVoltage * generalConfig->noOfCellsSeries;
|
const float startFaultVoltage = generalConfig->cellLCSoftUnderVoltage * generalConfig->noOfCellsSeries;
|
||||||
const float endFaultVoltage = generalConfig->cellSoftOverVoltage * generalConfig->noOfCellsSeries;
|
const float endFaultVoltage = generalConfig->cellSoftOverVoltage * generalConfig->noOfCellsSeries;
|
||||||
memcpy(buffer, &startFaultVoltage, sizeof(startFaultVoltage));
|
memcpy(buffer, &startFaultVoltage, sizeof(startFaultVoltage));
|
||||||
memcpy(buffer + 4, &endFaultVoltage, sizeof(endFaultVoltage));
|
memcpy(buffer + 4, &endFaultVoltage, sizeof(endFaultVoltage));
|
||||||
addCanPacketToQueue(0x503, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
|
addCanPacketToQueue(0x503, buffer, can2_transmit_queue, &can2_transmit_queue_size);
|
||||||
|
|
||||||
// sending charge start current
|
// sending charge start current
|
||||||
float chargeStartingCurrent = 15; // TODO move to generalConfig
|
float chargeStartingCurrent = 15; // TODO move to generalConfig
|
||||||
u32_t chargeStartingCurrentInterval = 20; // in seconds TODO move to generalConfig
|
uint32_t chargeStartingCurrentInterval = 20; // in seconds TODO move to generalConfig
|
||||||
memcpy(buffer, &chargeStartingCurrent, sizeof(chargeStartingCurrent));
|
memcpy(buffer, &chargeStartingCurrent, sizeof(chargeStartingCurrent));
|
||||||
memcpy(buffer + 4, &chargeStartingCurrentInterval, sizeof(chargeStartingCurrentInterval));
|
memcpy(buffer + 4, &chargeStartingCurrentInterval, sizeof(chargeStartingCurrentInterval));
|
||||||
addCanPacketToQueue(0x504, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
|
addCanPacketToQueue(0x504, buffer, can2_transmit_queue, &can2_transmit_queue_size);
|
||||||
|
|
||||||
// sending table current and end-of-charge current command
|
// sending table current and end-of-charge current command
|
||||||
const int socIndex = getIndexBySoc();
|
const int socIndex = getIndexBySoc();
|
||||||
@@ -1330,7 +1328,7 @@ void transmitCan2Packet()
|
|||||||
float chargeEndingCurrent = 5; // TODO move to generalConfig
|
float chargeEndingCurrent = 5; // TODO move to generalConfig
|
||||||
memcpy(buffer + 0, &tableCurrent, sizeof(tableCurrent));
|
memcpy(buffer + 0, &tableCurrent, sizeof(tableCurrent));
|
||||||
memcpy(buffer + 4, &chargeEndingCurrent, sizeof(chargeEndingCurrent));
|
memcpy(buffer + 4, &chargeEndingCurrent, sizeof(chargeEndingCurrent));
|
||||||
addCanPacketToQueue(0x505, buffer, &can2_transmit_queue, &can2_transmit_queue_size);
|
addCanPacketToQueue(0x505, buffer, can2_transmit_queue, &can2_transmit_queue_size);
|
||||||
|
|
||||||
// sending charge permission, charge ending, charge/discharge state command
|
// sending charge permission, charge ending, charge/discharge state command
|
||||||
const uint8_t chargeAllowed = packState.chargeAllowed ? 0xFF : 0x00;
|
const uint8_t chargeAllowed = packState.chargeAllowed ? 0xFF : 0x00;
|
||||||
@@ -1340,20 +1338,18 @@ void transmitCan2Packet()
|
|||||||
memcpy(buffer + 0, &chargeAllowed, sizeof(chargeAllowed));
|
memcpy(buffer + 0, &chargeAllowed, sizeof(chargeAllowed));
|
||||||
memcpy(buffer + 1, &chargeEnding, sizeof(chargeEnding));
|
memcpy(buffer + 1, &chargeEnding, sizeof(chargeEnding));
|
||||||
memcpy(buffer + 2, &chargeSwitchState, sizeof(chargeSwitchState));
|
memcpy(buffer + 2, &chargeSwitchState, sizeof(chargeSwitchState));
|
||||||
addCanPacketToQueue(0x506, 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)
|
void addCanPacketToQueue(uint16_t id, uint8_t* data, uint8_t* queue, uint16_t* queueSize)
|
||||||
{
|
{
|
||||||
return;
|
memcpy(queue + *queueSize, &id, 2);
|
||||||
*queueSize += 10;
|
memcpy(queue + *queueSize + 2, data, 8);
|
||||||
*queue = (uint8_t*)realloc(*queue, *queueSize);
|
|
||||||
|
|
||||||
memcpy(*queue + *queueSize - 10, &id, 2);
|
*queueSize += 10;
|
||||||
memcpy(*queue + *queueSize - 8, data, 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void transmitCanPacketFromQueue(uint8_t** queue, uint16_t* queueSize, CAN_HandleTypeDef* hcan)
|
void transmitCanPacketFromQueue(uint8_t* queue, uint16_t* queueSize, CAN_HandleTypeDef* hcan)
|
||||||
{
|
{
|
||||||
if (*queueSize < 10)
|
if (*queueSize < 10)
|
||||||
return;
|
return;
|
||||||
@@ -1361,11 +1357,11 @@ void transmitCanPacketFromQueue(uint8_t** queue, uint16_t* queueSize, CAN_Handle
|
|||||||
uint16_t id = 0;
|
uint16_t id = 0;
|
||||||
uint8_t data[8] = {};
|
uint8_t data[8] = {};
|
||||||
|
|
||||||
memcpy(&id, *queue + *queueSize - 10, 2);
|
memcpy(&id, queue, 2);
|
||||||
memcpy(data, *queue + *queueSize - 8, 8);
|
memcpy(data, queue + 2, 8);
|
||||||
|
|
||||||
*queueSize -= 10;
|
*queueSize -= 10;
|
||||||
*queue = (uint8_t*)realloc(*queue, *queueSize);
|
memmove(queue, queue + 10, *queueSize);
|
||||||
|
|
||||||
CAN_Transmit(id, data, 8, hcan);
|
CAN_Transmit(id, data, 8, hcan);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user