更新485定时采集逻辑
This commit is contained in:
parent
4f4ef32d1b
commit
a6c486f9f3
@ -97,7 +97,7 @@ static BATT_INFO batt;
|
||||
|
||||
static void timer485_cb()
|
||||
{
|
||||
rt_mutex_release(sendcmd);
|
||||
// rt_mutex_release(sendcmd);
|
||||
}
|
||||
static int b2v(uint8_t *din)
|
||||
{
|
||||
@ -162,6 +162,26 @@ uint8_t getBattInfo(uint8_t *dout)
|
||||
return p;
|
||||
}
|
||||
|
||||
static void T485_thread_entry(void *parameter)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
//发送指令
|
||||
// if (rt_mutex_take(sendcmd, RT_WAITING_FOREVER) == RT_EOK)
|
||||
if(rt_mutex_take(sendcmd, rt_tick_from_millisecond(1*60*1000)) != RT_EOK)
|
||||
{
|
||||
uint8_t cmd[] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x1d, 0x85, 0xc3 };
|
||||
|
||||
//send cmd
|
||||
rt_pin_write(TR485_RE, PIN_HIGH);
|
||||
rt_device_write(serial485, 0, cmd, sizeof(cmd));
|
||||
rt_pin_write(TR485_RE, PIN_LOW);
|
||||
LOG_D("send 485");
|
||||
}
|
||||
// rt_thread_mdelay(60*1000);
|
||||
}
|
||||
}
|
||||
|
||||
static void serial485_thread_entry(void *parameter)
|
||||
{
|
||||
struct rx_msg msg;
|
||||
@ -171,17 +191,6 @@ static void serial485_thread_entry(void *parameter)
|
||||
|
||||
while (1)
|
||||
{
|
||||
//发送指令
|
||||
// if (rt_mutex_take(sendcmd, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
uint8_t cmd[] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x1d, 0x85, 0xc3 };
|
||||
|
||||
//send cmd
|
||||
rt_pin_write(TR485_RE, PIN_HIGH);
|
||||
rt_device_write(serial485, 0, cmd, sizeof(cmd));
|
||||
rt_pin_write(TR485_RE, PIN_LOW);
|
||||
}
|
||||
|
||||
rt_memset(&msg, 0, sizeof(msg));
|
||||
/* 从消息队列中读取消息*/
|
||||
|
||||
@ -200,7 +209,7 @@ static void serial485_thread_entry(void *parameter)
|
||||
parseBattInfo(rx_buffer, rx_length);
|
||||
}
|
||||
|
||||
rt_thread_mdelay(1*60*1000);
|
||||
// rt_thread_mdelay(1*60*1000);
|
||||
|
||||
}
|
||||
|
||||
@ -268,12 +277,26 @@ static int uart485_dma_sample(int argc, char *argv[])
|
||||
ret = RT_ERROR;
|
||||
}
|
||||
|
||||
sendcmd = rt_mutex_create("reqBatt", RT_IPC_FLAG_FIFO);
|
||||
timer485 = rt_timer_create("batt", timer485_cb, RT_NULL, rt_tick_from_millisecond(6*10*1000), RT_TIMER_FLAG_PERIODIC);
|
||||
/* 创建 serial 线程 */
|
||||
thread = rt_thread_create("T485", T485_thread_entry, RT_NULL, 1024*5, 25, 10);
|
||||
/* 创建成功则启动线程 */
|
||||
if (thread != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(thread);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = RT_ERROR;
|
||||
}
|
||||
|
||||
/* 启动定时器1 */
|
||||
if (timer485 != RT_NULL)
|
||||
rt_timer_start(timer485);
|
||||
sendcmd = rt_mutex_create("reqBatt", RT_IPC_FLAG_FIFO);
|
||||
rt_mutex_take(sendcmd, RT_WAITING_FOREVER);
|
||||
LOG_I("RS485 inited ok");
|
||||
// timer485 = rt_timer_create("batt", timer485_cb, RT_NULL, rt_tick_from_millisecond(1*60*1000), RT_TIMER_FLAG_PERIODIC);
|
||||
//
|
||||
// /* 启动定时器1 */
|
||||
// if (timer485 != RT_NULL)
|
||||
// rt_timer_start(timer485);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -284,6 +307,6 @@ static int uart485_dma_sample(int argc, char *argv[])
|
||||
|
||||
/* 导出到 msh 命令列表中 */
|
||||
//MSH_CMD_EXPORT(uart485_dma_sample,uart485_dma_sample);
|
||||
INIT_COMPONENT_EXPORT(uart485_dma_sample);
|
||||
INIT_APP_EXPORT(uart485_dma_sample);
|
||||
MSH_CMD_EXPORT(dumpBattInfo,解析电池信息);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user