From f4db7850748e3a72f7a2dc8986960bb12a074fc0 Mon Sep 17 00:00:00 2001 From: xudx Date: Thu, 21 Nov 2024 09:55:37 +0800 Subject: [PATCH] [ADD] modbus thread --- test/test.c | 77 ++++++++++++++++++++++++++++++----------------------- test/test.h | 1 + 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/test/test.c b/test/test.c index 704131d..7e8c997 100644 --- a/test/test.c +++ b/test/test.c @@ -9,6 +9,7 @@ #include "drv_can.h" #include "drv_tcp.h" #include "drv_4g.h" +#include "libmodbus/include/modbus-rtu.h" void runTest() { @@ -24,7 +25,7 @@ void testCreatThreadTask() { printf("testThreadTask\n"); logger_init("./log"); - pthread_t tTestLogger, tTestDIDetect, tTestUart, tTestTcp, tTest4G, tTestCanSend, tTestCanRecv; + pthread_t tTestLogger, tTestDIDetect, tTestUart, tTestTcp, tTest4G, tTestCanSend, tTestCanRecv, tTestModbus; // pthread_create(&tTestLogger, NULL, testLoggerThread, "testLoggerThread"); // pthread_join(tTestLogger, NULL); // int ret = pthread_create(&tTestDIDetect, NULL, testDIDetectThread, "testDIDetectThread"); @@ -36,13 +37,42 @@ void testCreatThreadTask() // pthread_join(tTestTcp, NULL); // pthread_create(&tTest4G, NULL, test4GThread, "test4GThread"); // pthread_join(tTest4G, NULL); - pthread_create(&tTestCanSend, NULL, testCanSendThread, "testCanSendhread"); + pthread_create(&tTestCanSend, NULL, testCanSendThread, "testCanSendThread"); pthread_join(tTestCanSend, NULL); - // pthread_create(&tTestCanRecv, NULL, testCanRecvThread, "testCanRecvhread"); + // pthread_create(&tTestCanRecv, NULL, testCanRecvThread, "testCanRecvThread"); // pthread_join(tTestCanRecv, NULL); + pthread_create(&tTestModbus, NULL, testModbusThread, "testModbusThread"); + pthread_join(tTestModbus, NULL); logger_destroy(); } +// DI驱动测试 +void testDI() +{ + printf("test di\n"); + char value; + drv_di_read(DRV_DI1, &value); + printf("device[%s] value[%c]\n", DRV_DI1, value); +} + +// DO驱动测试 +void testDO() +{ + printf("test do\n"); + drv_do_write(DRV_LED1, DRV_DO_H); +} + +// Uart驱动测试 +void testUart() +{ + printf("test uart\n"); + int devFd = drv_uart_open(RS485_1, 9600, 8, 'N', '1'); + char test[100]="forlinx_uart_test.1234567890..."; + printf("Send test data:\n%s\n", test); + write(devFd, test, strlen(test) + 1); +} + + // Logger测试线程 void *testLoggerThread(void *arg) { @@ -99,33 +129,7 @@ void *testUartThread(void *arg) close(devFd); } -// DI驱动测试 -void testDI() -{ - printf("test di\n"); - char value; - drv_di_read(DRV_DI1, &value); - printf("device[%s] value[%c]\n", DRV_DI1, value); -} - -// DO驱动测试 -void testDO() -{ - printf("test do\n"); - drv_do_write(DRV_LED1, DRV_DO_H); -} - -// Uart驱动测试 -void testUart() -{ - printf("test uart\n"); - int devFd = drv_uart_open(RS485_1, 9600, 8, 'N', '1'); - char test[100]="forlinx_uart_test.1234567890..."; - printf("Send test data:\n%s\n", test); - write(devFd, test, strlen(test) + 1); -} - -//服务端功能测试 +//服务端功能测试线程 void *testTcpThread(void *arg) { logger_level_printf(LOGGER_DEBUG_LEVEL, arg); @@ -134,7 +138,7 @@ void *testTcpThread(void *arg) tcpServe(8888); } -//客户端功能测试 +//客户端功能测试线程 void *test4GThread(void *arg) { logger_level_printf(LOGGER_DEBUG_LEVEL, arg); @@ -142,7 +146,7 @@ void *test4GThread(void *arg) client(INTERFACE, SERVER_ADDR, PORT); } -//Can接收功能测试 +//Can接收功能测试线程 void *testCanRecvThread(void *arg) { logger_level_printf(LOGGER_DEBUG_LEVEL, arg); @@ -155,7 +159,7 @@ void *testCanRecvThread(void *arg) } } -//Can发送功能测试 +//Can发送功能测试线程 void *testCanSendThread(void *arg) { logger_level_printf(LOGGER_DEBUG_LEVEL, arg); @@ -167,5 +171,10 @@ void *testCanSendThread(void *arg) can_send(CANNUM_SEND, canID_send, can_send_data, CANDLC_SEND); sleep(1); } - +} + +//Modbus测试线程 +void *testModbusThread(void *arg) +{ + logger_level_printf(LOGGER_DEBUG_LEVEL, arg); } diff --git a/test/test.h b/test/test.h index 8fa8875..39fcf2a 100644 --- a/test/test.h +++ b/test/test.h @@ -13,4 +13,5 @@ void *testTcpThread(void *arg); void *test4GThread(void *arg); void *testCanSendThread(void *arg); void *testCanRecvThread(void *arg); +void *testModbusThread(void *arg); #endif