global refactoring
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
#include "board.h"
|
||||
#include "charger_gbt.h"
|
||||
#include "usart.h"
|
||||
#include <time.h>
|
||||
#include <connector.h>
|
||||
|
||||
|
||||
uint8_t debug_rx_buffer[256];
|
||||
uint8_t debug_cmd_received;
|
||||
@@ -22,11 +25,23 @@ extern UART_HandleTypeDef huart2;
|
||||
#if defined(__GNUC__)
|
||||
int _write(int fd, char * ptr, int len)
|
||||
{
|
||||
HAL_UART_Transmit(&huart2, (uint8_t *) ptr, len, HAL_MAX_DELAY);
|
||||
return len;
|
||||
HAL_GPIO_WritePin(USART2_DIR_GPIO_Port, USART2_DIR_Pin, 1);
|
||||
HAL_UART_Transmit(&huart2, (uint8_t *) ptr, len, HAL_MAX_DELAY);
|
||||
HAL_GPIO_WritePin(USART2_DIR_GPIO_Port, USART2_DIR_Pin, 0);
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
|
||||
|
||||
// if(huart->Instance == USART1){
|
||||
// mm_rx_interrupt(huart, Size);
|
||||
// }
|
||||
if(huart->Instance == USART2){
|
||||
debug_rx_interrupt(huart, Size);
|
||||
}
|
||||
}
|
||||
|
||||
void debug_rx_interrupt(UART_HandleTypeDef *huart, uint16_t Size){
|
||||
debug_rx_buffer[Size] = '\0';
|
||||
debug_rx_buffer_size = Size;
|
||||
@@ -53,7 +68,7 @@ void parse_command(uint8_t* buffer, size_t length) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer[0] == 0) return;
|
||||
if (strncmp((const char*)buffer, "reset", length) == 0) {
|
||||
printf("Resetting...\n");
|
||||
NVIC_SystemReset();
|
||||
@@ -75,7 +90,7 @@ void parse_command(uint8_t* buffer, size_t length) {
|
||||
// mm_schedule_read(0x02, 0x0001);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "adc", length) == 0) {
|
||||
printf("CC1=%.2f\n", GBT_CC_GetAdc());
|
||||
printf("CC1=%.2f\n", CONN_CC_GetAdc());
|
||||
|
||||
} else if (strncmp((const char*)buffer, "lock_state", length) == 0) {
|
||||
printf("Lock state=%d\n", GBT_LockGetState());
|
||||
@@ -88,26 +103,29 @@ void parse_command(uint8_t* buffer, size_t length) {
|
||||
printf("Unlocked\n");
|
||||
GBT_Lock(0);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "complete", length) == 0) {
|
||||
CONN_SetState(CONN_Occupied_complete);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "start", length) == 0) {
|
||||
printf("Started\n");
|
||||
GBT_Start();
|
||||
|
||||
} else if (strncmp((const char*)buffer, "stop", length) == 0) {
|
||||
printf("Stopped\n");
|
||||
GBT_Stop();
|
||||
GBT_Stop(GBT_CST_SUSPENDS_ARTIFICIALLY);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "stop1", length) == 0) {
|
||||
printf("Stopped\n");
|
||||
GBT_Stop1();
|
||||
GBT_ForceStop();
|
||||
|
||||
} else if (strncmp((const char*)buffer, "force", length) == 0) {
|
||||
printf("Stopped\n");
|
||||
GBT_Lock(1);
|
||||
GBT_SwitchState(GBT_S2_LOCKED);
|
||||
GBT_Delay(500);
|
||||
// } else if (strncmp((const char*)buffer, "force", length) == 0) {
|
||||
// printf("Stopped\n");
|
||||
// GBT_Lock(1);
|
||||
// GBT_SwitchState(GBT_S2_LOCKED);
|
||||
// GBT_Delay(500);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "cc_state", length) == 0) {
|
||||
switch(GBT_CC_GetState()){
|
||||
switch(CONN_CC_GetState()){
|
||||
case GBT_CC_UNKNOWN:
|
||||
printf("GBT_CC_UNKNOWN\n");
|
||||
break;
|
||||
@@ -149,6 +167,18 @@ void parse_command(uint8_t* buffer, size_t length) {
|
||||
printf("EVIN: %.17s\n", GBT_EVInfo.EVIN); //EVIN
|
||||
printf("EV_SW_VER: %.8s\n", GBT_EVInfo.EV_SW_VER);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "info3", length) == 0) {
|
||||
printf("GBT_MaxLoad info:\n");
|
||||
printf("Output max current: %d\n",GBT_MaxLoad.maxOutputCurrent);
|
||||
printf("Output min current: %d\n",GBT_MaxLoad.minOutputCurrent);
|
||||
printf("Output max voltage: %d\n",GBT_MaxLoad.maxOutputVoltage);
|
||||
printf("Output min voltage: %d\n",GBT_MaxLoad.minOutputVoltage);
|
||||
printf("\nGBT_ChargerInfo info:\n");
|
||||
printf("BMS Recognized: %d\n",GBT_ChargerInfo.bmsIdentified);
|
||||
printf("Charger location: %.3s\n",GBT_ChargerInfo.chargerLocation);
|
||||
printf("Charger number: %lu\n",GBT_ChargerInfo.chargerNumber);
|
||||
|
||||
|
||||
} else if (strncmp((const char*)buffer, "help", length) == 0) {
|
||||
printf("Command list:\n");
|
||||
printf("reset\n");
|
||||
@@ -162,11 +192,32 @@ void parse_command(uint8_t* buffer, size_t length) {
|
||||
printf("start\n");
|
||||
printf("stop\n");
|
||||
printf("stop1\n");
|
||||
printf("force\n");
|
||||
// printf("force\n");
|
||||
printf("info1\n");
|
||||
printf("info2\n");
|
||||
printf("info3\n");
|
||||
printf("time\n");
|
||||
printf("cantest\n");
|
||||
|
||||
//TODO: info commands
|
||||
|
||||
} else if (strncmp((const char*)buffer, "time", length) == 0) {
|
||||
|
||||
time_t unix_time = (time_t)get_Current_Time();
|
||||
struct tm *parts = localtime(&unix_time);
|
||||
|
||||
printf("Year: %d\n", parts->tm_year + 1900);
|
||||
printf("Month: %d\n", parts->tm_mon + 1);
|
||||
printf("Day: %d\n", parts->tm_mday);
|
||||
printf("Hour: %d\n", parts->tm_hour);
|
||||
printf("Minute: %d\n", parts->tm_min);
|
||||
printf("Second: %d\n", parts->tm_sec);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "cantest", length) == 0) {
|
||||
//GBT_SendCHM();
|
||||
GBT_Error(0xFDF0C0FC); //BRM Timeout
|
||||
printf("can test\n");
|
||||
|
||||
} else {
|
||||
printf("Unknown command\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user