diff --git a/Changelog b/Changelog index 6d56a79..129e383 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,10 @@ +2022-05-30: +- display issues with signed and unsigned int16 in the values tab. + +- buildwindows will compile test-fc15 and test-fc16 command line tools. + +- adding to the test-fc16 some byte and word swapping mechanism + Initial Application: diff --git a/Makefile b/Makefile index db3b7c5..4d6c0c1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .SILENT: help -VERSION = 1.0.0 +VERSION = 1.0.1 APP = testmodbus-server -include Makefile.rules @@ -76,16 +76,18 @@ dep: $(CXX) -MM `ls *.cc` $(CXXFLAGS) > $(DEPENDFILE) test-fc16: test-fc16.cc - $(CPP) -o test-fc16 test-fc16.cc $(LDFLAGS) -I/usr/include -I/usr/local/include -L/usr/local/lib -L/usr/lib + $(CPP) -o test-fc16 test-fc16.cc tcp.cc $(LDFLAGS) test-fc15: test-fc15.cc - $(CPP) -o test-fc15 test-fc15.cc $(LDFLAGS) -I/usr/include -I/usr/local/include -L/usr/local/lib -L/usr/lib + $(CPP) -o test-fc15 test-fc15.cc tcp.cc $(LDFLAGS) buildwindows: clean make configcross make $(TARGET) -j 9 + make test-fc15 + make test-fc16 mkdir TestModbus-Server-$(VERSION) - cp testmodbus-server.exe TestModbus-Server-$(VERSION)/ + cp *.exe TestModbus-Server-$(VERSION)/ cp testmodbus-server.ui TestModbus-Server-$(VERSION)/ cp testmodbus-server.png TestModbus-Server-$(VERSION)/ cp README.md TestModbus-Server-$(VERSION)/ diff --git a/guimodbusdata.cc b/guimodbusdata.cc index 6130c96..57b1dec 100644 --- a/guimodbusdata.cc +++ b/guimodbusdata.cc @@ -175,7 +175,7 @@ void MBData_ChangeRegs (int fc, int regstart, int count, ModbusRegister *r) { model = gtk_tree_view_get_model(GTK_TREE_VIEW(mbdata)); for (i = 0; regstart < MAXREG && i < count; i++, regstart++) { - for (j = 0; j < 4; j++) value[3-j] = hex[(r[i].value >> j)%16]; + strncpy(value, to_hex16(r[i].value).c_str(), 16); path = std::to_string(fc-1) + ":" + std::to_string(regstart / STEPREG) + ":" + std::to_string(regstart % STEPREG); // printf ("fc:%d reg:%d val:%d enabled:%d requested:%d path:%s\n", fc, regstart, r[i].value, r[i].enabled, r[i].requested, path.c_str()); diff --git a/test-fc15.cc b/test-fc15.cc index 89ad133..3e9374c 100644 --- a/test-fc15.cc +++ b/test-fc15.cc @@ -4,7 +4,7 @@ // ///////////////////////////////////////////////////////////////////////////////// -#include +#include "tcp.h" #include #include diff --git a/test-fc16.cc b/test-fc16.cc index 7f93ef2..e642bd0 100644 --- a/test-fc16.cc +++ b/test-fc16.cc @@ -4,11 +4,28 @@ // ///////////////////////////////////////////////////////////////////////////////// -#include +#include "tcp.h" #include #include #define SIZE_BUFFER 4096 + +void swapbytes (unsigned char *p1, unsigned char *p2) { + unsigned char tmp; + tmp = *p2; + *p2 = *p1; + *p1 = tmp; +} + +void swapwords (unsigned char *p1, unsigned char *p2) { + uint16_t tmp; + + memcpy (&tmp, p2, 2); + memcpy (p2, p1, 2); + memcpy (p1, &tmp, 2); +} + + int main (int argc, char **argv) { unsigned char data[] = { 0x00,0x70,0x00,0x00 , 0x00,0x0B,0x01,0x10 , 0x00,0x04,0x00,0x02 , 0x04,0xC0,0x02,0x7B , @@ -27,9 +44,14 @@ int main (int argc, char **argv) { memset (buffer, 0x00, SIZE_BUFFER); - if (argc < 3) { - printf("test-fc16 server port register values...\n"); - printf("test-fc16 localhost 502 16 25.0 0.54 1000.5\n"); + if (argc < 6) { + printf ("%d\n", argc); + printf("test-fc16 server port register NOSWAP|WSWAP|BSWAP|BWSWAP values...\n"); + printf("test-fc16 localhost 502 16 NOSWAP 25.0 0.54 1000.5\n"); + printf (" NOSWAP no swapping words\n"); + printf (" WordSWAP swap the 16bit words\n"); + printf (" ByteSWAP swap the Bytes\n"); + printf (" WordByteSWAP swap the bytes and the words\n"); return 0; } @@ -43,9 +65,9 @@ int main (int argc, char **argv) { if (argc == 3) { tcp.Write((char*)data, sizeof(data)); } - else if (argc > 4) { + else if (argc > 5) { regstart = atoi (argv[3]); - regcnt = argc-4; + regcnt = argc-5; printf ("writing %d floats, offset %d\n", regcnt, regstart); @@ -93,7 +115,7 @@ int main (int argc, char **argv) { pos += sizeof(ui8); for (i = 0; i < regcnt; i++) { - f = (float) atof(argv[i+4]); + f = (float) atof(argv[i+5]); printf ("i: %d string:%s f:%f\n", i, argv[i+4], f); memcpy (&ui16, &f, sizeof(ui16)); @@ -105,6 +127,12 @@ int main (int argc, char **argv) { ui16 = htons(ui16); memcpy (buffer+pos, &ui16, sizeof(ui16)); pos += sizeof(ui16); + + if (strstr (argv[4], "Word") != NULL) swapwords((unsigned char*)buffer+pos-4, (unsigned char*)buffer+pos-2); + if (strstr (argv[4], "Byte") != NULL) { + swapbytes((unsigned char*)buffer+pos-4, (unsigned char*)buffer+pos-3); + swapbytes((unsigned char*)buffer+pos-2, (unsigned char*)buffer+pos-1); + } } tcp.Write((char*)buffer, pos);