1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

Merge remote-tracking branch 'origin/devel' into PORTX_HAL_cursense2_HIGHMEM

This commit is contained in:
Asbelos 2022-11-07 12:21:05 +00:00
commit 61e0de1080
11 changed files with 171 additions and 68 deletions

11
.gitignore vendored
View File

@ -8,13 +8,14 @@ Release/*
.vscode/ .vscode/
config.h config.h
.vscode/* .vscode/*
mySetup.h # mySetup.h
mySetup.cpp mySetup.cpp
myHal.cpp myHal.cpp
myAutomation.h # myAutomation.h
myFilter.cpp myFilter.cpp
myAutomation.h # myAutomation.h
myFilter.cpp # myLayout.h
myLayout.h my*.h
!my*.example.h
.vscode/extensions.json .vscode/extensions.json
.vscode/extensions.json .vscode/extensions.json

View File

@ -81,6 +81,7 @@ const int16_t HASH_KEYWORD_A='A';
const int16_t HASH_KEYWORD_C='C'; const int16_t HASH_KEYWORD_C='C';
const int16_t HASH_KEYWORD_R='R'; const int16_t HASH_KEYWORD_R='R';
const int16_t HASH_KEYWORD_T='T'; const int16_t HASH_KEYWORD_T='T';
const int16_t HASH_KEYWORD_X='X';
const int16_t HASH_KEYWORD_LCN = 15137; const int16_t HASH_KEYWORD_LCN = 15137;
const int16_t HASH_KEYWORD_HAL = 10853; const int16_t HASH_KEYWORD_HAL = 10853;
const int16_t HASH_KEYWORD_SHOW = -21309; const int16_t HASH_KEYWORD_SHOW = -21309;
@ -732,15 +733,7 @@ bool DCCEXParser::parseT(Print *stream, int16_t params, int16_t p[])
switch (params) switch (params)
{ {
case 0: // <T> list turnout definitions case 0: // <T> list turnout definitions
{ return Turnout::printAll(stream); // will <X> if none found
bool gotOne = false;
for (Turnout *tt = Turnout::first(); tt != NULL; tt = tt->next())
{
gotOne = true;
tt->print(stream);
}
return gotOne; // will <X> if none found
}
case 1: // <T id> delete turnout case 1: // <T id> delete turnout
if (!Turnout::remove(p[0])) if (!Turnout::remove(p[0]))
@ -761,12 +754,19 @@ bool DCCEXParser::parseT(Print *stream, int16_t params, int16_t p[])
case HASH_KEYWORD_T: case HASH_KEYWORD_T:
state= false; state= false;
break; break;
default: case HASH_KEYWORD_X:
return false; // Invalid parameter {
Turnout *tt = Turnout::get(p[0]);
if (tt) {
tt->print(stream);
return true;
}
return false;
}
default: // Invalid parameter
return false;
} }
if (!Turnout::setClosed(p[0], state)) return false; if (!Turnout::setClosed(p[0], state)) return false;
return true; return true;
} }

View File

@ -120,9 +120,9 @@ void DCCTimer::reset() {
} }
#if defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) #if defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)
#define NUM_ADC_INPUTS 7
#else
#define NUM_ADC_INPUTS 15 #define NUM_ADC_INPUTS 15
#else
#define NUM_ADC_INPUTS 7
#endif #endif
uint16_t ADCee::usedpins = 0; uint16_t ADCee::usedpins = 0;
int * ADCee::analogvals = NULL; int * ADCee::analogvals = NULL;

View File

@ -1,4 +1,5 @@
/* /*
* © 2022 Paul M. Antoine
* © 2021 Mike S * © 2021 Mike S
* © 2021 Harald Barth * © 2021 Harald Barth
* © 2021 Fred Decker * © 2021 Fred Decker
@ -124,5 +125,31 @@ void DCCTimer::reset() {
while(true){} while(true){}
} }
int16_t ADCee::ADCmax() {
return 4095;
}
int ADCee::init(uint8_t pin) {
return analogRead(pin);
}
/*
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
*/
int ADCee::read(uint8_t pin, bool fromISR) {
int current;
if (!fromISR) noInterrupts();
current = analogRead(pin);
if (!fromISR) interrupts();
return current;
}
/*
* Scan function that is called from interrupt
*/
void ADCee::scan() {
}
void ADCee::begin() {
noInterrupts();
interrupts();
}
#endif #endif

View File

@ -141,4 +141,31 @@ void DCCTimer::reset() {
SCB_AIRCR = 0x05FA0004; SCB_AIRCR = 0x05FA0004;
} }
int16_t ADCee::ADCmax() {
return 4095;
}
int ADCee::init(uint8_t pin) {
return analogRead(pin);
}
/*
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
*/
int ADCee::read(uint8_t pin, bool fromISR) {
int current;
if (!fromISR) noInterrupts();
current = analogRead(pin);
if (!fromISR) interrupts();
return current;
}
/*
* Scan function that is called from interrupt
*/
void ADCee::scan() {
}
void ADCee::begin() {
noInterrupts();
interrupts();
}
#endif #endif

