preparation for testmodbus-client

master
Steffen Pohle 2 years ago
parent b1577fbdab
commit 018d96efb6

@ -1,17 +1,18 @@
.SILENT: help .SILENT: help
VERSION = 1.0.1 VERSION = 1.0.1
APP = testmodbus-server
-include Makefile.rules -include Makefile.rules
OBJECTS = gui.oo server.oo mbsconfig.oo modbus.oo guimodbusdata.oo guivalues.oo json.oo tcp.oo OBJECTSSRV = gui.oo server.oo mbsconfig.oo modbussrv.oo guimodbusdata.oo guivalues.oo json.oo tcp.oo
OBJECTSCLI = client.oo tcp.oo
DISTNAME=testmodbus-server-$(VERSION) DISTNAME=testmodbus-server-$(VERSION)
ifeq ($(TARGET),) ifeq ($(CONFIGSET),)
noconfig: help noconfig: help
endif endif
all: Makefile.rules $(TARGET) all: Makefile.rules testmodbus-server$(TARGETEXT) testmodbus-client$(TARGETEXT)
help: help:
echo "set up configuration" echo "set up configuration"
@ -41,8 +42,11 @@ config: Makefile.rules
echo "#endif" >> config.h echo "#endif" >> config.h
$(TARGET): $(OBJECTS) testmodbus-server$(TARGETEXT): $(OBJECTSSRV)
$(CPP) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(LIBS) $(CPP) -o testmodbus-server$(TARGETEXT) $(OBJECTSSRV) $(LDFLAGS) $(LIBS)
testmodbus-client$(TARGETEXT): $(OBJECTSCLI)
$(CPP) -o testmodbus-client$(TARGETEXT) $(OBJECTSCLI) $(LDFLAGS) $(LIBS)
.SUFFIXES: .SUFFIXES:
.SUFFIXES: .c .cc .C .cpp .oo .SUFFIXES: .c .cc .C .cpp .oo
@ -52,7 +56,7 @@ $(TARGET): $(OBJECTS)
clean: clean:
rm -rf TestModbus-Server-$(VERSION)/ rm -rf TestModbus-Server-$(VERSION)/
rm -f *.o *.oo *.c~ *.h~ *.cc~ *.ui~ $(APP) Makefile~ rm -f *.o *.oo *.c~ *.h~ *.cc~ *.ui~ testmodbus-server$(TARGETEXT) testmodbus-client$(TARGETEXT) Makefile~
rm -rf *.dll rm -rf *.dll
rm -rf *.exe rm -rf *.exe
rm -rf Makefile.rules rm -rf Makefile.rules
@ -95,6 +99,9 @@ buildwindows: clean
cp Changelog TestModbus-Server-$(VERSION)/ cp Changelog TestModbus-Server-$(VERSION)/
cp LICENSE TestModbus-Server-$(VERSION)/ cp LICENSE TestModbus-Server-$(VERSION)/
./copydlls.sh ./copydlls.sh
./copydlls.sh
./copydlls.sh
./copydlls.sh
./copyshare.sh ./copyshare.sh
mv *.dll TestModbus-Server-$(VERSION)/ mv *.dll TestModbus-Server-$(VERSION)/
mv share TestModbus-Server-$(VERSION)/ mv share TestModbus-Server-$(VERSION)/

@ -1,5 +1,6 @@
TARGET = $(APP).exe TARGETEXT = .exe
CONFIGSET = YES
CROSSENV = /opt/W64-cross-compile/ CROSSENV = /opt/W64-cross-compile/
CPP = /usr/bin/x86_64-w64-mingw32-g++ CPP = /usr/bin/x86_64-w64-mingw32-g++
CPPFLAGS = -ggdb -Wall -O0 `PKG_CONFIG_PATH=$(CROSSENV)/lib/pkgconfig pkg-config --cflags gtk+-3.0 gmodule-export-2.0` -Wl,--export-dynamic -DBUILD_WINDOWS=1 -Wdeprecated CPPFLAGS = -ggdb -Wall -O0 `PKG_CONFIG_PATH=$(CROSSENV)/lib/pkgconfig pkg-config --cflags gtk+-3.0 gmodule-export-2.0` -Wl,--export-dynamic -DBUILD_WINDOWS=1 -Wdeprecated

@ -1,6 +1,6 @@
TARGET = $(APP) TARGETEXT =
CONFIGSET = YES
CPP = c++ CPP = c++
CPPFLAGS = -ggdb -Wall -O0 `pkg-config --cflags gtk+-3.0 gmodule-export-2.0` -Wl,--export-dynamic -I/usr/include -DBUILD_LINUX=1 CPPFLAGS = -ggdb -Wall -O0 `pkg-config --cflags gtk+-3.0 gmodule-export-2.0` -Wl,--export-dynamic -I/usr/include -DBUILD_LINUX=1
INCLUDES = INCLUDES =

