mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-04-21 12:31:19 +02:00
saving: works
This commit is contained in:
parent
250a34bc09
commit
74cb0c12b0
114
IO_RSproto.cpp
114
IO_RSproto.cpp
@ -71,14 +71,40 @@ uint16_t RSproto::crc16(uint8_t *data, uint16_t length) {
|
|||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RSprotonode::_pollDigital(unsigned long currentMicros) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void RSprotonode::_pollAnalog(unsigned long currentMicros) {
|
||||||
|
RSproto *bus = RSproto::findBus(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void RSproto::_loop(unsigned long currentMicros) {
|
void RSproto::_loop(unsigned long currentMicros) {
|
||||||
_currentMicros = currentMicros;
|
_currentMicros = currentMicros;
|
||||||
//if (_busy == true) return;
|
//if (_busy == true) return;
|
||||||
|
if (_currentNode == NULL) _currentNode = _nodeListStart;
|
||||||
|
if (!hasTasks() && _currentNode->isInitialised()) {
|
||||||
|
_cycleStartTime = _currentMicros;
|
||||||
|
uint8_t buffA[3];
|
||||||
|
buffA[0] = (_currentNode->getNodeID());
|
||||||
|
buffA[1] = (0);
|
||||||
|
buffA[2] = (EXIORDD);
|
||||||
|
addTask(buffA, 3, EXIORDD);
|
||||||
|
uint8_t buffB[3];
|
||||||
|
buffB[0] = (_currentNode->getNodeID());
|
||||||
|
buffB[1] = (0);
|
||||||
|
buffB[2] = (EXIORDAN);
|
||||||
|
addTask(buffB, 3, EXIORDAN);
|
||||||
|
//DIAG(F("Polling node: %i"), _currentNode->getNodeID());
|
||||||
|
_currentNode = _currentNode->getNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (currentTask == nullptr) return;
|
||||||
|
|
||||||
if ( hasTasks()){
|
if ( hasTasks() && _currentMicros - _cycleStartTimeA >= _cycleTime){
|
||||||
|
_cycleStartTimeA = _currentMicros;
|
||||||
Task* currentTask = getTaskById(getNextTaskId());
|
Task* currentTask = getTaskById(getNextTaskId());
|
||||||
if (currentTask == nullptr) return;
|
|
||||||
if (!currentTask->rxMode) { // Check if a task was found
|
if (!currentTask->rxMode) { // Check if a task was found
|
||||||
currentTask->crcPassFail = 0;
|
currentTask->crcPassFail = 0;
|
||||||
uint16_t response_crc = crc16((uint8_t*)currentTask->commandArray, currentTask->byteCount-1);
|
uint16_t response_crc = crc16((uint8_t*)currentTask->commandArray, currentTask->byteCount-1);
|
||||||
@ -99,14 +125,16 @@ void RSproto::_loop(unsigned long currentMicros) {
|
|||||||
// delete task command after sending, for now
|
// delete task command after sending, for now
|
||||||
currentTask->rxMode = true;
|
currentTask->rxMode = true;
|
||||||
|
|
||||||
} else if (currentTask->rxMode) {
|
//DIAG(F("Polling Task: %i"), currentTask->taskID);
|
||||||
if (_serial->available() && currentTask->rxMode) {
|
markTaskCompleted(currentTask->taskID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( _serial->available()) {
|
||||||
|
|
||||||
|
|
||||||
uint16_t calculated_crc;
|
uint16_t calculated_crc;
|
||||||
int byteCount = 100;
|
int byteCount = 100;
|
||||||
|
|
||||||
uint8_t byte_array[byteCount];
|
|
||||||
int curByte = _serial->read();
|
int curByte = _serial->read();
|
||||||
|
|
||||||
if (curByte == 0xFE && flagStart == false) flagStart = true;
|
if (curByte == 0xFE && flagStart == false) flagStart = true;
|
||||||
@ -148,12 +176,8 @@ void RSproto::_loop(unsigned long currentMicros) {
|
|||||||
if (received_crc == calculated_crc) {
|
if (received_crc == calculated_crc) {
|
||||||
//DIAG(F("Loop CRC PASS"));
|
//DIAG(F("Loop CRC PASS"));
|
||||||
crcPass = true;
|
crcPass = true;
|
||||||
currentTask->crcPassFail = 1;
|
|
||||||
}else {
|
}else {
|
||||||
//DIAG(F("Loop CRC Fail %x %x"),received_crc,calculated_crc);
|
//DIAG(F("Loop CRC Fail %x %x"),received_crc,calculated_crc);
|
||||||
currentTask->processed = true;
|
|
||||||
|
|
||||||
currentTask->crcPassFail = -1;
|
|
||||||
}
|
}
|
||||||
flagEnded = false;
|
flagEnded = false;
|
||||||
|
|
||||||
@ -165,17 +189,11 @@ void RSproto::_loop(unsigned long currentMicros) {
|
|||||||
int nodeTo = received_data[0];
|
int nodeTo = received_data[0];
|
||||||
if (nodeTo == 0) { // for master. master does not retransmit, or a loop will runaway.
|
if (nodeTo == 0) { // for master. master does not retransmit, or a loop will runaway.
|
||||||
flagProc = true;
|
flagProc = true;
|
||||||
currentTask->gotCallback = true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//DIAG(F("IO_RSproto: CRC Error!"));
|
//DIAG(F("IO_RSproto: CRC Error!"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// temp debug
|
|
||||||
|
|
||||||
|
|
||||||
if (flagProc) {
|
if (flagProc) {
|
||||||
int nodeTo = received_data[0];
|
int nodeTo = received_data[0];
|
||||||
@ -220,88 +238,54 @@ void RSproto::_loop(unsigned long currentMicros) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentTask->processed = true;
|
|
||||||
node->resFlag[currentTask->retFlag] = 1;
|
|
||||||
break;}
|
break;}
|
||||||
case EXIOINITA: {
|
case EXIOINITA: {
|
||||||
for (int i = 0; i < node->getnumAnalogPins(); i++) {
|
for (int i = 0; i < node->getnumAnalogPins(); i++) {
|
||||||
node->setanalogPinMap(received_data[i+3], i);
|
node->setanalogPinMap(received_data[i+3], i);
|
||||||
}
|
}
|
||||||
currentTask->processed = true;
|
|
||||||
node->resFlag[currentTask->retFlag] = 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXIOVER: {
|
case EXIOVER: {
|
||||||
node->setMajVer(received_data[3]);
|
node->setMajVer(received_data[3]);
|
||||||
node->setMinVer(received_data[4]);
|
node->setMinVer(received_data[4]);
|
||||||
node->setPatVer(received_data[5]);
|
node->setPatVer(received_data[5]);
|
||||||
DIAG(F("EX-IOExpander485: Found node %i v%i.%i.%i"),nodeFr, node->getMajVer(), node->getMinVer(), node->getPatVer());
|
DIAG(F("EX-IOExpander485: Found node %i v%i.%i.%i"),node->getNodeID(), node->getMajVer(), node->getMinVer(), node->getPatVer());
|
||||||
//if (!_currentNode->isInitialised()) {
|
node->setInitialised();
|
||||||
//_currentNode->setInitialised();
|
//DIAG(F("EX-IOExpander485: Initialized Node:%d "), node->getNodeID());
|
||||||
//DIAG(F("EX-IOExpander485: Initialized Node:%d "), nodeFr);
|
|
||||||
//}
|
|
||||||
currentTask->processed = true;
|
|
||||||
node->resFlag[currentTask->retFlag] = 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXIORDY: {
|
case EXIORDY: {
|
||||||
currentTask->processed = true;
|
|
||||||
node->resFlag[currentTask->retFlag] = 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXIOERR: {
|
case EXIOERR: {
|
||||||
currentTask->processed = true;
|
DIAG(F("EX-IOExplorer485: Some sort of error was received... WHAT DID YOU DO!")); // ;-)
|
||||||
node->resFlag[currentTask->retFlag] = -1;
|
|
||||||
DIAG(F("Some sort of error was received... WHAT DID YOU DO!"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case EXIORDD: {
|
|
||||||
for (int i = 0; i < (node->_numDigitalPins+7)/8; i++) {
|
|
||||||
node->setanalogInputStates(received_data[i+3], i);
|
|
||||||
}
|
|
||||||
currentTask->processed = true;
|
|
||||||
node->resFlag[currentTask->retFlag] = 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXIORDAN: {
|
case EXIORDAN: {
|
||||||
for (int i = 0; i < node->_numAnaloguePins; i++) {
|
for (int i = 0; i < node->_numAnaloguePins; i++) {
|
||||||
node->setanalogInputBuffer(received_data[i+3], i);
|
node->setanalogInputBuffer(received_data[i+3], i);
|
||||||
}
|
}
|
||||||
currentTask->processed = true;
|
|
||||||
node->resFlag[currentTask->retFlag] = 1;
|
break;
|
||||||
|
}
|
||||||
|
case EXIORDD: {
|
||||||
|
for (int i = 0; i < (node->_numDigitalPins+7)/8; i++) {
|
||||||
|
node->setdigitalInputStates(received_data[i+3], i);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
flagProc = false;
|
flagProc = false;
|
||||||
|
|
||||||
}
|
|
||||||
if (currentTask->processed) {
|
|
||||||
markTaskCompleted(currentTask->taskID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// temp debug
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (_currentMicros - _cycleStartTime >= _cycleTime/* && _currentNode->isInitialised()*/) {
|
|
||||||
_cycleStartTime = _currentMicros;
|
|
||||||
if (_currentNode == NULL) _currentNode = _nodeListStart;
|
|
||||||
RSproto *bus = RSproto::findBus(0);
|
|
||||||
uint8_t buffB[3];
|
|
||||||
buffB[0] = (_currentNode->getNodeID());
|
|
||||||
buffB[1] = (0);
|
|
||||||
buffB[2] = (EXIORDD);
|
|
||||||
bus->setBusy();
|
|
||||||
bus->addTask(buffB, 3, EXIORDD);
|
|
||||||
|
|
||||||
buffB[0] = (_currentNode->getNodeID());
|
|
||||||
buffB[1] = (0);
|
|
||||||
buffB[2] = (EXIORDD);
|
|
||||||
bus->setBusy();
|
|
||||||
bus->addTask(buffB, 3, EXIORDAN);
|
|
||||||
_currentNode = _currentNode->getNext();
|
|
||||||
//DIAG(F("Polling"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link to chain of RSproto instances, left over from RSproto template.
|
// Link to chain of RSproto instances, left over from RSproto template.
|
||||||
@ -406,7 +390,7 @@ void RSprotonode::_begin() {
|
|||||||
bus->addTask(buff, 3, EXIOVER);
|
bus->addTask(buff, 3, EXIOVER);
|
||||||
|
|
||||||
|
|
||||||
setInitialised();
|
//setInitialised();
|
||||||
#ifdef DIAG_IO
|
#ifdef DIAG_IO
|
||||||
_display();
|
_display();
|
||||||
#endif
|
#endif
|
||||||
|
14
IO_RSproto.h
14
IO_RSproto.h
@ -122,6 +122,8 @@ public:
|
|||||||
Bounce = 4, // For semaphores/turnouts with a bit of bounce!!
|
Bounce = 4, // For semaphores/turnouts with a bit of bounce!!
|
||||||
NoPowerOff = 0x80, // Flag to be ORed in to suppress power off after move.
|
NoPowerOff = 0x80, // Flag to be ORed in to suppress power off after move.
|
||||||
};
|
};
|
||||||
|
void _pollDigital(unsigned long currentMicros);
|
||||||
|
void _pollAnalog(unsigned long currentMicros);
|
||||||
|
|
||||||
uint8_t _numDigitalPins = 0;
|
uint8_t _numDigitalPins = 0;
|
||||||
uint8_t getnumDigialPins() {
|
uint8_t getnumDigialPins() {
|
||||||
@ -277,6 +279,7 @@ private:
|
|||||||
// Here we define the device-specific variables.
|
// Here we define the device-specific variables.
|
||||||
uint8_t _busNo;
|
uint8_t _busNo;
|
||||||
unsigned long _cycleStartTime = 0;
|
unsigned long _cycleStartTime = 0;
|
||||||
|
unsigned long _cycleStartTimeA = 0;
|
||||||
unsigned long _timeoutStart = 0;
|
unsigned long _timeoutStart = 0;
|
||||||
unsigned long _cycleTime; // target time between successive read/write cycles, microseconds
|
unsigned long _cycleTime; // target time between successive read/write cycles, microseconds
|
||||||
unsigned long _timeoutPeriod; // timeout on read responses, in microseconds.
|
unsigned long _timeoutPeriod; // timeout on read responses, in microseconds.
|
||||||
@ -286,7 +289,7 @@ private:
|
|||||||
int _operationCount = 0;
|
int _operationCount = 0;
|
||||||
int _refreshOperation = 0;
|
int _refreshOperation = 0;
|
||||||
byte bufferLength;
|
byte bufferLength;
|
||||||
static const int ARRAY_SIZE = 75;
|
static const int ARRAY_SIZE = 150;
|
||||||
int buffer[ARRAY_SIZE];
|
int buffer[ARRAY_SIZE];
|
||||||
byte inCommandPayload;
|
byte inCommandPayload;
|
||||||
static RSproto *_busList; // linked list of defined bus instances
|
static RSproto *_busList; // linked list of defined bus instances
|
||||||
@ -321,7 +324,7 @@ private:
|
|||||||
int byteCounter = 0;
|
int byteCounter = 0;
|
||||||
public:
|
public:
|
||||||
struct Task {
|
struct Task {
|
||||||
static const int ARRAY_SIZE = 254;
|
static const int ARRAY_SIZE = 150;
|
||||||
int taskID;
|
int taskID;
|
||||||
uint8_t commandArray[ARRAY_SIZE];
|
uint8_t commandArray[ARRAY_SIZE];
|
||||||
int byteCount;
|
int byteCount;
|
||||||
@ -332,7 +335,7 @@ struct Task {
|
|||||||
bool completed;
|
bool completed;
|
||||||
bool processed;
|
bool processed;
|
||||||
};
|
};
|
||||||
static const int MAX_TASKS = 100;
|
static const int MAX_TASKS = 50;
|
||||||
int taskIDCntr = 0;
|
int taskIDCntr = 0;
|
||||||
Task taskBuffer[MAX_TASKS]; // Buffer to hold up to 100 tasks
|
Task taskBuffer[MAX_TASKS]; // Buffer to hold up to 100 tasks
|
||||||
int currentTaskIndex = 0;
|
int currentTaskIndex = 0;
|
||||||
@ -363,7 +366,7 @@ void addTask(const uint8_t* cmd, int byteCount, uint8_t retFlag) {
|
|||||||
DIAG(F("Task Buffer Full!"));
|
DIAG(F("Task Buffer Full!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < ARRAY_SIZE; i++) taskBuffer[emptySlot].commandArray[i] = cmd[i];
|
for (int i = 0; i < byteCount; i++) taskBuffer[emptySlot].commandArray[i] = cmd[i];
|
||||||
taskBuffer[emptySlot].byteCount = byteCount;
|
taskBuffer[emptySlot].byteCount = byteCount;
|
||||||
taskBuffer[emptySlot].retFlag = retFlag;
|
taskBuffer[emptySlot].retFlag = retFlag;
|
||||||
taskBuffer[emptySlot].rxMode = false;
|
taskBuffer[emptySlot].rxMode = false;
|
||||||
@ -447,6 +450,9 @@ uint16_t crc16(uint8_t *data, uint16_t length);
|
|||||||
uint16_t _pullup;
|
uint16_t _pullup;
|
||||||
uint16_t _pin;
|
uint16_t _pin;
|
||||||
int8_t _txPin;
|
int8_t _txPin;
|
||||||
|
int8_t getTxPin() {
|
||||||
|
return _txPin;
|
||||||
|
}
|
||||||
bool _busy = false;
|
bool _busy = false;
|
||||||
void setBusy() {
|
void setBusy() {
|
||||||
_busy = true;
|
_busy = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user