-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3484da0
commit 6e29e6a
Showing
41 changed files
with
4,624 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[submodule "nanoMODBUS"] | ||
path = nanoMODBUS | ||
url = https://github.com/debevv/nanoMODBUS | ||
[submodule "openssl_3.2"] | ||
path = openssl_3.2 | ||
url = https://github.com/openssl/openssl | ||
branch = openssl-3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"${workspaceFolder}/**", | ||
"${workspaceFolder}/mqtt/**", | ||
"${workspaceFolder}/nanoMODBUS/**", | ||
"${workspaceFolder}/openssl-openssl-3.3.1/**", | ||
"${workspaceFolder}/mqtt/MQTTPacket" | ||
], | ||
"defines": [], | ||
"compilerPath": "/usr/bin/gcc", | ||
"cStandard": "c17", | ||
"cppStandard": "gnu++17", | ||
"intelliSenseMode": "linux-gcc-x64", | ||
"configurationProvider": "ms-vscode.makefile-tools" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "(gdb) Launch", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/main", | ||
"args": [], | ||
"stopAtEntry": false, | ||
"cwd": "${fileDirname}", | ||
"environment": [], | ||
"externalConsole": false, | ||
}, | ||
{ | ||
"name": "Debug C Program", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/main", // Path to the compiled executable | ||
"args": [], // Arguments to pass to the program | ||
"stopAtEntry": false, // Set to true to stop at main() | ||
"cwd": "${workspaceFolder}", // Current working directory | ||
"environment": [], | ||
"externalConsole": false, // If true, opens an external console | ||
"MIMode": "gdb", // Debugger type, could be "gdb" or "lldb" | ||
"setupCommands": [ | ||
{ | ||
"description": "Enable pretty-printing for gdb", | ||
"text": "-enable-pretty-printing", | ||
"ignoreFailures": true | ||
} | ||
], | ||
"preLaunchTask": "build", // Task to run before launching the debugger | ||
"miDebuggerPath": "/usr/bin/gdb", // Path to the debugger | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"files.associations": { | ||
"ssl.h": "c", | ||
"bio.h": "c", | ||
"stdio.h": "c", | ||
"e_os2.h": "c", | ||
"err.h": "c", | ||
"modbus_task.h": "c", | ||
"stdlib.h": "c", | ||
"mqttclient.h": "c", | ||
"mqttinterface.h": "c", | ||
"mqtt_task.h": "c", | ||
"*.inc": "c", | ||
"array": "c", | ||
"string": "c", | ||
"string_view": "c", | ||
"string.h": "c", | ||
"pthread.h": "c", | ||
"nanomodbus.h": "c", | ||
"initializer_list": "c", | ||
"utility": "c" | ||
}, | ||
"cmake.sourceDirectory": "/home/federico/git/qubip-mqtt-linux-client-openssl/nanoMODBUS" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"type": "shell", | ||
"command": "make", | ||
"args": [], | ||
"group": "build", | ||
"problemMatcher": [ | ||
"$gcc" | ||
], | ||
"detail": "Generated task for building the C program using make" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Target executable | ||
TARGET := main | ||
|
||
# Compiler and flags | ||
CC := gcc | ||
CFLAGS := -Wall -Wextra -pedantic -g -pthread | ||
|
||
# Path to OpenSSL header files | ||
CFLAGS += -Iopenssl-3.2.2/ -Imqtt/ -Imqtt/MQTTPacket/ | ||
|
||
# Percorso agli header files di nanoModbus | ||
CFLAGS += -InanoMODBUS/ | ||
|
||
# Libraries | ||
LIBS := -lstdc++ -Lopenssl-3.2.2 -lssl -lcrypto | ||
|
||
# Source files | ||
#SRCS := main.c modbus_task.c mqtt_task.c nanoMODBUS/nanomodbus.c utilis.c mqtt/MQTTInterface.c mqtt/MQTTClient.c | ||
SRCS := $(wildcard *.c nanoMODBUS/*.c mqtt/*.c mqtt/MQTTPacket/*.c) | ||
|
||
# Object files | ||
OBJS := $(SRCS:.c=.o) | ||
|
||
# Default target | ||
all: $(TARGET) | ||
|
||
# Build the target | ||
$(TARGET): $(OBJS) | ||
$(CC) $(CFLAGS) $^ -o $@ $(LIBS) | ||
|
||
# Compile source files into object files | ||
%.o: %.c | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
# Clean up | ||
clean: | ||
rm -f $(TARGET) $(OBJS) | ||
|
||
.PHONY: all clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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F+ofKiARh4FsAlpxiTuC2RGYr/9TYRHJn1a3eCWc1+SNQBK8e | ||
F2z6NbPZX1Ow32TU0KOjXaZ3im0lQLTBUNlymrXup/7P4eIuexQY8+BzQXLIw+DY | ||
KAwcNnBcDtEc/I3uLzrF1LsYGZbJ8lElxjY13l2TzkAvonO90ZXMZSmWpssLW7k4 | ||
z81M5G1nHW10HNzukG1nrahcZMHsq9bxM86yA4k/0eIINxbxhByTNMYhq6744BDh | ||
bBeMGN3kxMWs | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDhDCCAmygAwIBAgIUc+vC6JB/wiRlgXzEyCM31gLDFOowDQYJKoZIhvcNAQEL | ||
BQAwWjELMAkGA1UEBhMCaXQxCzAJBgNVBAgMAmFsMQswCQYDVQQHDAJ0cDELMAkG | ||
A1UECgwCc2YxCzAJBgNVBAsMAmViMRcwFQYDVQQDDA4xOTIuMTY4LjEwMS42MzAe | ||
Fw0yNDA3MTAxMzE5NTVaFw0yNTA3MTAxMzE5NTVaMFoxCzAJBgNVBAYTAml0MQsw | ||
CQYDVQQIDAJhbDELMAkGA1UEBwwCdG8xCzAJBgNVBAoMAnNmMQswCQYDVQQLDAJl | ||
YjEXMBUGA1UEAwwOMTkyLjE2OC4xMDEuNjMwggEiMA0GCSqGSIb3DQEBAQUAA4IB | ||
DwAwggEKAoIBAQC+edJqS8QecC0Q/+dR4h/89oSzhT9U7Es1DPYLFXekKz70T30n | ||
qWZTBvIhGtmS6ZeDkjDIpQDf50KgqsPlHI84KNEPrcB3ZGlmvmUIvDILTIuSDWAF | ||
WpO1ovRbwmU5GDqWWw4qMCT0QdvYbtbHkmMDyJ3x1gFtDejsXggFrlfvTvAJx/AH | ||
lXytCsXpsCn+3+N2kXhABR3K7k/jMo60D924hi/980drYrwLxpKuV6+QFgpTAoZ4 | ||
aabwu4os6BdrS0O9IEzi7GADs0AlA8ewNTVjNqqUDgTzC7XdaMg4fwJsB9IKiLGZ | ||
qzAWxyT6pxiGj8Ji8Y0zJHAKZW0sdzcIiwBdAgMBAAGjQjBAMB0GA1UdDgQWBBQ+ | ||
tgdM1sGHb+WtGBAxo+Suc8sXqjAfBgNVHSMEGDAWgBSHHm+ISZlaDqa8FSoix0SL | ||
xdePVzANBgkqhkiG9w0BAQsFAAOCAQEAJ95diL7bnVOs2KCQbzv5SYyAUxuLLdBm | ||
JUAbi4RNrFeHmgdiHIeAGXamlxZglAn8ovdp06DRNdMZRkG9kN3L+mnh4TIH7cUu | ||
NbzBFzwkNcEdavyRn3lzjWXLQYtS+ixry1kUJ5rVPKFsuR9pRf19Wjd+ZWX0GO9Z | ||
HdZ0QkSPosleYtHn0TKexs7+P+1x8vtI86cmiZPwn02tGh1OpTkvKmenzRxWw7m+ | ||
4YHwSump5LqkFyk+N+DnITXwJBn+l9RdZ2b1hVww1L/jlLAT1fxi+7FxFp2nZbwF | ||
jasYJBVqhNm7As4Z85JGBjZI7HPwMXM2n1Aw5vV8s8W7DK+qJ+17og== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC+edJqS8QecC0Q | ||
/+dR4h/89oSzhT9U7Es1DPYLFXekKz70T30nqWZTBvIhGtmS6ZeDkjDIpQDf50Kg | ||
qsPlHI84KNEPrcB3ZGlmvmUIvDILTIuSDWAFWpO1ovRbwmU5GDqWWw4qMCT0QdvY | ||
btbHkmMDyJ3x1gFtDejsXggFrlfvTvAJx/AHl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VfUgAY6FxiuEg7tpoEgC/3MLkx77vbMbo0b3wKBgGEU | ||
VRIbQDnSNAqQWvxJuuRHGYmfyfiHh87kZ7oJYwUh62HpqyxRqYK61udkaHFLtFPo | ||
OeXBTG9OWwn3WeSnPri7gM7DClPcSxSkltzyzLo+DVfybInncc1E14LJmLugCUn/ | ||
JfF+uqve6ebJYbRMmYthnQHEBPR/ZOqrdGZi5LrHAoGAOxjXBJr9m7OWtWc6QCv2 | ||
ZJ+Fjiuxr60KGBwjK3Fgeo2AsDpP72wtEBFKjCQijbJLHm1bhUvw8ray8qO/81ox | ||
6H3gcyUul76LlfHPpKOa/IV7F5R6GvvkQyxerJkOBsJ7UNg3lJ66JJEbQMoA7we5 | ||
jPOMOOrhlRIhcb7des6DPgU= | ||
-----END PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef __CONFIG_H__ | ||
#define __CONFIG_H__ | ||
|
||
// #define MOBBUS_PLC_IP "192.168.101.212" | ||
#define MOBBUS_PLC_IP "192.168.168.133" | ||
//#define MODBUS_PLC_PORT "502" | ||
#define MODBUS_PLC_PORT "5002" | ||
//#define MODBUS_PLC_REGISTER (32770) | ||
#define MODBUS_PLC_REGISTER (10) | ||
|
||
#define MQTT_BROKER_IP "192.168.101.63" | ||
#define MQTT_BROKER_PORT "1883" | ||
|
||
#define MQTT_TOPIC "2023/test" | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
Include mqtt lib | ||
include openssl lib | ||
fd -> openssl -> mqtt | ||
mqtt -> openssl -> fd | ||
init | ||
deinit | ||
connenct | ||
disconnect | ||
write | ||
read | ||
*/ | ||
|
||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <signal.h> | ||
#include <stdarg.h> | ||
#include "config.h" | ||
#include "modbus_task.h" | ||
#include "mqtt_task.h" | ||
|
||
void init_signals(void); | ||
static void signal_handler(int); | ||
static void cleanup(void); | ||
void panic(const char *, ...); | ||
struct sigaction sigact; | ||
|
||
int main() | ||
{ | ||
pthread_t modbus_thread = 0; | ||
pthread_t mqtt_sub_thread = 0; | ||
pthread_t mqtt_pub_thread = 0; | ||
int ret = 0; | ||
|
||
atexit(cleanup); | ||
init_signals(); | ||
|
||
// Create threads | ||
|
||
// MODBUS TCP thread | ||
modbus_task_config_t modbus_config = {MOBBUS_PLC_IP, MODBUS_PLC_PORT, MODBUS_PLC_REGISTER}; | ||
|
||
ret = pthread_create(&modbus_thread, NULL, modbus_task, (void *)&modbus_config); | ||
if (ret != 0) | ||
{ | ||
fprintf(stderr, "Error in creating modbus thread\n"); | ||
return -1; | ||
} | ||
|
||
// MQTT thread | ||
mqtt_config_t mqtt_config = {MQTT_BROKER_IP, MQTT_BROKER_PORT}; | ||
|
||
ret = pthread_create(&mqtt_sub_thread, NULL, mqtt_sub_task, (void *)&mqtt_config); | ||
if (ret != 0) | ||
{ | ||
fprintf(stderr, "Error in creating mqtt sub thread\n"); | ||
return -1; | ||
} | ||
|
||
ret = pthread_create(&mqtt_pub_thread, NULL, mqtt_pub_task, (void *)&mqtt_config); | ||
if (ret != 0) | ||
{ | ||
fprintf(stderr, "Error in creating mqtt pub thread\n"); | ||
return -1; | ||
} | ||
|
||
// Wait till threads are complete before main continues. | ||
pthread_join(modbus_thread, NULL); | ||
pthread_join(mqtt_sub_thread, NULL); | ||
pthread_join(mqtt_pub_thread, NULL); | ||
|
||
return 0; | ||
} | ||
|
||
void init_signals(void) | ||
{ | ||
sigact.sa_handler = signal_handler; | ||
sigemptyset(&sigact.sa_mask); | ||
sigact.sa_flags = 0; | ||
sigaction(SIGINT, &sigact, (struct sigaction *)NULL); | ||
} | ||
|
||
static void signal_handler(int sig) | ||
{ | ||
switch (sig) | ||
{ | ||
case SIGINT: | ||
panic("\nCaught signal for Ctrl+C\n"); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
void panic(const char *fmt, ...) | ||
{ | ||
char buf[150]; | ||
va_list argptr; | ||
va_start(argptr, fmt); | ||
vsprintf(buf, fmt, argptr); | ||
va_end(argptr); | ||
fprintf(stderr, "%s", buf); | ||
exit(-1); | ||
} | ||
|
||
void cleanup(void) | ||
{ | ||
sigemptyset(&sigact.sa_mask); | ||
/* Do any cleaning up chores here */ | ||
} |
Oops, something went wrong.