roll south mb
This commit is contained in:
@@ -1,22 +1,17 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
|
||||
#include "chrg_thread.h"
|
||||
#include "chrg_roll_sou.h"
|
||||
#include "chrg_switch.h"
|
||||
#include "chrg_eload.h"
|
||||
#include "chrg_utils.h"
|
||||
|
||||
#define LOG_TAG "chrg.rollsou"
|
||||
#include <rtdbg.h>
|
||||
|
||||
|
||||
void chrg_roll_sou_evt_send (void)
|
||||
{
|
||||
struct chrg_thread_t *pTHR = &chrgthr[IDX_THR_ROLL_SOU];
|
||||
if (RT_NULL != pTHR->ev) {
|
||||
rt_event_send(pTHR->ev, ROLL_SOU_EVT_RECVED);
|
||||
}
|
||||
}
|
||||
rt_uint8_t sou_ch = IDX_SOU_CH1;
|
||||
rt_uint8_t sou_pt = MB_R_PART1;
|
||||
|
||||
void chrg_roll_sou_thread_entry (void *data)
|
||||
{
|
||||
@@ -26,7 +21,7 @@ void chrg_roll_sou_thread_entry (void *data)
|
||||
return ;
|
||||
}
|
||||
|
||||
rt_uint8_t idx = 0;
|
||||
rt_uint8_t index = 0, idx = 0, part = 0, pt = 0, manu = 0;
|
||||
rt_err_t ret = RT_EOK;
|
||||
struct chrg_south_t *pSOU = &chrgsouth;
|
||||
struct chrg_thread_t *pTS = &chrgthr[IDX_THR_SOUTH];
|
||||
@@ -34,30 +29,48 @@ void chrg_roll_sou_thread_entry (void *data)
|
||||
|
||||
while (1) {
|
||||
rt_mutex_take(pTHR->mutex, RT_WAITING_FOREVER);
|
||||
pSOU->idx = idx%(TOTAL_CHS+TOTAL_SOU_CHS);
|
||||
manu = pSOU->manual;
|
||||
rt_mutex_release(pTHR->mutex);
|
||||
|
||||
if (pSOU->idx < TOTAL_SOU_CHS) {
|
||||
if (0 == pSOU->enable[pSOU->idx]) {
|
||||
idx++;
|
||||
if (1 == manu) {
|
||||
chrg_south_switch((eIDX_SOU_CH)sou_ch);
|
||||
chrg_eload_refresh(ID_ELOAD, sou_pt);
|
||||
|
||||
} else { // 轮巡4个通道,每个通道3条读取命令
|
||||
part = index%(TOTAL_SOU_CHS*TOTAL_MB_R); // [0, 11]
|
||||
idx = part/TOTAL_MB_R; // [0, 3]
|
||||
pt = part%TOTAL_MB_R;
|
||||
|
||||
if (0 == pSOU->enable[idx]) {
|
||||
pSOU->idx = (eIDX_SOU_CH)idx;
|
||||
index++;
|
||||
rt_thread_mdelay(10);
|
||||
continue;
|
||||
} else {
|
||||
pSOU->idx = (eIDX_SOU_CH)pSOU->idx;
|
||||
chrg_switch_south(pSOU->idx);
|
||||
if (idx != (rt_uint8_t)pSOU->idx) {
|
||||
pSOU->idx = (eIDX_SOU_CH)idx;
|
||||
chrg_south_switch(pSOU->idx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//rt_kprintf("Sou[%d].%d\r\n", pSOU->idx, pSOU->id);
|
||||
chrg_eload_refresh(ID_ELOAD, pt);
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
idx++;
|
||||
|
||||
ret = rt_mb_recv(pTS->mb, (rt_uint32_t *)&pMB_R, 100); // 超时 100ms
|
||||
ret = rt_mb_recv(pTS->mb, (rt_uint32_t *)&pMB_R, 200); // 超时 200ms
|
||||
if ((RT_EOK == ret)&&(RT_NULL != pMB_R)) {
|
||||
// todo mail data
|
||||
|
||||
if (0 == mb_crc16(pMB_R->payload, pMB_R->length)) {
|
||||
if (1 == manu) {
|
||||
rt_mutex_take(pTHR->mutex, RT_WAITING_FOREVER);
|
||||
pSOU->manual = 0;
|
||||
rt_mutex_release(pTHR->mutex);
|
||||
} else {
|
||||
chrg_eload_parse(idx, pt, pMB_R->payload, pMB_R->length);
|
||||
}
|
||||
} else {
|
||||
LOG_E("crc failed.");
|
||||
}
|
||||
|
||||
if (RT_NULL != pMB_R->payload) {
|
||||
rt_free(pMB_R->payload);
|
||||
@@ -70,11 +83,48 @@ void chrg_roll_sou_thread_entry (void *data)
|
||||
}
|
||||
|
||||
rt_thread_mdelay(50); // 间隔 50ms
|
||||
} else if (RT_ETIMEOUT == ret) {
|
||||
rt_mutex_take(pTHR->mutex, RT_WAITING_FOREVER);
|
||||
pSOU->manual = 0;
|
||||
rt_mutex_release(pTHR->mutex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if 1
|
||||
static int south_send(rt_uint8_t argc, char **argv)
|
||||
{
|
||||
struct chrg_south_t *pSOU = &chrgsouth;
|
||||
int ch = 0, pt = 0;
|
||||
|
||||
if (3 != argc) {
|
||||
rt_kprintf("help : %s [0-3] [0-2]\r\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ch = (rt_uint8_t)atoi(argv[1]);
|
||||
if ((ch < 0)||(ch >= TOTAL_SOU_CHS)) {
|
||||
rt_kprintf("help : %s [0-3] [0-2]\r\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pt = (rt_uint8_t)atoi(argv[2]);
|
||||
if ((pt < 0)||(pt >= TOTAL_MB_R)) {
|
||||
rt_kprintf("help : %s [0-3] [0-2]\r\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sou_ch = (rt_uint8_t)ch;
|
||||
sou_pt = (rt_uint8_t)pt;
|
||||
pSOU->manual = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT(south_send, south send test);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user