1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-04-21 12:31:19 +02:00

update for better task handeling, untested

This commit is contained in:
travis-farmer 2024-12-26 17:21:02 -05:00
parent 51058a66f3
commit 25c01e0ca4
No known key found for this signature in database
GPG Key ID: 0BC296791D14CB35
2 changed files with 162 additions and 138 deletions

View File

@ -90,9 +90,31 @@ void EXIO485::_loop(unsigned long currentMicros) {
DIAG(F("Polling")); DIAG(F("Polling"));
} }
if ( hasTasks() && _currentMicros - _cycleStartTimeA >= _cycleTime){ if ( hasTasks()){
_cycleStartTimeA = _currentMicros; _cycleStartTimeA = _currentMicros;
Task* currentTask = getTaskById(getNextTaskId()); if (CurrentTaskID == -1) {
CurrentTaskID = getNextTaskId();
}
Task* currentTask = getTaskById(CurrentTaskID);
if (_currentMicros - _cycleStartTime > 1000000UL) { // timout every 1000ms
_cycleStartTime = _currentMicros;// reset timout
if (taskResendCount >= 2) { // max resends
markTaskCompleted(CurrentTaskID); // kill task and move on
CurrentTaskID = getNextTaskId(); // move on
taskResendCount = 0;
DIAG(F("Move on"));
} else {
currentTask->rxMode = false; // resend
taskResendCount++;
DIAG(F("Resend"));
}
}
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);
@ -113,9 +135,8 @@ void EXIO485::_loop(unsigned long currentMicros) {
// delete task command after sending, for now // delete task command after sending, for now
currentTask->rxMode = true; currentTask->rxMode = true;
DIAG(F("Task")); DIAG(F("Task"));
markTaskCompleted(currentTask->taskID);
} } else {
}
if ( _serial->available()) { if ( _serial->available()) {
@ -214,11 +235,13 @@ void EXIO485::_loop(unsigned long currentMicros) {
} }
} }
} }
markTaskCompleted(currentTask->taskID);
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);
} }
markTaskCompleted(currentTask->taskID);
break; break;
} }
case EXIOVER: { case EXIOVER: {
@ -227,12 +250,15 @@ void EXIO485::_loop(unsigned long currentMicros) {
node->setPatVer(received_data[5]); node->setPatVer(received_data[5]);
DIAG(F("EX-IOExpander485: Found node %i v%i.%i.%i"),node->getNodeID(), 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());
node->setInitialised(); node->setInitialised();
markTaskCompleted(currentTask->taskID);
break; break;
} }
case EXIORDY: { case EXIORDY: {
markTaskCompleted(currentTask->taskID);
break; break;
} }
case EXIOERR: { case EXIOERR: {
markTaskCompleted(currentTask->taskID);
DIAG(F("EX-IOExplorer485: Some sort of error was received...")); // ;-) DIAG(F("EX-IOExplorer485: Some sort of error was received...")); // ;-)
break; break;
} }
@ -240,13 +266,14 @@ void EXIO485::_loop(unsigned long currentMicros) {
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);
} }
markTaskCompleted(currentTask->taskID);
break; break;
} }
case EXIORDD: { case EXIORDD: {
for (int i = 0; i < (node->_numDigitalPins+7)/8; i++) { for (int i = 0; i < (node->_numDigitalPins+7)/8; i++) {
node->setdigitalInputStates(received_data[i+3], i); node->setdigitalInputStates(received_data[i+3], i);
} }
markTaskCompleted(currentTask->taskID);
break; break;
} }
} }
@ -254,13 +281,8 @@ void EXIO485::_loop(unsigned long currentMicros) {
} }
flagProc = false; flagProc = false;
} }
}
// temp debug }
} }
// Link to chain of EXIO485 instances, left over from EXIO485 template. // Link to chain of EXIO485 instances, left over from EXIO485 template.

View File

@ -428,6 +428,8 @@ struct Task {
}; };
static const int MAX_TASKS = 50; static const int MAX_TASKS = 50;
int taskIDCntr = 0; int taskIDCntr = 0;
int CurrentTaskID = -1;
int taskResendCount = 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;
void initTask() { void initTask() {