mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
UART interceptor now is compatible with Whireshark
This commit is contained in:
@@ -16,10 +16,11 @@
|
||||
#-DPID_DISABLE
|
||||
|
||||
#Define pins for Serial1. Default - 9/10 is utilized by ESP flash
|
||||
#-DRX1=15
|
||||
#-DTX1=2
|
||||
#-DMODBUS_UART_RX_PIN=15
|
||||
#-DMODBUS_UART_TX_PIN=2
|
||||
#-DmodbusSerial=Serial1
|
||||
|
||||
-DMODBUS_UART_RX_PIN=15
|
||||
-DMODBUS_UART_TX_PIN=2
|
||||
-DmodbusSerial=Serial1
|
||||
# Use default pins
|
||||
-DMODBUS_UART_RX_PIN=-1
|
||||
-DMODBUS_UART_TX_PIN=-1
|
||||
|
||||
|
||||
@@ -211,6 +211,8 @@ enum lan_status {
|
||||
DO_NOTHING = -15
|
||||
};
|
||||
|
||||
extern lan_status lanStatus;
|
||||
|
||||
typedef union {
|
||||
uint32_t UID_Long[5];
|
||||
uint8_t UID_Byte[20];
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP32)
|
||||
#undef WAK_PIN
|
||||
#undef SCL_RESET
|
||||
//#ifndef WAK_PIN
|
||||
//#define WAK_PIN 17
|
||||
//#endif
|
||||
|
||||
@@ -11,6 +11,22 @@
|
||||
#include "main.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 ModbusMaster node;
|
||||
extern short modbusBusy;
|
||||
@@ -88,6 +104,14 @@ bool out_UARTbridge::getConfig()
|
||||
MODULE_UATRBRIDGE_UARTB.begin(store->baud, (store->serialParam));
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -95,6 +119,7 @@ bool out_UARTbridge::getConfig()
|
||||
int out_UARTbridge::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
|
||||
if (!store) store= (ubPersistent *)item->setPersistent(new ubPersistent);
|
||||
if (!store)
|
||||
{ errorSerial<<F("UARTbridge: Out of memory")<<endl;
|
||||
@@ -134,22 +159,60 @@ return CST_UNKNOWN;
|
||||
|
||||
int out_UARTbridge::Poll(short cause)
|
||||
{
|
||||
int chA;
|
||||
int chB;
|
||||
uint8_t chA;
|
||||
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())
|
||||
{
|
||||
|
||||
if (MODULE_UATRBRIDGE_UARTA.available())
|
||||
{
|
||||
timerA=millisNZ();
|
||||
if (timerB) return 1;
|
||||
chA=MODULE_UATRBRIDGE_UARTA.read();
|
||||
MODULE_UATRBRIDGE_UARTB.write(chA);
|
||||
debugSerial<<F("<")<<_HEX(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())
|
||||
{
|
||||
chB=MODULE_UATRBRIDGE_UARTB.read();
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
//aJsonObject * parameters;
|
||||
};
|
||||
|
||||
|
||||
#define PDELAY 50
|
||||
|
||||
class out_UARTbridge : public abstractOut {
|
||||
public:
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
// Configuration of drivers enabled
|
||||
#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
|
||||
#define ADAFRUIT_LED
|
||||
#endif
|
||||
@@ -194,7 +202,6 @@
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#undef _dmxin
|
||||
//#undef _modbus
|
||||
|
||||
#ifndef DMX_DISABLE
|
||||
#define _espdmx
|
||||
@@ -212,13 +219,10 @@
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#undef _dmxin
|
||||
//#undef _modbus
|
||||
|
||||
#ifndef DMX_DISABLE
|
||||
#define _espdmx
|
||||
#endif
|
||||
//#undef _dmxout
|
||||
//#undef modbusSerial
|
||||
|
||||
#ifndef modbusSerial
|
||||
#define modbusSerial Serial2
|
||||
#endif
|
||||
@@ -227,15 +231,6 @@
|
||||
#define AC_Serial Serial2
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MODBUS_UART_RX_PIN
|
||||
#define MODBUS_RX_PIN -1
|
||||
#endif
|
||||
|
||||
#ifndef MODBUS_UART_TX_PIN
|
||||
#define MODBUS_TX_PIN -1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _dmxout
|
||||
|
||||
Reference in New Issue
Block a user