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:
parent
51058a66f3
commit
25c01e0ca4
@ -90,9 +90,31 @@ void EXIO485::_loop(unsigned long currentMicros) {
|
||||
DIAG(F("Polling"));
|
||||
}
|
||||
|
||||
if ( hasTasks() && _currentMicros - _cycleStartTimeA >= _cycleTime){
|
||||
if ( hasTasks()){
|
||||
_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
|
||||
currentTask->crcPassFail = 0;
|
||||
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
|
||||
currentTask->rxMode = true;
|
||||
DIAG(F("Task"));
|
||||
markTaskCompleted(currentTask->taskID);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if ( _serial->available()) {
|
||||
|
||||
|
||||
@ -214,11 +235,13 @@ void EXIO485::_loop(unsigned long currentMicros) {
|
||||
}
|
||||
}
|
||||
}
|
||||
markTaskCompleted(currentTask->taskID);
|
||||
break;}
|
||||
case EXIOINITA: {
|
||||
for (int i = 0; i < node->getnumAnalogPins(); i++) {
|
||||
node->setanalogPinMap(received_data[i+3], i);
|
||||
}
|
||||
markTaskCompleted(currentTask->taskID);
|
||||
break;
|
||||
}
|
||||
case EXIOVER: {
|
||||
@ -227,12 +250,15 @@ void EXIO485::_loop(unsigned long currentMicros) {
|
||||
node->setPatVer(received_data[5]);
|
||||
DIAG(F("EX-IOExpander485: Found node %i v%i.%i.%i"),node->getNodeID(), node->getMajVer(), node->getMinVer(), node->getPatVer());
|
||||
node->setInitialised();
|
||||
markTaskCompleted(currentTask->taskID);
|
||||
break;
|
||||
}
|
||||
case EXIORDY: {
|
||||
markTaskCompleted(currentTask->taskID);
|
||||
break;
|
||||
}
|
||||
case EXIOERR: {
|
||||
markTaskCompleted(currentTask->taskID);
|
||||
DIAG(F("EX-IOExplorer485: Some sort of error was received...")); // ;-)
|
||||
break;
|
||||
}
|
||||
@ -240,13 +266,14 @@ void EXIO485::_loop(unsigned long currentMicros) {
|
||||
for (int i = 0; i < node->_numAnaloguePins; i++) {
|
||||
node->setanalogInputBuffer(received_data[i+3], i);
|
||||
}
|
||||
|
||||
markTaskCompleted(currentTask->taskID);
|
||||
break;
|
||||
}
|
||||
case EXIORDD: {
|
||||
for (int i = 0; i < (node->_numDigitalPins+7)/8; i++) {
|
||||
node->setdigitalInputStates(received_data[i+3], i);
|
||||
}
|
||||
markTaskCompleted(currentTask->taskID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -254,13 +281,8 @@ void EXIO485::_loop(unsigned long currentMicros) {
|
||||
}
|
||||
flagProc = false;
|
||||
}
|
||||
|
||||
// temp debug
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Link to chain of EXIO485 instances, left over from EXIO485 template.
|
||||
|
@ -428,6 +428,8 @@ struct Task {
|
||||
};
|
||||
static const int MAX_TASKS = 50;
|
||||
int taskIDCntr = 0;
|
||||
int CurrentTaskID = -1;
|
||||
int taskResendCount = 0;
|
||||
Task taskBuffer[MAX_TASKS]; // Buffer to hold up to 100 tasks
|
||||
int currentTaskIndex = 0;
|
||||
void initTask() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user