View File

@ -1,6 +1,7 @@
/* /*
* © 2022 Bruno Sanches
* © 2021 Fred Decker * © 2021 Fred Decker
* © 2020-2021 Harald Barth * © 2020-2022 Harald Barth
* © 2020-2021 Chris Harlow * © 2020-2021 Chris Harlow
* © 2020 Gregor Baues * © 2020 Gregor Baues
* All rights reserved. * All rights reserved.
@ -36,8 +37,13 @@ EthernetInterface * EthernetInterface::singleton=NULL;
*/ */
void EthernetInterface::setup() void EthernetInterface::setup()
{ {
singleton=new EthernetInterface(); if (singleton!=NULL) {
if (!singleton->connected) singleton=NULL; DIAG(F("Prog Error!"));
return;
}
if ((singleton=new EthernetInterface()))
return;
DIAG(F("Ethernet not initialized"));
}; };
@ -54,45 +60,41 @@ EthernetInterface::EthernetInterface()
connected=false; connected=false;
#ifdef IP_ADDRESS #ifdef IP_ADDRESS
Ethernet.begin(mac, IP_ADDRESS); if (Ethernet.begin(mac, IP_ADDRESS) == 0)
#else #else
if (Ethernet.begin(mac) == 0) if (Ethernet.begin(mac) == 0)
#endif
{ {
DIAG(F("Ethernet.begin FAILED")); DIAG(F("Ethernet.begin FAILED"));
return; return;
} }
#endif
DIAG(F("begin OK."));
if (Ethernet.hardwareStatus() == EthernetNoHardware) { if (Ethernet.hardwareStatus() == EthernetNoHardware) {
DIAG(F("Ethernet shield not found")); DIAG(F("Ethernet shield not found or W5100"));
return;
} }
unsigned long startmilli = millis(); unsigned long startmilli = millis();
while ((millis() - startmilli) < 5500) // Loop to give time to check for cable connection while ((millis() - startmilli) < 5500) { // Loop to give time to check for cable connection
{
if (Ethernet.linkStatus() == LinkON) if (Ethernet.linkStatus() == LinkON)
break; break;
DIAG(F("Ethernet waiting for link (1sec) ")); DIAG(F("Ethernet waiting for link (1sec) "));
delay(1000); delay(1000);
} }
// now we either do have link of we have a W5100
if (Ethernet.linkStatus() == LinkOFF) { // where we do not know if we have link. That's
DIAG(F("Ethernet cable not connected")); // the reason to now run checkLink.
return; // CheckLinks sets up outboundRing if it does
// not exist yet as well.
checkLink();
} }
connected=true; /**
* @brief Cleanup any resources
IPAddress ip = Ethernet.localIP(); // reassign the obtained ip address *
* @return none
server = new EthernetServer(IP_PORT); // Ethernet Server listening on default port IP_PORT */
server->begin(); EthernetInterface::~EthernetInterface() {
delete server;
LCD(4,F("IP: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); delete outboundRing;
LCD(5,F("Port:%d"), IP_PORT);
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
} }
/** /**
@ -101,33 +103,70 @@ EthernetInterface::EthernetInterface()
*/ */
void EthernetInterface::loop() void EthernetInterface::loop()
{ {
if (!singleton) return; if (!singleton || (!singleton->checkLink()))
return;
switch (Ethernet.maintain()) switch (Ethernet.maintain()) {
{
case 1: case 1:
//renewed fail //renewed fail
DIAG(F("Ethernet Error: renewed fail")); DIAG(F("Ethernet Error: renewed fail"));
singleton=NULL; singleton=NULL;
return; return;
case 3: case 3:
//rebind fail //rebind fail
DIAG(F("Ethernet Error: rebind fail")); DIAG(F("Ethernet Error: rebind fail"));
singleton=NULL; singleton=NULL;
return; return;
default: default:
//nothing happened //nothing happened
break; break;
} }
singleton->loop2(); singleton->loop2();
} }
void EthernetInterface::loop2() /**
{ * @brief Checks ethernet link cable status and detects when it connects / disconnects
*
* @return true when cable is connected, false otherwise
*/
bool EthernetInterface::checkLink() {
if (Ethernet.linkStatus() != LinkOFF) { // check for not linkOFF instead of linkON as the W5100 does return LinkUnknown
//if we are not connected yet, setup a new server
if(!connected) {
DIAG(F("Ethernet cable connected"));
connected=true;
IPAddress ip = Ethernet.localIP(); // reassign the obtained ip address
server = new EthernetServer(IP_PORT); // Ethernet Server listening on default port IP_PORT
server->begin();
LCD(4,F("IP: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
LCD(5,F("Port:%d"), IP_PORT);
// only create a outboundRing it none exists, this may happen if the cable
// gets disconnected and connected again
if(!outboundRing)
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
}
return true;
} else { // connected
DIAG(F("Ethernet cable disconnected"));
connected=false;
//clean up any client
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++) {
if(clients[socket].connected())
clients[socket].stop();
}
// tear down server
delete server;
server = nullptr;
LCD(4,F("IP: None"));
}
return false;
}
void EthernetInterface::loop2() {
if (!outboundRing) { // no idea to call loop2() if we can't handle outgoing data in it
if (Diag::ETHERNET) DIAG(F("No outboundRing"));
return;
}
// get client from the server // get client from the server
EthernetClient client = server->accept(); EthernetClient client = server->accept();
@ -182,7 +221,9 @@ void EthernetInterface::loop()
// handle at most 1 outbound transmission // handle at most 1 outbound transmission
int socketOut=outboundRing->read(); int socketOut=outboundRing->read();
if (socketOut>=0) { if (socketOut >= MAX_SOCK_NUM) {
DIAG(F("Ethernet outboundRing socket=%d error"), socketOut);
} else if (socketOut >= 0) {
int count=outboundRing->count(); int count=outboundRing->count();
if (Diag::ETHERNET) DIAG(F("Ethernet reply socket=%d, count=:%d"), socketOut,count); if (Diag::ETHERNET) DIAG(F("Ethernet reply socket=%d, count=:%d"), socketOut,count);
for(;count>0;count--) clients[socketOut].write(outboundRing->read()); for(;count>0;count--) clients[socketOut].write(outboundRing->read());

View File

@ -59,12 +59,13 @@ class EthernetInterface {
static EthernetInterface * singleton; static EthernetInterface * singleton;
bool connected; bool connected;
EthernetInterface(); EthernetInterface();
~EthernetInterface();
void loop2(); void loop2();
EthernetServer * server; bool checkLink();
EthernetServer * server = NULL;
EthernetClient clients[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield EthernetClient clients[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield
uint8_t buffer[MAX_ETH_BUFFER+1]; // buffer used by TCP for the recv uint8_t buffer[MAX_ETH_BUFFER+1]; // buffer used by TCP for the recv
RingStream * outboundRing; RingStream * outboundRing = NULL;
}; };
#endif #endif

View File

@ -1 +1 @@
#define GITHUB_SHA "PORTX-HAL-cursense2-202210192255Z" #define GITHUB_SHA "devel-202211071020Z"

View File

@ -183,6 +183,6 @@
new MotorDriver( 3, 12, UNUSED_PIN, 9, A0, 2.99, 1500, UNUSED_PIN), \ new MotorDriver( 3, 12, UNUSED_PIN, 9, A0, 2.99, 1500, UNUSED_PIN), \
new MotorDriver(11, 13, UNUSED_PIN, 8, A1, 2.99, 1500, UNUSED_PIN), \ new MotorDriver(11, 13, UNUSED_PIN, 8, A1, 2.99, 1500, UNUSED_PIN), \
new MotorDriver( 2, 10, UNUSED_PIN, 7, A3, 2.99, 1500, UNUSED_PIN), \ new MotorDriver( 2, 10, UNUSED_PIN, 7, A3, 2.99, 1500, UNUSED_PIN), \
new MotorDriver(10, 4, UNUSED_PIN, 6, A4, 2.99, 1500, UNUSED_PIN) new MotorDriver( 5, 4, UNUSED_PIN, 6, A4, 2.99, 1500, UNUSED_PIN)
// //
#endif #endif

View File

@ -171,9 +171,14 @@ public:
// Save all turnout definitions // Save all turnout definitions
static void store(); static void store();
#endif #endif
static void printAll(Print *stream) { static bool printAll(Print *stream) {
bool gotOne=false;
for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout) for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout)
if (!tt->isHidden()) StringFormatter::send(stream, F("<H %d %d>\n"),tt->getId(), tt->isThrown()); if (!tt->isHidden()) {
gotOne=true;
StringFormatter::send(stream, F("<H %d %d>\n"),tt->getId(), tt->isThrown());
}
return gotOne;
} }

View File

@ -5,6 +5,7 @@
#define VERSION "4.2.4" #define VERSION "4.2.4"
// Ethernet start improvement and link detection
// 4.2.4 ESP32 experimental BT support // 4.2.4 ESP32 experimental BT support
// More DC configurations possible and lower frequency // More DC configurations possible and lower frequency
// Handle decoders that do not ack at write better // Handle decoders that do not ack at write better