[ADD] modbus thread

This commit is contained in:
xudx 2024-11-21 09:55:37 +08:00
parent bf9d6a823b
commit f4db785074
2 changed files with 44 additions and 34 deletions

View File

@ -9,6 +9,7 @@
#include "drv_can.h" #include "drv_can.h"
#include "drv_tcp.h" #include "drv_tcp.h"
#include "drv_4g.h" #include "drv_4g.h"
#include "libmodbus/include/modbus-rtu.h"
void runTest() void runTest()
{ {
@ -24,7 +25,7 @@ void testCreatThreadTask()
{ {
printf("testThreadTask\n"); printf("testThreadTask\n");
logger_init("./log"); 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_create(&tTestLogger, NULL, testLoggerThread, "testLoggerThread");
// pthread_join(tTestLogger, NULL); // pthread_join(tTestLogger, NULL);
// int ret = pthread_create(&tTestDIDetect, NULL, testDIDetectThread, "testDIDetectThread"); // int ret = pthread_create(&tTestDIDetect, NULL, testDIDetectThread, "testDIDetectThread");
@ -36,13 +37,42 @@ void testCreatThreadTask()
// pthread_join(tTestTcp, NULL); // pthread_join(tTestTcp, NULL);
// pthread_create(&tTest4G, NULL, test4GThread, "test4GThread"); // pthread_create(&tTest4G, NULL, test4GThread, "test4GThread");
// pthread_join(tTest4G, NULL); // pthread_join(tTest4G, NULL);
pthread_create(&tTestCanSend, NULL, testCanSendThread, "testCanSendhread"); pthread_create(&tTestCanSend, NULL, testCanSendThread, "testCanSendThread");
pthread_join(tTestCanSend, NULL); pthread_join(tTestCanSend, NULL);
// pthread_create(&tTestCanRecv, NULL, testCanRecvThread, "testCanRecvhread"); // pthread_create(&tTestCanRecv, NULL, testCanRecvThread, "testCanRecvThread");
// pthread_join(tTestCanRecv, NULL); // pthread_join(tTestCanRecv, NULL);
pthread_create(&tTestModbus, NULL, testModbusThread, "testModbusThread");
pthread_join(tTestModbus, NULL);
logger_destroy(); 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测试线程 // Logger测试线程
void *testLoggerThread(void *arg) void *testLoggerThread(void *arg)
{ {
@ -99,33 +129,7 @@ void *testUartThread(void *arg)
close(devFd); 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) void *testTcpThread(void *arg)
{ {
logger_level_printf(LOGGER_DEBUG_LEVEL, arg); logger_level_printf(LOGGER_DEBUG_LEVEL, arg);
@ -134,7 +138,7 @@ void *testTcpThread(void *arg)
tcpServe(8888); tcpServe(8888);
} }
//客户端功能测试 //客户端功能测试线程
void *test4GThread(void *arg) void *test4GThread(void *arg)
{ {
logger_level_printf(LOGGER_DEBUG_LEVEL, arg); logger_level_printf(LOGGER_DEBUG_LEVEL, arg);
@ -142,7 +146,7 @@ void *test4GThread(void *arg)
client(INTERFACE, SERVER_ADDR, PORT); client(INTERFACE, SERVER_ADDR, PORT);
} }
//Can接收功能测试 //Can接收功能测试线程
void *testCanRecvThread(void *arg) void *testCanRecvThread(void *arg)
{ {
logger_level_printf(LOGGER_DEBUG_LEVEL, arg); logger_level_printf(LOGGER_DEBUG_LEVEL, arg);
@ -155,7 +159,7 @@ void *testCanRecvThread(void *arg)
} }
} }
//Can发送功能测试 //Can发送功能测试线程
void *testCanSendThread(void *arg) void *testCanSendThread(void *arg)
{ {
logger_level_printf(LOGGER_DEBUG_LEVEL, 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); can_send(CANNUM_SEND, canID_send, can_send_data, CANDLC_SEND);
sleep(1); sleep(1);
} }
}
//Modbus测试线程
void *testModbusThread(void *arg)
{
logger_level_printf(LOGGER_DEBUG_LEVEL, arg);
} }

View File

@ -13,4 +13,5 @@ void *testTcpThread(void *arg);
void *test4GThread(void *arg); void *test4GThread(void *arg);
void *testCanSendThread(void *arg); void *testCanSendThread(void *arg);
void *testCanRecvThread(void *arg); void *testCanRecvThread(void *arg);
void *testModbusThread(void *arg);
#endif #endif