mirror of
https://github.com/anklimov/lighthub
synced 2025-12-12 14:49:50 +03:00
uartBridge refactored & cross-compiled. new Mega dev
This commit is contained in:
@@ -82,7 +82,6 @@ EthernetClient ethClient;
|
||||
|
||||
#if defined(OTA)
|
||||
#include <ArduinoOTA.h>
|
||||
//bool OTA_initialized=false;
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
@@ -103,6 +102,7 @@ NRFFlashStorage EEPROM;
|
||||
|
||||
#ifdef SYSLOG_ENABLE
|
||||
#include <Syslog.h>
|
||||
|
||||
#ifndef WIFI_ENABLE
|
||||
EthernetUDP udpSyslogClient;
|
||||
#else
|
||||
@@ -121,7 +121,7 @@ Streamlog errorSerial(&debugSerialPort,LOG_ERROR, ledRED);
|
||||
Streamlog infoSerial (&debugSerialPort,LOG_INFO);
|
||||
#endif
|
||||
|
||||
statusLED LED(ledRED);
|
||||
StatusLED statusLED(ledRED);
|
||||
|
||||
|
||||
lan_status lanStatus = INITIAL_STATE;
|
||||
@@ -271,7 +271,7 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
||||
return;
|
||||
}
|
||||
|
||||
LED.flash(ledBLUE);
|
||||
statusLED.flash(ledBLUE);
|
||||
for (unsigned int i = 0; i < length; i++)
|
||||
debugSerial<<((char) payload[i]);
|
||||
debugSerial<<endl;
|
||||
@@ -378,23 +378,40 @@ if (element && element->type == aJson_String) return element->valuestring;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)
|
||||
#define flashStorage InternalStorage
|
||||
#else
|
||||
InternalStorageClass flashStorage(EEPROM_offsetJSON);
|
||||
#endif
|
||||
|
||||
void setupOTA(void)
|
||||
{
|
||||
#ifdef OTA
|
||||
//if (OTA_initialized) return;
|
||||
// ArduinoOTA.end();
|
||||
// start the OTEthernet library with internal (flash) based storage
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", flashStorage);
|
||||
infoSerial<<F("OTA initialized\n");
|
||||
//OTA_initialized=true;
|
||||
#if (defined(ARDUINO_ARCH_ESP32) || defined(ESP8266))
|
||||
void setupOTA(void)
|
||||
{
|
||||
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage);
|
||||
infoSerial<<F("OTA initialized\n");
|
||||
|
||||
}
|
||||
#elif defined (ARDUINO_ARCH_AVR)
|
||||
InternalStorageAVRClass flashStorage;
|
||||
void setupOTA(void)
|
||||
{
|
||||
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", flashStorage);
|
||||
infoSerial<<F("OTA initialized\n");
|
||||
|
||||
}
|
||||
#else
|
||||
InternalStorageClass flashStorage(EEPROM_offsetJSON);
|
||||
void setupOTA(void)
|
||||
{
|
||||
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", flashStorage);
|
||||
infoSerial<<F("OTA initialized\n");
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#else
|
||||
void setupOTA(void) {};
|
||||
#endif
|
||||
}
|
||||
|
||||
void setupSyslog()
|
||||
{
|
||||
@@ -414,7 +431,7 @@ void setupSyslog()
|
||||
char *syslogServer = getStringFromConfig(udpSyslogArr, 0);
|
||||
if (n>1) syslogPort = aJson.getArrayItem(udpSyslogArr, 1)->valueint;
|
||||
|
||||
inet_ntoa_r(Ethernet.localIP(),syslogDeviceHostname,sizeof(syslogDeviceHostname));
|
||||
_inet_ntoa_r(Ethernet.localIP(),syslogDeviceHostname,sizeof(syslogDeviceHostname));
|
||||
infoSerial<<F("Syslog params:")<<syslogServer<<":"<<syslogPort<<":"<<syslogDeviceHostname<<endl;
|
||||
udpSyslog.server(syslogServer, syslogPort);
|
||||
udpSyslog.deviceHostname(syslogDeviceHostname);
|
||||
@@ -439,8 +456,8 @@ lan_status lanLoop() {
|
||||
switch (lanStatus) {
|
||||
|
||||
case INITIAL_STATE:
|
||||
// LED.set(ledRED|((configLoaded)?ledBLINK:0));
|
||||
LED.set(ledRED|((configLoaded)?ledBLINK:0));
|
||||
// statusLED.set(ledRED|((configLoaded)?ledBLINK:0));
|
||||
statusLED.set(ledRED|((configLoaded)?ledBLINK:0));
|
||||
|
||||
#if defined(WIFI_ENABLE)
|
||||
onInitialStateInitLAN(); // Moves state to AWAITING_ADDRESS or HAVE_IP_ADDRESS
|
||||
@@ -485,7 +502,7 @@ lan_status lanLoop() {
|
||||
break;
|
||||
|
||||
case LIBS_INITIALIZED:
|
||||
LED.set(ledRED|ledGREEN|((configLoaded)?ledBLINK:0));
|
||||
statusLED.set(ledRED|ledGREEN|((configLoaded)?ledBLINK:0));
|
||||
if (configLocked) return LIBS_INITIALIZED;
|
||||
|
||||
if (!configOk)
|
||||
@@ -496,7 +513,7 @@ lan_status lanLoop() {
|
||||
|
||||
case IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER:
|
||||
wdt_res();
|
||||
LED.set(ledRED|ledGREEN|((configLoaded)?ledBLINK:0));
|
||||
statusLED.set(ledRED|ledGREEN|((configLoaded)?ledBLINK:0));
|
||||
ip_ready_config_loaded_connecting_to_broker();
|
||||
break;
|
||||
|
||||
@@ -517,7 +534,7 @@ lan_status lanLoop() {
|
||||
}
|
||||
break;
|
||||
case OPERATION:
|
||||
LED.set(ledGREEN|((configLoaded)?ledBLINK:0));
|
||||
statusLED.set(ledGREEN|((configLoaded)?ledBLINK:0));
|
||||
if (!mqttClient.connected()) lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;//2;
|
||||
break;
|
||||
|
||||
@@ -525,7 +542,7 @@ lan_status lanLoop() {
|
||||
//if (mqttClient.connected()) mqttClient.disconnect(); // Hmm hungs then cable disconnected
|
||||
timerLanCheckTime = millis();// + 5000;
|
||||
lanStatus = REINIT;
|
||||
LED.set(ledRED|((configLoaded)?ledBLINK:0));
|
||||
statusLED.set(ledRED|((configLoaded)?ledBLINK:0));
|
||||
break;
|
||||
|
||||
case REINIT: // Pause and re-init LAN
|
||||
@@ -831,7 +848,9 @@ void onInitialStateInitLAN() {
|
||||
WiFi.mode(WIFI_STA); // ESP 32 - WiFi.disconnect(); instead
|
||||
infoSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD)<<endl;
|
||||
|
||||
#ifndef ARDUINO_ARCH_ESP32
|
||||
wifi_set_macaddr(STATION_IF,mac); //ESP32 to check
|
||||
#endif
|
||||
|
||||
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||
|
||||
@@ -1276,16 +1295,16 @@ void cmdFunctionIp(int arg_cnt, char **args)
|
||||
|
||||
// switch (arg_cnt) {
|
||||
// case 5:
|
||||
if (arg_cnt>4 && inet_aton(args[4], ip)) saveFlash(OFFSET_MASK, ip);
|
||||
if (arg_cnt>4 && _inet_aton(args[4], ip)) saveFlash(OFFSET_MASK, ip);
|
||||
else saveFlash(OFFSET_MASK, ip0);
|
||||
// case 4:
|
||||
if (arg_cnt>3 && inet_aton(args[3], ip)) saveFlash(OFFSET_GW, ip);
|
||||
if (arg_cnt>3 && _inet_aton(args[3], ip)) saveFlash(OFFSET_GW, ip);
|
||||
else saveFlash(OFFSET_GW, ip0);
|
||||
// case 3:
|
||||
if (arg_cnt>2 && inet_aton(args[2], ip)) saveFlash(OFFSET_DNS, ip);
|
||||
if (arg_cnt>2 && _inet_aton(args[2], ip)) saveFlash(OFFSET_DNS, ip);
|
||||
else saveFlash(OFFSET_DNS, ip0);
|
||||
// case 2:
|
||||
if (arg_cnt>1 && inet_aton(args[1], ip)) saveFlash(OFFSET_IP, ip);
|
||||
if (arg_cnt>1 && _inet_aton(args[1], ip)) saveFlash(OFFSET_IP, ip);
|
||||
else saveFlash(OFFSET_IP, ip0);
|
||||
// break;
|
||||
|
||||
@@ -1422,15 +1441,18 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
//if (freeRam()<512) cleanConf();
|
||||
|
||||
HTTPClient hclient(configServer, 80);
|
||||
debugSerial<<F("free ")<<freeRam()<<endl;delay(100);
|
||||
// FILE is the return STREAM type of the HTTPClient
|
||||
configStream = hclient.getURI(URI);
|
||||
debugSerial<<F("hclient")<<endl;delay(100);
|
||||
responseStatusCode = hclient.getLastReturnCode();
|
||||
debugSerial<<F("retcode ")<<responseStatusCode<<endl;delay(100);
|
||||
//wdt_en();
|
||||
|
||||
|
||||
if (configStream != NULL) {
|
||||
if (responseStatusCode == 200) {
|
||||
|
||||
infoSerial<<F("got Config\n");
|
||||
infoSerial<<F("got Config\n"); delay(500);
|
||||
char c;
|
||||
aJsonFileStream as = aJsonFileStream(configStream);
|
||||
noInterrupts();
|
||||
@@ -1519,10 +1541,11 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) //|| defined (NRF5)
|
||||
HTTPClient httpClient;
|
||||
WiFiClient wifiClient;
|
||||
String fullURI = "http://";
|
||||
fullURI+=configServer;
|
||||
fullURI+=URI;
|
||||
httpClient.begin(fullURI);
|
||||
httpClient.begin(wifiClient,fullURI);
|
||||
int httpResponseCode = httpClient.GET();
|
||||
if (httpResponseCode > 0) {
|
||||
infoSerial.printf("[HTTP] GET... code: %d\n", httpResponseCode);
|
||||
@@ -1786,11 +1809,16 @@ infoSerial<<F("\n(-)PID");
|
||||
#endif
|
||||
|
||||
#ifdef SYSLOG_ENABLE
|
||||
//udpSyslogClient.begin(SYSLOG_LOCAL_SOCKET);
|
||||
infoSerial<<F("\n(+)SYSLOG");
|
||||
#else
|
||||
infoSerial<<F("\n(-)SYSLOG");
|
||||
#endif
|
||||
|
||||
#ifdef UARTBRIDGE_ENABLE
|
||||
infoSerial<<F("\n(+)UARTBRIDGE");
|
||||
#else
|
||||
infoSerial<<F("\n(-)UARTBRIDGE");
|
||||
#endif
|
||||
infoSerial<<endl;
|
||||
|
||||
// WDT_Disable( WDT ) ;
|
||||
@@ -1888,8 +1916,8 @@ void setupCmdArduino() {
|
||||
cmdAdd("reboot",cmdFunctionReboot);
|
||||
}
|
||||
|
||||
void loop_main() {
|
||||
LED.poll();
|
||||
void loop_main() {
|
||||
statusLED.poll();
|
||||
|
||||
#if defined(M5STACK)
|
||||
// Initialize the M5Stack object
|
||||
@@ -1900,7 +1928,7 @@ void loop_main() {
|
||||
wdt_res();
|
||||
yield();
|
||||
cmdPoll();
|
||||
if (lanLoop() > HAVE_IP_ADDRESS) {
|
||||
if (lanLoop() > HAVE_IP_ADDRESS) {
|
||||
mqttClient.loop();
|
||||
|
||||
#if defined(OTA)
|
||||
@@ -1967,7 +1995,7 @@ ethernetIdleCount--;
|
||||
};
|
||||
|
||||
void modbusIdle(void) {
|
||||
LED.poll();
|
||||
statusLED.poll();
|
||||
yield();
|
||||
cmdPoll();
|
||||
wdt_res();
|
||||
@@ -2065,9 +2093,9 @@ configLocked--;
|
||||
|
||||
|
||||
void pollingLoop(void) {
|
||||
if (!items) return;
|
||||
// FAST POLLINT - as often AS possible every item
|
||||
configLocked++;
|
||||
if (items) {
|
||||
aJsonObject * item = items->child;
|
||||
while (items && item)
|
||||
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
|
||||
@@ -2078,7 +2106,6 @@ if (items) {
|
||||
yield();
|
||||
item = item->next;
|
||||
} //if
|
||||
}
|
||||
configLocked--;
|
||||
// SLOW POLLING
|
||||
boolean done = false;
|
||||
|
||||
@@ -356,7 +356,7 @@ return is8bit;
|
||||
|
||||
//if (readModbus(registerFrom,MODBUS_HOLDING_REG_TYPE,registerTo-registerFrom+1))
|
||||
if (readModbus(registerFrom,regType,registerTo-registerFrom+1))
|
||||
{
|
||||
{ debugSerial<<endl;
|
||||
for(int i=registerFrom;i<=registerTo;i++)
|
||||
{
|
||||
findRegister(i,i-registerFrom,regType);
|
||||
@@ -382,7 +382,6 @@ if ((store->pollingRegisters || store->pollingIrs) && !modbusBusy && (Status() =
|
||||
modbusSerial.begin(store->baud, static_cast <USARTClass::USARTModes> (store->serialParam));
|
||||
#elif defined (ARDUINO_ARCH_ESP8266)
|
||||
modbusSerial.begin(store->baud, static_cast <SerialConfig>(store->serialParam));
|
||||
Serial1.begin()
|
||||
#elif defined (ESP32)
|
||||
//modbusSerial.begin(store->baud, store->serialParam);
|
||||
//delay(100);
|
||||
|
||||
@@ -7,71 +7,37 @@
|
||||
#include "Streaming.h"
|
||||
|
||||
#include "item.h"
|
||||
#include <ModbusMaster.h>
|
||||
//#include <ModbusMaster.h>
|
||||
#include "main.h"
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#if defined (ESP32)
|
||||
#include <AsyncUDP.h>
|
||||
AsyncUDP udp;
|
||||
AsyncUDPMessage udpMessageA;
|
||||
AsyncUDPMessage udpMessageB;
|
||||
|
||||
#include <Udp.h>
|
||||
#ifndef WIFI_ENABLE
|
||||
EthernetUDP udpClientA;
|
||||
EthernetUDP udpClientB;
|
||||
#else
|
||||
WiFiUDP udpClientA;
|
||||
WiFiUDP udpClientB;
|
||||
#endif
|
||||
|
||||
IPAddress targetIP;
|
||||
uint16_t targetPort=5555;
|
||||
#endif
|
||||
|
||||
short halfduplex=1;
|
||||
bool udpdump=false;
|
||||
uint32_t timerA = 0;
|
||||
uint32_t timerB = 0;
|
||||
uint16_t sizeA = 0;
|
||||
uint16_t sizeB = 0;
|
||||
|
||||
//extern aJsonObject *modbusObj;
|
||||
//extern ModbusMaster node;
|
||||
//extern short modbusBusy;
|
||||
//extern void modbusIdle(void) ;
|
||||
|
||||
extern aJsonObject *modbusObj;
|
||||
extern ModbusMaster node;
|
||||
extern short modbusBusy;
|
||||
extern void modbusIdle(void) ;
|
||||
|
||||
/*
|
||||
struct reg_t
|
||||
{
|
||||
const char verb[4];
|
||||
const uint8_t id;
|
||||
};
|
||||
|
||||
|
||||
#define PAR_I16 1
|
||||
#define PAR_I32 2
|
||||
#define PAR_U16 3
|
||||
#define PAR_U32 4
|
||||
#define PAR_I8H 5
|
||||
#define PAR_I8L 6
|
||||
#define PAR_U8H 7
|
||||
#define PAR_U8L 8
|
||||
#define PAR_TENS 9
|
||||
|
||||
const reg_t regSize_P[] PROGMEM =
|
||||
{
|
||||
{ "i16", (uint8_t) PAR_I16 },
|
||||
{ "i32", (uint8_t) PAR_I32 },
|
||||
{ "u16", (uint8_t) PAR_U16 },
|
||||
{ "u32", (uint8_t) PAR_U32 },
|
||||
{ "i8h", (uint8_t) PAR_I8H },
|
||||
{ "i8l", (uint8_t) PAR_I8L },
|
||||
{ "u8h", (uint8_t) PAR_U8H },
|
||||
{ "u8l", (uint8_t) PAR_U8L },
|
||||
{ "x10", (uint8_t) PAR_TENS }
|
||||
} ;
|
||||
#define regSizeNum sizeof(regSize_P)/sizeof(reg_t)
|
||||
|
||||
int str2regSize(char * str)
|
||||
{
|
||||
for(uint8_t i=0; i<regSizeNum && str;i++)
|
||||
if (strcmp_P(str, regSize_P[i].verb) == 0)
|
||||
return pgm_read_byte_near(®Size_P[i].id);
|
||||
return (int) PAR_I16;
|
||||
}
|
||||
*/
|
||||
|
||||
bool out_UARTbridge::getConfig()
|
||||
{
|
||||
@@ -106,11 +72,20 @@ bool out_UARTbridge::getConfig()
|
||||
|
||||
aJsonObject * debugIPObj=aJson.getObjectItem(item->itemArg, "ip");
|
||||
aJsonObject * debugPortObj=aJson.getObjectItem(item->itemArg, "port");
|
||||
aJsonObject * hdObj=aJson.getObjectItem(item->itemArg, "hd");
|
||||
|
||||
if (debugIPObj)
|
||||
{
|
||||
_inet_aton(debugIPObj->valuestring, targetIP);
|
||||
if (udpClientA.begin(SOURCE_PORT_A) && udpClientB.begin(SOURCE_PORT_B)) udpdump=true;
|
||||
else {
|
||||
udpClientA.stop(); udpClientB.stop(); udpdump=false;
|
||||
errorSerial<<F("No sockets available, udpdump disabled")<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (debugPortObj) targetPort = debugPortObj->valueint;
|
||||
if (debugPortObj) targetPort = debugPortObj->valueint;
|
||||
if (hdObj) halfduplex = hdObj->valueint;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -125,7 +100,12 @@ if (!store)
|
||||
{ errorSerial<<F("UARTbridge: Out of memory")<<endl;
|
||||
return 0;}
|
||||
|
||||
//store->timestamp=millisNZ();
|
||||
|
||||
sizeA=0;
|
||||
sizeB=0;
|
||||
timerA=0;
|
||||
timerB=0;
|
||||
|
||||
if (getConfig())
|
||||
{
|
||||
infoSerial<<F("UARTbridge config loaded ")<< item->itemArr->name<<endl;
|
||||
@@ -143,6 +123,10 @@ else
|
||||
int out_UARTbridge::Stop()
|
||||
{
|
||||
Serial.println("UARTbridge De-Init");
|
||||
|
||||
udpClientA.stop();
|
||||
udpClientB.stop();
|
||||
udpdump=false;
|
||||
|
||||
delete store;
|
||||
item->setPersistent(NULL);
|
||||
@@ -157,11 +141,75 @@ if (store)
|
||||
return CST_UNKNOWN;
|
||||
}
|
||||
|
||||
void flushA()
|
||||
{
|
||||
if (sizeA)
|
||||
{
|
||||
if (lanStatus>=HAVE_IP_ADDRESS && udpdump) udpClientA.endPacket();
|
||||
debugSerial<<endl;
|
||||
}
|
||||
timerA=0;
|
||||
sizeA=0;
|
||||
}
|
||||
|
||||
void flushB()
|
||||
{
|
||||
if (sizeB)
|
||||
{
|
||||
if (lanStatus>=HAVE_IP_ADDRESS && udpdump) udpClientB.endPacket();
|
||||
debugSerial<<endl;
|
||||
}
|
||||
timerB=0;
|
||||
sizeB=0;
|
||||
}
|
||||
|
||||
int out_UARTbridge::Poll(short cause)
|
||||
{
|
||||
uint8_t chA;
|
||||
uint8_t chB;
|
||||
|
||||
while (MODULE_UATRBRIDGE_UARTA.available() || MODULE_UATRBRIDGE_UARTB.available())
|
||||
{
|
||||
|
||||
if (MODULE_UATRBRIDGE_UARTA.available())
|
||||
{
|
||||
if (!sizeA)
|
||||
{
|
||||
if (lanStatus>=HAVE_IP_ADDRESS && udpdump) udpClientA.beginPacket(targetIP, targetPort);
|
||||
if (halfduplex) flushB();
|
||||
}
|
||||
|
||||
timerA=millisNZ();
|
||||
////if (timerB) return 1;
|
||||
chA=MODULE_UATRBRIDGE_UARTA.read();
|
||||
MODULE_UATRBRIDGE_UARTB.write(chA);
|
||||
debugSerial<<F("<")<<((chA<16)?"0":"")<<_HEX(chA);
|
||||
if (lanStatus>=HAVE_IP_ADDRESS && udpdump) {udpClientA.write(chA);}
|
||||
sizeA++;
|
||||
}
|
||||
|
||||
if (MODULE_UATRBRIDGE_UARTB.available())
|
||||
{
|
||||
if (!sizeB)
|
||||
{
|
||||
if (lanStatus>=HAVE_IP_ADDRESS && udpdump) udpClientB.beginPacket(targetIP, targetPort);
|
||||
if (halfduplex) flushA();
|
||||
}
|
||||
timerB=millisNZ();
|
||||
////if (timerA) return 1;
|
||||
chB=MODULE_UATRBRIDGE_UARTB.read();
|
||||
MODULE_UATRBRIDGE_UARTA.write(chB);
|
||||
debugSerial<<F(">")<<((chB<16)?"0":"")<<_HEX(chB);
|
||||
if (lanStatus>=HAVE_IP_ADDRESS && udpdump) {udpClientB.write(chB);};
|
||||
sizeB++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((timerA && (isTimeOver(timerA,millis(),PDELAY)) || sizeA>=MAX_PDU)) flushA();
|
||||
if ((timerB && (isTimeOver(timerB,millis(),PDELAY)) || sizeB>=MAX_PDU)) flushB();
|
||||
|
||||
|
||||
/*
|
||||
if ((lanStatus>=HAVE_IP_ADDRESS) && udpMessageA.length() && (isTimeOver(timerA,millis(),PDELAY) || timerB))
|
||||
{
|
||||
udp.sendTo(udpMessageA,targetIP,targetPort);
|
||||
@@ -201,19 +249,8 @@ if ((lanStatus>=HAVE_IP_ADDRESS) && udpMessageB.length() && (isTimeOver(timerB,m
|
||||
udpMessageB.write(chB);
|
||||
}
|
||||
}
|
||||
/*
|
||||
while (MODULE_UATRBRIDGE_UARTB.available())
|
||||
{
|
||||
chB=MODULE_UATRBRIDGE_UARTB.read();
|
||||
MODULE_UATRBRIDGE_UARTA.write(chB);
|
||||
debugSerial<<F(">")<<((chB<10)?"0":"")<<_HEX(chB);
|
||||
udpMessageB.write(chB);
|
||||
timerB=millisNZ();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
return 1;//store->pollingInterval;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
#define serialParamType uint16_t
|
||||
#endif
|
||||
|
||||
#define SOURCE_PORT_A 5551
|
||||
#define SOURCE_PORT_B 5552
|
||||
#define MAX_PDU 1024
|
||||
|
||||
#ifndef MODULE_UATRBRIDGE_UARTA
|
||||
#define MODULE_UATRBRIDGE_UARTA Serial1
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@ e-mail anklimov@gmail.com
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
statusLED::statusLED(uint8_t pattern)
|
||||
StatusLED::StatusLED(uint8_t pattern)
|
||||
{
|
||||
#if defined (STATUSLED)
|
||||
pinMode(pinRED, OUTPUT);
|
||||
@@ -33,7 +33,7 @@ statusLED::statusLED(uint8_t pattern)
|
||||
#endif
|
||||
}
|
||||
|
||||
void statusLED::show (uint8_t pattern)
|
||||
void StatusLED::show (uint8_t pattern)
|
||||
{
|
||||
#if defined (STATUSLED)
|
||||
digitalWrite(pinRED,(pattern & ledRED)?HIGH:LOW );
|
||||
@@ -42,7 +42,7 @@ void statusLED::show (uint8_t pattern)
|
||||
#endif
|
||||
}
|
||||
|
||||
void statusLED::set (uint8_t pattern)
|
||||
void StatusLED::set (uint8_t pattern)
|
||||
{
|
||||
#if defined (STATUSLED)
|
||||
short newStat = pattern & ledParams;
|
||||
@@ -56,7 +56,7 @@ void statusLED::set (uint8_t pattern)
|
||||
#endif
|
||||
}
|
||||
|
||||
void statusLED::flash(uint8_t pattern)
|
||||
void StatusLED::flash(uint8_t pattern)
|
||||
{
|
||||
#if defined (STATUSLED)
|
||||
show(pattern);
|
||||
@@ -64,7 +64,7 @@ void statusLED::flash(uint8_t pattern)
|
||||
#endif
|
||||
}
|
||||
|
||||
void statusLED::poll()
|
||||
void StatusLED::poll()
|
||||
{
|
||||
#if defined (STATUSLED)
|
||||
if (curStat & ledFlash)
|
||||
|
||||
@@ -30,16 +30,22 @@ e-mail anklimov@gmail.com
|
||||
#define ledFlash 32
|
||||
#define ledHidden 64
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
#define pinRED 47
|
||||
#define pinGREEN 48
|
||||
#define pinBLUE 49
|
||||
#else
|
||||
#define pinRED 50
|
||||
#define pinGREEN 51
|
||||
#define pinBLUE 52
|
||||
#endif
|
||||
|
||||
#define ledDelayms 1000UL
|
||||
#define ledFastDelayms 300UL
|
||||
|
||||
class statusLED {
|
||||
class StatusLED {
|
||||
public:
|
||||
statusLED(uint8_t pattern = 0);
|
||||
StatusLED(uint8_t pattern = 0);
|
||||
void set (uint8_t pattern);
|
||||
void show (uint8_t pattern);
|
||||
void poll();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "statusled.h"
|
||||
|
||||
#if defined (STATUSLED)
|
||||
extern statusLED LED;
|
||||
extern StatusLED statusLED;
|
||||
#endif
|
||||
|
||||
#ifdef SYSLOG_ENABLE
|
||||
@@ -77,7 +77,7 @@ if (syslogInitialized)
|
||||
#endif
|
||||
|
||||
#if defined (STATUSLED)
|
||||
if ((ch=='\n') && ledPattern) LED.flash(ledPattern);
|
||||
if ((ch=='\n') && ledPattern) statusLED.flash(ledPattern);
|
||||
#endif
|
||||
|
||||
if (serialPort) return serialPort->write(ch);
|
||||
|
||||
@@ -685,14 +685,14 @@ unsigned long millisNZ(uint8_t shift)
|
||||
return now;
|
||||
}
|
||||
|
||||
struct serial_t
|
||||
struct serial_st
|
||||
{
|
||||
const char verb[4];
|
||||
const serialParamType mode;
|
||||
};
|
||||
|
||||
|
||||
const serial_t serialModes_P[] PROGMEM =
|
||||
const serial_st serialModes_P[] PROGMEM =
|
||||
{
|
||||
{ "8E1", (serialParamType) SERIAL_8E1},//(uint16_t) US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_EVEN },
|
||||
{ "8N1", (serialParamType) SERIAL_8N1},
|
||||
@@ -703,16 +703,18 @@ const serial_t serialModes_P[] PROGMEM =
|
||||
// { "8M1", SERIAL_8M1},
|
||||
// { "8S1", SERIAL_8S1},
|
||||
{ "7E1", (serialParamType) SERIAL_7E1},//(uint16_t) US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_EVEN },
|
||||
{ "7N1", (serialParamType) SERIAL_7N1},
|
||||
{ "7E2", (serialParamType) SERIAL_7E2},
|
||||
{ "7N2", (serialParamType) SERIAL_7N2},
|
||||
{ "7O1", (serialParamType) SERIAL_7O1},
|
||||
{ "7O2", (serialParamType) SERIAL_7O2}
|
||||
#ifndef ARDUINO_ARCH_STM32
|
||||
,{ "7N1", (serialParamType) SERIAL_7N1}
|
||||
,{ "7N2", (serialParamType) SERIAL_7N2}
|
||||
#endif
|
||||
// { "7M1", SERIAL_7M1},
|
||||
// { "7S1", SERIAL_7S1}
|
||||
} ;
|
||||
|
||||
#define serialModesNum sizeof(serialModes_P)/sizeof(serial_t)
|
||||
#define serialModesNum sizeof(serialModes_P)/sizeof(serial_st)
|
||||
|
||||
serialParamType str2SerialParam(char * str)
|
||||
{ debugSerial<<str<<F(" =>");
|
||||
|
||||
@@ -60,8 +60,8 @@ void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int
|
||||
int log(const char *str, ...);
|
||||
void printFloatValueToStr(float value, char *valstr);
|
||||
void ReadUniqueID( uint32_t * pdwUniqueID );
|
||||
int inet_aton(const char* aIPAddrString, IPAddress& aResult);
|
||||
char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
|
||||
int _inet_aton(const char* aIPAddrString, IPAddress& aResult);
|
||||
char *_inet_ntoa_r(IPAddress addr, char *buf, int buflen);
|
||||
void printIPAddress(IPAddress ipAddress);
|
||||
char* setTopic(char* buf, int8_t buflen, topicType tt, const char* suffix = NULL);
|
||||
void printUlongValueToStr(char *valstr, unsigned long value);
|
||||
|
||||
Reference in New Issue
Block a user