#include "main.h" #include "os-app.h" #include #include #include #include #include #include "usart-board.h" #include "modbus-s.h" #include "modbusaddr.h" ALIGN(RT_ALIGN_SIZE) static char thread_stack[4096]; static struct rt_thread probus_thread; uint16_t REG_DATA[REG_MAX] = {0x00}; // 寄存器对应的数据 // case ssKHYSet: // { // vv = value*10; // dbg_printf ("MbusSetValue vv:%d\r\n",vv); // sendcmd[type][4] = ((vv >> 8) & 0xff); // sendcmd[type][5] = (vv & 0xff); // vv = bsp_crc_calc16((uint8_t *)sendcmd[type],6); // sendcmd[type][7] = ((vv >> 8) & 0xff); // sendcmd[type][6] = (vv & 0xff); // for(int i = 0;i < 8;i++) // { // dbg_printf("%02X ",sendcmd[type][i]); // } // dbg_printf("\r\n"); // } // {0x01, 0x03, 0x00, 0x00, 0x00, 0x06, 0xC5, 0xC8}, // 闸位计读取开度 // {0x01, 0x06, 0x00, 0x07, 0x00, 0x02, 0xE6, 0x69}, // 闸位计设置开度 // {0x01, 0x06, 0x00, 0x04, 0x01, 0x00, 0xC9, 0x9B}, // 启动闸位计 // {0x01, 0x06, 0x00, 0x04, 0x00, 0x00, 0xC8, 0x0B}, // 停止闸位计 static ModBusSlave_t modbus_slave; static uint8_t modbus_rx_data[32]; static void eth2_data_rxdone(void) { rt_event_send(gUartEvents,EVENT_UART_ETH2_RX); //rt_kprintf("net_data_rxdone\r\n"); } static void probus_handle(uint16_t addr,uint8_t * data) { switch (addr) { case REG_SOPEN: // 设定闸门开度 break; case REG_SLOPT: // 执行闸门动作 if (data[0] == 0x01) // 执行 { rt_event_send(gCtrlEvents,EVENT_CTRL_SET_OPEN); rt_kprintf("probus_handle set open\r\n"); } else { } break; default: break; } } static void thread_entry(void * argument) { int k = 0; uint8_t txbuff[128] = {0}; int tx_size = 0; rt_kprintf("%s was start!\r\n",__FILE__); g_ETH2Drv.rxdone = eth2_data_rxdone; g_ETH2Drv.BaudRate = 115200; MX_UART_Init(&g_ETH2Drv); ModbusSlaveInit(&modbus_slave,0x01,modbus_rx_data,REG_DATA,REG_MAX); // 注册网络驱动 // 注册网络驱动 while (1) { if( RT_EOK == rt_event_recv( gUartEvents, EVENT_UART_ETH2_RX,RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, RT_NULL )) { // rt_kprintf("<<<<<<<<<<<<<<<<<<< 0) { MX_UART_PutBuffer(&g_ETH2Drv,(char *)txbuff,tx_size); } MX_UART_Clear(&g_ETH2Drv); } rt_thread_delay(10); } } void PROBUS_APPThreadStart(void ) { /* 创建线程1,名称是thread1,入口是thread1_entry*/ rt_thread_init(&probus_thread, "probus_thread", thread_entry, RT_NULL, &thread_stack[0], sizeof(thread_stack), PROBUS_APP_THREAD_PRIORITY, PROBUS_APP_THREAD_TIMESLICE); rt_thread_startup(&probus_thread); return ; }