@ -1,6 +1,6 @@
TARGET = $(APP).exe TARGETEXT = .exe
CONFIGSET = YES
CPP = g++ CPP = g++
CPPFLAGS = -ggdb -Wall -O0 `pkg-config --cflags gtk+-3.0 gmodule-export-2.0` -Wl,--export-dynamic -I/usr/include -DBUILD_WINDOWS=1 CPPFLAGS = -ggdb -Wall -O0 `pkg-config --cflags gtk+-3.0 gmodule-export-2.0` -Wl,--export-dynamic -I/usr/include -DBUILD_WINDOWS=1
INCLUDES = INCLUDES =

@ -0,0 +1,54 @@
#include <sys/time.h>
#include "config.h"
#include "gui.h"
#define BUILDER_FILE "testmodbus-client.ui"
/************************************************************************************
* Global Variables
*/
ModbusCli modbuscli;
GtkBuilder *_builder_ = NULL; // work around for the thread situation
gboolean modbuscli_callback(gpointer data);
int main (int argc, char **argv) {
GtkBuilder *builder;
GObject *window;
#ifdef BUILD_WINDOWS
char buffer[16];
setvbuf (stdout, buffer, _IONBF, 16);
#endif
printf ("TestModbus-Client - %s\n", VERSION);
printf (" https://steffen.gulpe.de/modbus-tcpip\n");
printf (" written by Steffen Pohle <steffen@gulpe.de>\n");
gtk_init (&argc, &argv);
_builder_ = builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, BUILDER_FILE, NULL);
gtk_builder_connect_signals(builder, builder);
//
// #if defined _WIN32 || defined _WIN64 || defined __CYGWIN__
// #else
// #endif
//
// modbuscli.SetCallback(&modbus_callback);
window = gtk_builder_get_object (builder, "testmodbus-client");
gtk_widget_show_all (GTK_WIDGET(window));
gtk_main ();
return 0;
}
gboolean modbuscli_callback(gpointer data) {
struct modbus_callback_data *mdata = (struct modbus_callback_data *) data;
free (mdata);
return FALSE;
};

@ -35,4 +35,5 @@ copy_dependency() {
} }
copy_dependency testmodbus-server.exe copy_dependency testmodbus-server.exe
copy_dependency testmodbus-client.exe

@ -11,7 +11,7 @@
#include <stdio.h> #include <stdio.h>
#include <list> #include <list>
#include "gui.h" #include "gui.h"
#include "modbus.h" #include "modbussrv.h"
#include "guivalues.h" #include "guivalues.h"
#include "json.h" #include "json.h"
#include "mbsconfig.h" #include "mbsconfig.h"

@ -15,8 +15,6 @@
#include <iostream> #include <iostream>
#include <list> #include <list>
#define BUILDER_FILE "testmodbus-server.ui"
#include "guivalues.h" #include "guivalues.h"
#include "guimodbusdata.h" #include "guimodbusdata.h"
std::string to_hex16 (int v); std::string to_hex16 (int v);

@ -12,7 +12,7 @@
#include "gui.h" #include "gui.h"
#include "guimodbusdata.h" #include "guimodbusdata.h"
#include "modbus.h" #include "modbussrv.h"
extern ModbusSrv modbussrv; extern ModbusSrv modbussrv;

