UART interceptor now is compatible with Whireshark

This commit is contained in:
2021-06-07 15:44:39 +03:00
parent 5eae1b1838
commit 2f398df8aa
6 changed files with 91 additions and 29 deletions

View File

@@ -16,10 +16,11 @@
#-DPID_DISABLE #-DPID_DISABLE
#Define pins for Serial1. Default - 9/10 is utilized by ESP flash #Define pins for Serial1. Default - 9/10 is utilized by ESP flash
#-DRX1=15 #-DMODBUS_UART_RX_PIN=15
#-DTX1=2 #-DMODBUS_UART_TX_PIN=2
#-DmodbusSerial=Serial1
-DMODBUS_UART_RX_PIN=15 # Use default pins
-DMODBUS_UART_TX_PIN=2 -DMODBUS_UART_RX_PIN=-1
-DmodbusSerial=Serial1 -DMODBUS_UART_TX_PIN=-1

View File

@@ -211,6 +211,8 @@ enum lan_status {
DO_NOTHING = -15 DO_NOTHING = -15
}; };
extern lan_status lanStatus;
typedef union { typedef union {
uint32_t UID_Long[5]; uint32_t UID_Long[5];
uint8_t UID_Byte[20]; uint8_t UID_Byte[20];

View File

@@ -31,6 +31,7 @@
#if defined (ARDUINO_ARCH_ESP32) #if defined (ARDUINO_ARCH_ESP32)
#undef WAK_PIN #undef WAK_PIN
#undef SCL_RESET
//#ifndef WAK_PIN //#ifndef WAK_PIN
//#define WAK_PIN 17 //#define WAK_PIN 17
//#endif //#endif

View File

@@ -11,6 +11,22 @@
#include "main.h" #include "main.h"
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include "main.h"
#if defined (ESP32)
#include <AsyncUDP.h>
AsyncUDP udp;
AsyncUDPMessage udpMessageA;
AsyncUDPMessage udpMessageB;
IPAddress targetIP;
uint16_t targetPort=5555;
#endif
uint32_t timerA = 0;
uint32_t timerB = 0;
extern aJsonObject *modbusObj; extern aJsonObject *modbusObj;
extern ModbusMaster node; extern ModbusMaster node;
extern short modbusBusy; extern short modbusBusy;
@@ -88,6 +104,14 @@ bool out_UARTbridge::getConfig()
MODULE_UATRBRIDGE_UARTB.begin(store->baud, (store->serialParam)); MODULE_UATRBRIDGE_UARTB.begin(store->baud, (store->serialParam));
#endif #endif
aJsonObject * debugIPObj=aJson.getObjectItem(item->itemArg, "ip");
aJsonObject * debugPortObj=aJson.getObjectItem(item->itemArg, "port");
if (debugIPObj)
inet_aton(debugIPObj->valuestring, targetIP);
if (debugPortObj) targetPort = debugPortObj->valueint;
return true; return true;
} }
@@ -95,6 +119,7 @@ bool out_UARTbridge::getConfig()
int out_UARTbridge::Setup() int out_UARTbridge::Setup()
{ {
abstractOut::Setup(); abstractOut::Setup();
if (!store) store= (ubPersistent *)item->setPersistent(new ubPersistent); if (!store) store= (ubPersistent *)item->setPersistent(new ubPersistent);
if (!store) if (!store)
{ errorSerial<<F("UARTbridge: Out of memory")<<endl; { errorSerial<<F("UARTbridge: Out of memory")<<endl;
@@ -134,22 +159,60 @@ return CST_UNKNOWN;
int out_UARTbridge::Poll(short cause) int out_UARTbridge::Poll(short cause)
{ {
int chA; uint8_t chA;
int chB; uint8_t chB;
while (MODULE_UATRBRIDGE_UARTA.available()) if ((lanStatus>=HAVE_IP_ADDRESS) && udpMessageA.length() && (isTimeOver(timerA,millis(),PDELAY) || timerB))
{
udp.sendTo(udpMessageA,targetIP,targetPort);
udpMessageA.flush();
debugSerial<<endl;
timerA=0;
}
if ((lanStatus>=HAVE_IP_ADDRESS) && udpMessageB.length() && (isTimeOver(timerB,millis(),PDELAY) || timerA))
{
udp.sendTo(udpMessageB,targetIP,targetPort);
udpMessageB.flush();
debugSerial<<endl;
timerB=0;
}
while (MODULE_UATRBRIDGE_UARTA.available() || MODULE_UATRBRIDGE_UARTB.available())
{ {
chA=MODULE_UATRBRIDGE_UARTA.read();
MODULE_UATRBRIDGE_UARTB.write(chA);
debugSerial<<F("<")<<_HEX(chA);
}
if (MODULE_UATRBRIDGE_UARTA.available())
{
timerA=millisNZ();
if (timerB) return 1;
chA=MODULE_UATRBRIDGE_UARTA.read();
MODULE_UATRBRIDGE_UARTB.write(chA);
debugSerial<<F("<")<<((chA<16)?"0":"")<<_HEX(chA);
udpMessageA.write(chA);
}
if (MODULE_UATRBRIDGE_UARTB.available())
{
timerB=millisNZ();
if (timerA) return 1;
chB=MODULE_UATRBRIDGE_UARTB.read();
MODULE_UATRBRIDGE_UARTA.write(chB);
debugSerial<<F(">")<<((chB<16)?"0":"")<<_HEX(chB);
udpMessageB.write(chB);
}
}
/*
while (MODULE_UATRBRIDGE_UARTB.available()) while (MODULE_UATRBRIDGE_UARTB.available())
{ {
chB=MODULE_UATRBRIDGE_UARTB.read(); chB=MODULE_UATRBRIDGE_UARTB.read();
MODULE_UATRBRIDGE_UARTA.write(chB); MODULE_UATRBRIDGE_UARTA.write(chB);
debugSerial<<F(">")<<_HEX(chB); debugSerial<<F(">")<<((chB<10)?"0":"")<<_HEX(chB);
udpMessageB.write(chB);
timerB=millisNZ();
} }
*/
return 1;//store->pollingInterval; return 1;//store->pollingInterval;
}; };

View File

@@ -50,7 +50,7 @@ public:
//aJsonObject * parameters; //aJsonObject * parameters;
}; };
#define PDELAY 50
class out_UARTbridge : public abstractOut { class out_UARTbridge : public abstractOut {
public: public:

View File

@@ -1,6 +1,14 @@
// Configuration of drivers enabled // Configuration of drivers enabled
#define SYSLOG_LOCAL_SOCKET 514 #define SYSLOG_LOCAL_SOCKET 514
#ifndef MODBUS_UART_RX_PIN
#define MODBUS_RX_PIN -1
#endif
#ifndef MODBUS_UART_TX_PIN
#define MODBUS_TX_PIN -1
#endif
#ifndef FASTLED #ifndef FASTLED
#define ADAFRUIT_LED #define ADAFRUIT_LED
#endif #endif
@@ -194,7 +202,6 @@
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
#undef _dmxin #undef _dmxin
//#undef _modbus
#ifndef DMX_DISABLE #ifndef DMX_DISABLE
#define _espdmx #define _espdmx
@@ -212,13 +219,10 @@
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#undef _dmxin #undef _dmxin
//#undef _modbus
#ifndef DMX_DISABLE #ifndef DMX_DISABLE
#define _espdmx #define _espdmx
#endif #endif
//#undef _dmxout
//#undef modbusSerial
#ifndef modbusSerial #ifndef modbusSerial
#define modbusSerial Serial2 #define modbusSerial Serial2
#endif #endif
@@ -227,15 +231,6 @@
#define AC_Serial Serial2 #define AC_Serial Serial2
#endif #endif
#ifndef MODBUS_UART_RX_PIN
#define MODBUS_RX_PIN -1
#endif
#ifndef MODBUS_UART_TX_PIN
#define MODBUS_TX_PIN -1
#endif
#endif #endif
#ifndef _dmxout #ifndef _dmxout