stop run cmd

This commit is contained in:
wmano
2025-10-27 20:50:06 +08:00
parent 8b6f231b28
commit e7b859851b
16 changed files with 368 additions and 241 deletions
+2 -2
View File
@@ -6,8 +6,8 @@
struct chrg_io_t chrgios[TOTAL_IOS] = {
[IDX_GPO_LED1] = {GPO_PIN_LED1, PIN_MODE_OUTPUT, PIN_HIGH},
[IDX_GPO_LED2] = {GPO_PIN_LED2, PIN_MODE_OUTPUT, PIN_HIGH},
[IDX_GPO_LED3] = {GPO_PIN_LED3, PIN_MODE_OUTPUT, PIN_HIGH},
[IDX_GPO_LED2] = {GPO_PIN_LED2, PIN_MODE_OUTPUT, PIN_LOW},
[IDX_GPO_LED3] = {GPO_PIN_LED3, PIN_MODE_OUTPUT, PIN_LOW},
[IDX_GPO_UART_SW1] = {GPO_PIN_UART_SW1, PIN_MODE_OUTPUT, PIN_LOW},
[IDX_GPO_UART_SW2] = {GPO_PIN_UART_SW2, PIN_MODE_OUTPUT, PIN_LOW},
[IDX_GPO_UART_SW3] = {GPO_PIN_UART_SW3, PIN_MODE_OUTPUT, PIN_LOW},
+4 -4
View File
@@ -20,13 +20,13 @@ struct chrg_led_t chrgleds[TOTAL_LEDS] = {
.tmr_millis_off = PULSE_TIME*8,
.tmr_times = 1,
.tmr_cnt = 0,
} /*,
},
[IDX_LED2] = {
.index = IDX_LED2,
.pin_name = PIN_NAME_LED2,
.pin_base = PIN_LED2,
.pin_mode = PIN_MODE_OUTPUT,
.pin_value = PIN_HIGH,
.pin_value = PIN_LOW,
.tmr_name = TMR_NAME_LED2,
.tmr_fd = RT_NULL,
.tmr_stage = PIN_STAGE_IDLE,
@@ -40,7 +40,7 @@ struct chrg_led_t chrgleds[TOTAL_LEDS] = {
.pin_name = PIN_NAME_LED3,
.pin_base = PIN_LED3,
.pin_mode = PIN_MODE_OUTPUT,
.pin_value = PIN_HIGH,
.pin_value = PIN_LOW,
.tmr_name = TMR_NAME_LED3,
.tmr_fd = RT_NULL,
.tmr_stage = PIN_STAGE_IDLE,
@@ -48,7 +48,7 @@ struct chrg_led_t chrgleds[TOTAL_LEDS] = {
.tmr_millis_off = PULSE_TIME*8,
.tmr_times = 1,
.tmr_cnt = 0,
}*/
}
};
rt_int32_t chrg_led_get (eIDX_LED index)
+2 -2
View File
@@ -32,8 +32,8 @@
typedef enum {
IDX_LED1 = 0, // LED1
// IDX_LED2, // LED2
// IDX_LED3, // LED3
IDX_LED2, // LED2
IDX_LED3, // LED3
TOTAL_LEDS
} eIDX_LED;
+12 -35
View File
@@ -12,9 +12,7 @@
#include <rtdbg.h>
struct chrg_lcd_t chrglcd = {
.name = THR_NAME_LCD,
.devname = DEV_NAME_LCD,
.tid = RT_NULL,
.tty = RT_NULL,
};
@@ -70,14 +68,20 @@ int chrg_lcd_send (char *cmd)
void chrg_lcd_thread_entry (void *data)
{
struct chrg_lcd_t *pLCD = (struct chrg_lcd_t *)data;
struct chrg_thread_t *pTHR = (struct chrg_thread_t *)data;
if ((RT_NULL == pLCD)||(RT_NULL == pLCD->tty)) {
if (RT_NULL == pTHR) {
return ;
}
int len = 0;
struct chrg_tty_t *pTTY = pLCD->tty;
struct chrg_tty_t *pTTY = RT_NULL;
struct chrg_lcd_t *pLCD = &chrglcd;
pTTY = chrg_tty_create(pLCD->devname, 115200, 0, -1, 1);
if (RT_NULL == pTTY) {
LOG_E("tty can't create.");
return ;
}
chrg_tty_set_recv_tmo(pTTY, 100);
if (chrg_tty_connect(pTTY) != RT_EOK) {
@@ -85,7 +89,10 @@ void chrg_lcd_thread_entry (void *data)
return;
}
pLCD->tty = pTTY;
while (1) {
rt_memset(pLCD->rx_buf, 0, SIZE_BUF_TTY);
len = chrg_tty_recv(pTTY, pLCD->rx_buf, sizeof(pLCD->rx_buf));
if (len <= 0) {
rt_thread_mdelay(1);
@@ -99,36 +106,6 @@ void chrg_lcd_thread_entry (void *data)
}
int chrg_lcd_init (void)
{
rt_err_t ret;
struct chrg_lcd_t *pLCD = &chrglcd;
pLCD->tty = chrg_tty_create(pLCD->devname, 115200, 0, -1, 1);
if (RT_NULL == pLCD->tty) {
LOG_E("tty can't create.");
return -1;
}
rt_memset(pLCD->rx_buf, 0, SIZE_BUF_TTY);
ret = rt_mutex_init(&pLCD->lock, pLCD->name, RT_IPC_FLAG_FIFO);
if (ret != RT_EOK) {
LOG_E("init mutex '%s' failed.", pLCD->name);
return ret;
}
pLCD->tid = rt_thread_create(pLCD->name, chrg_lcd_thread_entry, pLCD, 4096,
RT_MAIN_THREAD_PRIORITY, 20);
if (RT_NULL != pLCD->tid) {
rt_thread_startup(pLCD->tid);
} else {
LOG_E("create thread '%s' failed.", pLCD->name);
}
return 0;
}
#if 1
static int lcdsend(rt_uint8_t argc, char **argv)
-5
View File
@@ -9,10 +9,7 @@
#define DEV_NAME_LCD "uart2"
struct chrg_lcd_t {
const char *name;
const char *devname;
struct rt_thread *tid;
struct rt_mutex lock;
struct chrg_tty_t *tty;
rt_uint8_t rx_buf[SIZE_BUF_TTY];
@@ -23,8 +20,6 @@ extern struct chrg_lcd_t chrglcd;
extern int chrg_lcd_send (char *cmd);
extern int chrg_lcd_init (void);
extern void chrg_lcd_thread_entry (void *data);
+4 -1
View File
@@ -9,8 +9,9 @@
#include "chrg_roll_nor.h"
#include "chrg_switch.h"
#include "chrg_utils.h"
#include "ulog.h"
#define LOG_TAG "chrg.nor"
//#define LOG_TAG "chrg.nor"
#define DBG_LEVEL DBG_LOG
#include <rtdbg.h>
@@ -51,6 +52,7 @@ int chrg_north_send (rt_uint8_t *data, rt_size_t length)
struct chrg_tty_t *pTTY = chrgnorth.tty;
if (RT_NULL != pTTY) {
LOG_HEX("sendN", 32, data, length);
ret = chrg_tty_send(pTTY, data, length);
}
@@ -249,6 +251,7 @@ void chrg_north_thread_entry (void *data)
}
rt_ringbuffer_put(pNOR->rb, pNOR->rx_buf, len);
LOG_HEX("recvN", 32, pNOR->rx_buf, len);
if (1 == pNOR->frame.findhead) {
if (rt_tick_get() >= pNOR->frame.last_tick + 100) { // 100ms
+31 -2
View File
@@ -1,7 +1,9 @@
#include <stdlib.h>
#include <string.h>
#include <rtthread.h>
#include "chrg_gpio.h"
#include "chrg_led.h"
#include "chrg_thread.h"
#include "chrg_sink.h"
#include "chrg_source.h"
@@ -13,6 +15,7 @@
#define LOG_TAG "chrg.rollnor"
#include <rtdbg.h>
rt_uint8_t nor_run = 1;
rt_uint8_t nor_ch = IDX_NOR_CH1;
const rt_base_t sw_uart[TOTAL_NOR_CHS] = {
@@ -65,6 +68,10 @@ void chrg_roll_nor_thread_entry (void *data)
chrg_north_switch((eIDX_NOR_CH)nor_ch);
source_get_vc(5000, 1000);
} else {
if (0 == nor_run) {
rt_thread_mdelay(1000);
continue;
}
pNOR->idx = idx%TOTAL_NOR_CHS;
@@ -73,6 +80,7 @@ void chrg_roll_nor_thread_entry (void *data)
rt_thread_mdelay(1);
continue;
} else {
chrg_led_flashing(IDX_LED2, TIMES_ONE, PULSE_TIME*2, PULSE_TIME*2);
chrg_north_switch(pNOR->idx);
pSW = &pNOR->sw[pNOR->idx];
@@ -90,7 +98,7 @@ void chrg_roll_nor_thread_entry (void *data)
idx++;
}
ret = rt_mb_recv(pTN->mb, (rt_uint32_t *)&pMB_R, 100); // 超时 100ms
ret = rt_mb_recv(pTN->mb, (rt_uint32_t *)&pMB_R, 200); // 超时 200ms
if ((RT_EOK == ret)&&(RT_NULL != pMB_R)) {
crc = calc_crc8(pMB_R->payload, pMB_R->length-1);
if (crc == pMB_R->payload[pMB_R->length-1]) {
@@ -115,7 +123,7 @@ void chrg_roll_nor_thread_entry (void *data)
}
rt_thread_mdelay(50); // 间隔 50ms
} else if (RT_ETIMEOUT == ret) {
} else {
rt_mutex_take(pTHR->mutex, RT_WAITING_FOREVER);
pNOR->manual = 0;
rt_mutex_release(pTHR->mutex);
@@ -150,6 +158,27 @@ static int north_send(rt_uint8_t argc, char **argv)
MSH_CMD_EXPORT(north_send, north send test);
static int north_run (int argc, char **argv)
{
if (2 != argc) {
rt_kprintf("help : %s start|stop\r\n", argv[0]);
return -1;
}
if (rt_strcmp(argv[1], "start") == 0) {
nor_run = 1;
} else if (rt_strcmp(argv[1], "stop") == 0) {
nor_run = 0;
} else {
rt_kprintf("help : %s start|stop\r\n", argv[0]);
return -1;
}
return 0;
}
MSH_CMD_EXPORT(north_run, north auto run);
#endif
+31 -2
View File
@@ -1,7 +1,8 @@
#include <stdlib.h>
#include <string.h>
#include <rtthread.h>
#include "chrg_led.h"
#include "chrg_thread.h"
#include "chrg_roll_sou.h"
#include "chrg_eload.h"
@@ -10,6 +11,7 @@
#define LOG_TAG "chrg.rollsou"
#include <rtdbg.h>
rt_uint8_t sou_run = 1;
rt_uint8_t sou_ch = IDX_SOU_CH1;
rt_uint8_t sou_pt = MB_R_PART1;
@@ -37,6 +39,11 @@ void chrg_roll_sou_thread_entry (void *data)
chrg_eload_refresh(ID_ELOAD, sou_pt);
} else { // 轮巡4个通道,每个通道3条读取命令
if (0 == sou_run) {
rt_thread_mdelay(1000);
continue;
}
part = index%(TOTAL_SOU_CHS*TOTAL_MB_R); // [0, 11]
idx = part/TOTAL_MB_R; // [0, 3]
pt = part%TOTAL_MB_R;
@@ -47,6 +54,7 @@ void chrg_roll_sou_thread_entry (void *data)
rt_thread_mdelay(10);
continue;
} else {
chrg_led_flashing(IDX_LED3, TIMES_ONE, PULSE_TIME*2, PULSE_TIME*2);
if (idx != (rt_uint8_t)pSOU->idx) {
pSOU->idx = (eIDX_SOU_CH)idx;
chrg_south_switch(pSOU->idx);
@@ -83,7 +91,7 @@ void chrg_roll_sou_thread_entry (void *data)
}
rt_thread_mdelay(50); // 间隔 50ms
} else if (RT_ETIMEOUT == ret) {
} else {
rt_mutex_take(pTHR->mutex, RT_WAITING_FOREVER);
pSOU->manual = 0;
rt_mutex_release(pTHR->mutex);
@@ -125,6 +133,27 @@ static int south_send(rt_uint8_t argc, char **argv)
MSH_CMD_EXPORT(south_send, south send test);
static int south_run (int argc, char **argv)
{
if (2 != argc) {
rt_kprintf("help : %s start|stop\r\n", argv[0]);
return -1;
}
if (rt_strcmp(argv[1], "start") == 0) {
sou_run = 1;
} else if (rt_strcmp(argv[1], "stop") == 0) {
sou_run = 0;
} else {
rt_kprintf("help : %s start|stop\r\n", argv[0]);
return -1;
}
return 0;
}
MSH_CMD_EXPORT(south_run, south auto run);
#endif
+4 -1
View File
@@ -7,8 +7,9 @@
#include "chrg_roll_sou.h"
#include "chrg_switch.h"
#include "chrg_utils.h"
#include "ulog.h"
#define LOG_TAG "chrg.sou"
//#define LOG_TAG "chrg.sou"
#define DBG_LEVEL DBG_LOG
#include <rtdbg.h>
@@ -108,6 +109,7 @@ int chrg_south_send (rt_uint8_t *data, rt_size_t length)
struct chrg_tty_t *pTTY = chrgsouth.tty;
if (RT_NULL != pTTY) {
LOG_HEX("sendS", 32, data, length);
ret = chrg_tty_send(pTTY, data, length);
}
@@ -309,6 +311,7 @@ void chrg_south_thread_entry (void *data)
}
rt_ringbuffer_put(pSOU->rb, pSOU->rx_buf, len);
LOG_HEX("recvS", 32, pSOU->rx_buf, len);
if (1 == pSOU->frame.findhead) {
if (rt_tick_get() >= pSOU->frame.last_tick + 100) { // 100ms
+2 -2
View File
@@ -15,7 +15,7 @@ int chrg_eload_read_regs (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t len)
u16_to_u8v(reg, &buf[2]);
u16_to_u8v(len, &buf[4]);
crc = mb_crc16(buf, 6);
u16_to_u8v(crc, &buf[6]);
u16_to_u8v(swap_u16(crc), &buf[6]);
return chrg_south_send(buf, 8);
}
@@ -30,7 +30,7 @@ int chrg_eload_write_reg (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t value)
u16_to_u8v(reg, &buf[2]);
u16_to_u8v(value, &buf[4]);
crc = mb_crc16(buf, 6);
u16_to_u8v(crc, &buf[6]);
u16_to_u8v(swap_u16(crc), &buf[6]);
return chrg_south_send(buf, 8);
}
+17 -1
View File
@@ -1,10 +1,26 @@
#include <rtthread.h>
#include "chrg_sink.h"
#include "chrg_north.h"
#include "chrg_north_pkg.h"
#include "chrg_utils.h"
int sink_get_vc (rt_uint16_t vol, rt_uint16_t cur)
{
rt_uint16_t len = 0;
rt_uint8_t data[12] = {0};
rt_uint8_t frame[16] = {0};
return 0;
u16_to_u8v(vol, &data[0]);
u16_to_u8v(cur, &data[2]);
data[4] = 0x00;
data[5] = 0x00;
chrg_north_pkg_encode(ID_SINK, SINK_CMD_GET_VOLTAGE, data, 6, frame, &len);
return chrg_north_send(frame, len);
}
+15
View File
@@ -119,5 +119,20 @@ rt_uint16_t u8v_to_u16 (rt_uint8_t *buf)
return 0;
}
// rt_uint16_t 高低位互换
rt_uint16_t swap_u16 (rt_uint16_t x)
{
return ((x & 0x00FF) << 8) |
((x & 0xFF00) >> 8);
}
// rt_uint32_t 高低位互换
rt_uint32_t swap_u32 (rt_uint32_t x)
{
return ((x & 0x000000FF) << 24) |
((x & 0x0000FF00) << 8) |
((x & 0x00FF0000) >> 8) |
((x & 0xFF000000) >> 24);
}
@@ -11,6 +11,10 @@ extern rt_uint8_t u16_to_u8v (rt_uint16_t value, rt_uint8_t *buf);
extern rt_uint16_t u8v_to_u16 (rt_uint8_t *buf);
extern rt_uint16_t swap_u16 (rt_uint16_t x);
extern rt_uint32_t swap_u32 (rt_uint32_t x);
#endif