You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

54 lines
1.2 KiB

#include "VK_Com.h"
#include "VK_Client.h"
#include "drv_ec800k.h"
#include "rtdef.h"
#include "rtthread.h"
rt_device_t fmu_com = RT_NULL;
rt_sem_t fmu_com_rx_sem = RT_NULL;
static rt_err_t fmu_com_rx_cb(rt_device_t dev, rt_size_t size) {
if (fmu_com_rx_sem != RT_NULL) {
rt_sem_release(fmu_com_rx_sem);
}
return RT_EOK;
}
rt_device_t fmu_com_get(void) { return fmu_com; }
int fmu_com_register(rt_device_t com_dev) {
fmu_com = com_dev;
if (fmu_com_rx_sem == RT_NULL) {
fmu_com_rx_sem = rt_sem_create("fmuComRx", 0, RT_IPC_FLAG_PRIO);
}
rt_device_set_rx_indicate(fmu_com, fmu_com_rx_cb);
return 0;
}
/*接收到串口的数据,并将数据转发到网络端*/
void com_task(void) {
static uint8_t buff[128];
uint32_t len = 0;
while (1) {
if (rt_sem_take(fmu_com_rx_sem, 1000) == RT_EOK) {
while (1) {
len = rt_device_read(fmu_com, 0, buff, sizeof(buff));
if (len > 0) {
if (lte_dev.client1->connect_sta == true) {
/* 仅在客户端2连接时转发 */
rt_device_write(lte_dev.com_dev, 0, buff, len);
}
} else {
break;
}
}
}
}
}