@ -8,7 +8,7 @@
#define _GUIMODBUSDATA_H_ #define _GUIMODBUSDATA_H_
#include "gui.h" #include "gui.h"
#include "modbus.h" #include "modbussrv.h"
#include "guivalues.h" #include "guivalues.h"
enum { enum {

@ -16,7 +16,7 @@
#include "gui.h" #include "gui.h"
#include "config.h" #include "config.h"
#include "mbsconfig.h" #include "mbsconfig.h"
#include "modbus.h" #include "modbussrv.h"
#include "guivalues.h" #include "guivalues.h"
void Value_ModStore(GtkTreeModel *model, GtkTreeIter *iter, GuiValue *g); void Value_ModStore(GtkTreeModel *model, GtkTreeIter *iter, GuiValue *g);

@ -8,7 +8,7 @@
#define _GUIVALUE_H_ #define _GUIVALUE_H_
#include "gui.h" #include "gui.h"
#include "modbus.h" #include "modbussrv.h"
#include <string> #include <string>
enum { enum {

@ -12,7 +12,7 @@
#define _MBDCONFIG_H_ #define _MBDCONFIG_H_
#include "config.h" #include "config.h"
#include "modbus.h" #include "modbussrv.h"
#include <string> #include <string>
// maybe soon internationalisation // maybe soon internationalisation

@ -6,16 +6,47 @@
#include <errno.h> #include <errno.h>
#include <glib.h> #include <glib.h>
#include <sys/time.h>
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#else #else
#include <unistd.h> /* close() */ #include <unistd.h> /* close() */
#endif #endif
#include "gui.h" #include "gui.h"
#include "modbus.h" #include "modbussrv.h"
#include "mbsconfig.h" #include "mbsconfig.h"
#include "config.h" #include "config.h"
std::string to_hex16 (int v) {
char HEX[] = "0123456789ABCDEF";
int i = v;
int n;
std::string txt = "";
for (n = 0; n < 4; n++) {
txt = HEX[i%16]+ txt;
i = i / 16;
}
return txt;
}
float get_cycletime(struct timeval *t) {
struct timeval t1;
float f = 0.0;
t1 = *t;
gettimeofday(t, NULL);
f = (float)(t->tv_sec - t1.tv_sec) + ((t->tv_usec - t1.tv_usec) / 1000000.0);
return f;
}
// //
// C / C++ Wrapper // C / C++ Wrapper
gpointer _ServerThread (gpointer data) { gpointer _ServerThread (gpointer data) {

@ -45,6 +45,7 @@ struct modbus_data {
// return the cycletime in us // return the cycletime in us
std::string to_hex16 (int v);
float get_cycletime(struct timeval *t); float get_cycletime(struct timeval *t);
struct { struct {
@ -106,6 +107,15 @@ public:
int isRunning(); int isRunning();
}; };
class ModbusCli {
private:
public:
ModbusCli() {};
~ModbusCli() {};
};
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#define usleep(_us_) Sleep(_us_/1000) #define usleep(_us_) Sleep(_us_/1000)
#endif #endif

@ -4,18 +4,18 @@
// //
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
#include <sys/time.h>
#include "config.h" #include "config.h"
#include "mbsconfig.h" #include "mbsconfig.h"
#include "gui.h" #include "gui.h"
#include "modbus.h" #include "modbussrv.h"
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
// //
// global variables // global variables
// //
#define BUILDER_FILE "testmodbus-server.ui"
Config config; Config config;
ModbusSrv modbussrv; ModbusSrv modbussrv;
GtkBuilder *_builder_ = NULL; // work around for the thread situation GtkBuilder *_builder_ = NULL; // work around for the thread situation
@ -67,20 +67,6 @@ int main (int argc, char **argv) {
return 0; return 0;
} }
string to_hex16 (int v) {
char HEX[] = "0123456789ABCDEF";
int i = v;
int n;
string txt = "";
for (n = 0; n < 4; n++) {
txt = HEX[i%16]+ txt;
i = i / 16;
}
return txt;
}
gboolean modbus_callback(gpointer data) { gboolean modbus_callback(gpointer data) {
struct modbus_callback_data *mdata = (struct modbus_callback_data *) data; struct modbus_callback_data *mdata = (struct modbus_callback_data *) data;
@ -93,15 +79,3 @@ gboolean modbus_callback(gpointer data) {
return FALSE; return FALSE;
}; };
float get_cycletime(struct timeval *t) {
struct timeval t1;
float f = 0.0;
t1 = *t;
gettimeofday(t, NULL);
f = (float)(t->tv_sec - t1.tv_sec) + ((t->tv_usec - t1.tv_usec) / 1000000.0);
return f;
}

@ -0,0 +1,288 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="testmodbus-client">
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">4</property>
<property name="margin-end">4</property>
<property name="margin-top">4</property>
<property name="margin-bottom">4</property>
<property name="label-xalign">0</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="left-padding">12</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Host:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="cli_host">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="text" translatable="yes">localhost</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Port:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="cli_port">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">6</property>
<property name="text" translatable="yes">502</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Refresh [ms]:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">4</property>
<property name="text" translatable="yes">1000</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkCheckButton" id="cli_cb_reconnect">
<property name="label" translatable="yes">Auto Reconnect</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="active">True</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="cli_cb_readonly">
<property name="label" translatable="yes">Read Only</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="active">True</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<child>
<object class="GtkButton" id="cli_btnConnect">
<property name="label">gtk-connect</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="cli_btnClose">
<property name="label">gtk-disconnect</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">last error | status</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Destination Host</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</interface>
Loading…
Cancel
Save