|
|
@@ -1,17 +1,28 @@
|
|
|
+#include <string.h>
|
|
|
#include "bsp/gpio.h"
|
|
|
#include "bsp/ml5238.h"
|
|
|
#include "bsp/uart.h"
|
|
|
#include "bsp/gd32_adc.h"
|
|
|
+#include "bsp/cs1180.h"
|
|
|
#include "nv_storage.h"
|
|
|
#include "pcba_test.h"
|
|
|
-
|
|
|
+static void pcba_test_timer_handler(shark_timer_t *timer);
|
|
|
+static shark_timer_t pcba_test_timer = {.handler = pcba_test_timer_handler};
|
|
|
+static int pcba_test_item = -1;
|
|
|
+static int powerdown_flags = 0;
|
|
|
+static void pcba_test_timer_handler(shark_timer_t *timer) {
|
|
|
+ if (pcba_test_item == 1) {
|
|
|
+ UART0_IR_EN(1);
|
|
|
+ }
|
|
|
+ pcba_test_item = -1;
|
|
|
+}
|
|
|
int pcba_test(uint8_t *data, int len, uint8_t *response){
|
|
|
uint8_t *payload = data + 2;
|
|
|
int resp_len = 0;
|
|
|
response[resp_len ++] = 0xFE;
|
|
|
response[resp_len ++] = 0xFE;
|
|
|
response[resp_len ++] = 0; //len
|
|
|
- response[resp_len ++] = payload[0];
|
|
|
+ //response[resp_len ++] = payload[0];
|
|
|
response[resp_len ++] = payload[1];
|
|
|
uint8_t cmd = payload[1];
|
|
|
if (cmd == 0x00) {
|
|
|
@@ -19,17 +30,11 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
|
|
|
}else if (cmd == 0x01) {
|
|
|
response[resp_len ++] = (uint8_t)nv_read_write_test();
|
|
|
}else if (cmd == 0x02){
|
|
|
- int8_t temp;
|
|
|
- uint8_t result = 0;
|
|
|
for (int i = 0; i < PACK_TEMPS_NUM; i++){
|
|
|
- temp = get_pack_temperature(i);
|
|
|
- if(!(((temp >= 24) && (temp <= 26))||((temp >= 63) && (temp <= 67)))){
|
|
|
- result = 1;
|
|
|
- }
|
|
|
+ response[resp_len ++] = (uint8_t)get_pack_temperature(i) + 40;
|
|
|
}
|
|
|
- response[resp_len ++] = result;
|
|
|
}else if (cmd == 0x03) {
|
|
|
- response[resp_len ++] = 0;
|
|
|
+ response[resp_len ++] = io_state()->aux_lock_detect?0:1;
|
|
|
}else if (cmd == 0x04) {
|
|
|
LED1_ON(0);
|
|
|
LED3_ON(0);
|
|
|
@@ -53,9 +58,10 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
|
|
|
response[resp_len ++] = 0;
|
|
|
}else if (cmd == 0x07) {
|
|
|
start_aux_power(1);
|
|
|
+ io_state()->aux_lock_irq = 0;
|
|
|
response[resp_len ++] = 0;
|
|
|
}else if (cmd == 0x08) {
|
|
|
- response[resp_len ++] = io_state()->aux_lock_detect;
|
|
|
+ response[resp_len ++] = io_state()->aux_lock_irq;
|
|
|
}else if (cmd == 0x09) {
|
|
|
start_aux_power(0);
|
|
|
response[resp_len ++] = 0;
|
|
|
@@ -81,6 +87,7 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
|
|
|
discharger_open(1);
|
|
|
start_aux_power(0);
|
|
|
response[resp_len ++] = 0;
|
|
|
+ powerdown_flags = 0xF;
|
|
|
system_power_down();
|
|
|
}else if (cmd == 0xf){
|
|
|
response[resp_len ++] = !IS_HALL1_DETECTED();
|
|
|
@@ -114,8 +121,8 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
|
|
|
response[resp_len ++] = aux_power_adc;
|
|
|
response[resp_len ++] = aux_power_adc >> 8;
|
|
|
}else if (cmd == 0x13) {
|
|
|
- shark_uart_deinit(SHARK_UART1);
|
|
|
- rcu_periph_clock_enable(RCU_GPIOA);
|
|
|
+ //shark_uart_deinit(SHARK_UART1);
|
|
|
+ //rcu_periph_clock_enable(RCU_GPIOA);
|
|
|
gpio_mode_output(GPIOA, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_2);
|
|
|
gpio_mode_input(GPIOA, GPIO_PUPD_NONE, GPIO_PIN_3);
|
|
|
gpio_bit_set(GPIOA, GPIO_PIN_2);
|
|
|
@@ -126,21 +133,25 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
|
|
|
}else if (cmd == 0x14) {
|
|
|
UART0_IR_EN(0);
|
|
|
response[resp_len ++] = gpio_output_bit_get(GPIOC,GPIO_PIN_14);
|
|
|
+ pcba_test_item = 1;
|
|
|
+ shark_timer_post(&pcba_test_timer, 500);
|
|
|
}else if (cmd == 0x15) {
|
|
|
- UART1_IR_EN(0);
|
|
|
- response[resp_len ++] = gpio_output_bit_get(GPIOF,GPIO_PIN_0);
|
|
|
+ UART0_IR_EN(1);
|
|
|
+ pcba_test_item = -1;
|
|
|
+ shark_timer_cancel(&pcba_test_timer);
|
|
|
+ response[resp_len ++] = gpio_output_bit_get(GPIOC,GPIO_PIN_14);
|
|
|
}else if (cmd == 0x17) {
|
|
|
- uint16_t vol = 0;
|
|
|
+ uint8_t cell_index = 0;
|
|
|
for (int i = 0; i < CELLS_NUM; i++){
|
|
|
if (measure_value()->cell_vol[i] > 3000 && measure_value()->cell_vol[i] < 3400) {
|
|
|
- vol = measure_value()->cell_vol[i];
|
|
|
+ cell_index = i;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- response[resp_len ++] = vol;
|
|
|
- response[resp_len ++] = vol >> 8;
|
|
|
+ response[resp_len ++] = cell_index;
|
|
|
}else if (cmd == 0x18) {
|
|
|
uint8_t result = 1;
|
|
|
+ response[resp_len ++] = payload[2];
|
|
|
if (payload[2] == 1) {
|
|
|
charger_open(1);
|
|
|
discharger_open(1);
|
|
|
@@ -150,7 +161,7 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
|
|
|
result = 0;
|
|
|
}
|
|
|
}else if (payload[2] == 3) {
|
|
|
- if (io_state()->aux_lock_detect) {
|
|
|
+ if (bms_health()->load_current_short) {
|
|
|
result = 0;
|
|
|
}
|
|
|
}else if (payload[2] == 4) {
|
|
|
@@ -159,8 +170,22 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
|
|
|
result = 0;
|
|
|
}
|
|
|
response[resp_len ++] = result;
|
|
|
+ }else if (cmd == 0x20) {
|
|
|
+ response[resp_len ++] = payload[2];
|
|
|
+ if (payload[2] == 1) {
|
|
|
+ response[resp_len ++] = cs1180_is_ready();
|
|
|
+ }else if (payload[2] == 2) {
|
|
|
+ charger_open(1);
|
|
|
+ discharger_open(1);
|
|
|
+ response[resp_len ++] = 0;
|
|
|
+ }else if (payload[2] == 3) {
|
|
|
+ memcpy(response + resp_len, &measure_value()->load_current, 4);
|
|
|
+ resp_len += 4;
|
|
|
+ }
|
|
|
+ }else if (cmd == 0x21) {
|
|
|
+ response[resp_len ++] = powerdown_flags;
|
|
|
}
|
|
|
- response[2] = resp_len;
|
|
|
+ response[2] = resp_len - 2;
|
|
|
|
|
|
return resp_len;
|
|
|
}
|