Skip to content

Commit a358230

Browse files
committed
convert rcs_status to class enum
1 parent 3cb4dad commit a358230

14 files changed

Lines changed: 107 additions & 106 deletions

File tree

src/emc/iotask/ioControl.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static int emcIoNmlGet()
165165
emcioStatus.heartbeat = 0;
166166
emcioStatus.command_type = 0;
167167
emcioStatus.echo_serial_number = 0;
168-
emcioStatus.status = RCS_DONE;
168+
emcioStatus.status = RCS_STATUS::DONE;
169169
emcioStatusBuffer->write(&emcioStatus);
170170
}
171171
}
@@ -562,7 +562,7 @@ void load_tool(int idx) {
562562
}
563563

564564
if (0 != tooldata_save(io_tool_table_file)) {
565-
emcioStatus.status = RCS_ERROR;
565+
emcioStatus.status = RCS_STATUS::ERROR;
566566
}
567567
} else if(idx == 0) {
568568
// on non-random tool-changers, asking for pocket 0 is the secret
@@ -622,7 +622,7 @@ static int read_tool_inputs(void)
622622
if (*iocontrol_data->tool_prepare && *iocontrol_data->tool_prepared) {
623623
emcioStatus.tool.pocketPrepped = *iocontrol_data->tool_prep_index; //check if tool has been (idx) prepared
624624
*(iocontrol_data->tool_prepare) = 0;
625-
emcioStatus.status = RCS_DONE; // we finally finished to do tool-changing, signal task with RCS_DONE
625+
emcioStatus.status = RCS_STATUS::DONE; // we finally finished to do tool-changing, signal task with RCS_DONE
626626
return 10; //prepped finished
627627
}
628628

@@ -649,7 +649,7 @@ static int read_tool_inputs(void)
649649
*(iocontrol_data->tool_prep_pocket) = 0; //likewise in HAL
650650
*(iocontrol_data->tool_prep_index) = 0; //likewise in HAL
651651
*(iocontrol_data->tool_change) = 0; //also reset the tool change signal
652-
emcioStatus.status = RCS_DONE; // we finally finished to do tool-changing, signal task with RCS_DONE
652+
emcioStatus.status = RCS_STATUS::DONE; // we finally finished to do tool-changing, signal task with RCS_DONE
653653
return 11; //change finished
654654
}
655655
return 0;
@@ -835,7 +835,7 @@ int main(int argc, char *argv[])
835835
}
836836

837837
type = emcioCommand->type;
838-
emcioStatus.status = RCS_DONE;
838+
emcioStatus.status = RCS_STATUS::DONE;
839839

840840
switch (type) {
841841
case 0:
@@ -921,7 +921,7 @@ int main(int argc, char *argv[])
921921
// the feedback logic is done inside read_hal_inputs()
922922
// we only need to set RCS_EXEC if RCS_DONE is not already set by the above logic
923923
if (tool_status != 10) //set above to 10 in case PREP already finished (HAL loopback machine)
924-
emcioStatus.status = RCS_EXEC;
924+
emcioStatus.status = RCS_STATUS::EXEC;
925925
}
926926
break;
927927
case EMC_TOOL_LOAD_TYPE:
@@ -952,7 +952,7 @@ int main(int argc, char *argv[])
952952
if (tool_status != 11)
953953
// set above to 11 in case LOAD already finished (HAL
954954
// loopback machine)
955-
emcioStatus.status = RCS_EXEC;
955+
emcioStatus.status = RCS_STATUS::EXEC;
956956
}
957957
break;
958958
}
@@ -968,7 +968,7 @@ int main(int argc, char *argv[])
968968
if(!strlen(filename)) filename = io_tool_table_file;
969969
rtapi_print_msg(RTAPI_MSG_DBG, "EMC_TOOL_LOAD_TOOL_TABLE\n");
970970
if (0 != tooldata_load(filename)) {
971-
emcioStatus.status = RCS_ERROR;
971+
emcioStatus.status = RCS_STATUS::ERROR;
972972
} else {
973973
reload_tool_number(emcioStatus.tool.toolInSpindle);
974974
}
@@ -1007,7 +1007,7 @@ int main(int argc, char *argv[])
10071007
UNEXPECTED_MSG;
10081008
}
10091009
if (0 != tooldata_save(io_tool_table_file)) {
1010-
emcioStatus.status = RCS_ERROR;
1010+
emcioStatus.status = RCS_STATUS::ERROR;
10111011
}
10121012
if (io_db_mode == DB_ACTIVE) {
10131013
int pno = idx; // for random_toolchanger

src/emc/iotask/ioControl_v2.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static int emcIoNmlGet()
253253
emcioStatus.heartbeat = 0;
254254
emcioStatus.command_type = 0;
255255
emcioStatus.echo_serial_number = 0;
256-
emcioStatus.status = RCS_DONE;
256+
emcioStatus.status = RCS_STATUS::DONE;
257257
emcioStatusBuffer->write(&emcioStatus);
258258
}
259259
}
@@ -515,7 +515,7 @@ void load_tool(int idx) {
515515
}
516516

517517
if (0 != tooldata_save(io_tool_table_file)) {
518-
emcioStatus.status = RCS_ERROR;
518+
emcioStatus.status = RCS_STATUS::ERROR;
519519
}
520520
} else if(idx == 0) {
521521
// magic T0 = pocket 0 = no tool
@@ -736,14 +736,14 @@ static void do_hal_exit(void) {
736736
}
737737

738738

739-
static void update_status(int status, int serial)
739+
static void update_status(RCS_STATUS status, int serial)
740740
{
741-
static int status_reported = -1;
741+
static RCS_STATUS status_reported = RCS_STATUS::UNINITIALIZED;
742742

743743
emcioStatus.status = status;
744744
if (status_reported != status) {
745745
rtapi_print_msg(RTAPI_MSG_DBG, "%s: updating status=%s state=%s fault=%d reason=%d\n",
746-
progname,strcs[emcioStatus.status],strstate[*(iocontrol_data->state)],
746+
progname,strcs[(int)emcioStatus.status],strstate[*(iocontrol_data->state)],//BUG: array accessed at -1 when status is RCS_STATUS::UNINITIALIZED
747747
emcioStatus.fault, emcioStatus.reason
748748
);
749749
status_reported = emcioStatus.status; // just print this once
@@ -919,11 +919,11 @@ int main(int argc, char *argv[])
919919
rtapi_print_msg(RTAPI_MSG_DBG, "%s:lube_level changed to %d\n",progname,emcioStatus.lube.level);
920920

921921
// need for different serial number, because we are pushing a new message
922-
update_status(RCS_DONE, emcioCommand->serial_number + 1);
922+
update_status(RCS_STATUS::DONE, emcioCommand->serial_number + 1);
923923
}
924924

925925
if (input_status & (TI_PREPARING)) {
926-
update_status(RCS_EXEC, emcioCommand->serial_number);
926+
update_status(RCS_STATUS::EXEC, emcioCommand->serial_number);
927927
}
928928

929929
if (input_status & (TI_START_CHANGE|TI_CHANGING)) {
@@ -934,15 +934,15 @@ int main(int argc, char *argv[])
934934
strstate[*(iocontrol_data->state)],
935935
str_input(input_status)
936936
);
937-
update_status(RCS_ERROR, emcioCommand->serial_number);
937+
update_status(RCS_STATUS::ERROR, emcioCommand->serial_number);
938938
} else {
939-
update_status(RCS_EXEC, emcioCommand->serial_number);
939+
update_status(RCS_STATUS::EXEC, emcioCommand->serial_number);
940940
}
941941
}
942942

943943
// if (input_status & (TI_PREPARE_COMPLETE|TI_CHANGE_COMPLETE|TI_START_CHANGE_ACKED|TI_EMC_ABORT_ACKED))
944944
if (input_status & (TI_PREPARE_COMPLETE|TI_CHANGE_COMPLETE|TI_START_CHANGE_ACKED)) {
945-
update_status(RCS_DONE, emcioCommand->serial_number);
945+
update_status(RCS_STATUS::DONE, emcioCommand->serial_number);
946946
}
947947

948948
/* read NML, run commands */
@@ -970,7 +970,7 @@ int main(int argc, char *argv[])
970970
* to cause an abort, set emcioStatus.reason and
971971
* emcioStatus.status to RCS_ERROR.
972972
*/
973-
emcioStatus.status = RCS_DONE;
973+
emcioStatus.status = RCS_STATUS::DONE;
974974
type = emcioCommand->type;
975975

976976
switch (type) {
@@ -1061,7 +1061,7 @@ int main(int argc, char *argv[])
10611061

10621062
// delay fetching the next message until prepare done
10631063
if (!(input_status & TI_PREPARE_COMPLETE)) {
1064-
emcioStatus.status = RCS_EXEC;
1064+
emcioStatus.status = RCS_STATUS::EXEC;
10651065
}
10661066
}
10671067
}
@@ -1093,7 +1093,7 @@ int main(int argc, char *argv[])
10931093

10941094
// delay fetching the next message until change done
10951095
if (! (input_status & TI_CHANGE_COMPLETE)) {
1096-
emcioStatus.status = RCS_EXEC;
1096+
emcioStatus.status = RCS_STATUS::EXEC;
10971097
}
10981098
}
10991099
break;
@@ -1106,7 +1106,7 @@ int main(int argc, char *argv[])
11061106
*(iocontrol_data->state) = ST_START_CHANGE;
11071107
// delay fetching the next message until ack line seen
11081108
if (! (input_status & TI_START_CHANGE_ACKED)) {
1109-
emcioStatus.status = RCS_EXEC;
1109+
emcioStatus.status = RCS_STATUS::EXEC;
11101110
}
11111111
}
11121112
break;
@@ -1123,7 +1123,7 @@ int main(int argc, char *argv[])
11231123
if(!strlen(filename)) filename = io_tool_table_file;
11241124
rtapi_print_msg(RTAPI_MSG_DBG, "EMC_TOOL_LOAD_TOOL_TABLE\n");
11251125
if (0 != tooldata_load(filename)) {
1126-
emcioStatus.status = RCS_ERROR;
1126+
emcioStatus.status = RCS_STATUS::ERROR;
11271127
} else {
11281128
reload_tool_number(emcioStatus.tool.toolInSpindle);
11291129
}
@@ -1163,7 +1163,7 @@ int main(int argc, char *argv[])
11631163
UNEXPECTED_MSG;
11641164
}
11651165
if (0 != tooldata_save(io_tool_table_file)) {
1166-
emcioStatus.status = RCS_ERROR;
1166+
emcioStatus.status = RCS_STATUS::ERROR;
11671167
}
11681168
if (io_db_mode == DB_ACTIVE) {
11691169
int pno = idx; // for random_toolchanger

src/emc/task/emctaskmain.cc

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ static void mdi_execute_hook(void)
686686
emcStatus->task.execState == EMC_TASK_EXEC::DONE &&
687687
emcStatus->task.interpState != EMC_TASK_INTERP::IDLE &&
688688
emcStatus->motion.traj.queue == 0 &&
689-
emcStatus->io.status == RCS_DONE &&
689+
emcStatus->io.status == RCS_STATUS::DONE &&
690690
!mdi_execute_wait &&
691691
!mdi_execute_next) {
692692

@@ -717,7 +717,7 @@ void readahead_waiting(void)
717717
if (interp_list.len() == 0 &&
718718
emcTaskCommand == 0 &&
719719
emcStatus->motion.traj.queue == 0 &&
720-
emcStatus->io.status == RCS_DONE)
720+
emcStatus->io.status == RCS_STATUS::DONE)
721721
// finished
722722
{
723723
int was_open = taskplanopen;
@@ -2653,36 +2653,36 @@ static int emcTaskExecute(void)
26532653

26542654
case EMC_TASK_EXEC::WAITING_FOR_MOTION:
26552655
STEPPING_CHECK();
2656-
if (emcStatus->motion.status == RCS_ERROR) {
2656+
if (emcStatus->motion.status == RCS_STATUS::ERROR) {
26572657
// emcOperatorError(0, "error in motion controller");
26582658
emcStatus->task.execState = EMC_TASK_EXEC::ERROR;
2659-
} else if (emcStatus->motion.status == RCS_DONE) {
2659+
} else if (emcStatus->motion.status == RCS_STATUS::DONE) {
26602660
emcStatus->task.execState = EMC_TASK_EXEC::DONE;
26612661
emcTaskEager = 1;
26622662
}
26632663
break;
26642664

26652665
case EMC_TASK_EXEC::WAITING_FOR_IO:
26662666
STEPPING_CHECK();
2667-
if (emcStatus->io.status == RCS_ERROR) {
2667+
if (emcStatus->io.status == RCS_STATUS::ERROR) {
26682668
// emcOperatorError(0, "error in IO controller");
26692669
emcStatus->task.execState = EMC_TASK_EXEC::ERROR;
2670-
} else if (emcStatus->io.status == RCS_DONE) {
2670+
} else if (emcStatus->io.status == RCS_STATUS::DONE) {
26712671
emcStatus->task.execState = EMC_TASK_EXEC::DONE;
26722672
emcTaskEager = 1;
26732673
}
26742674
break;
26752675

26762676
case EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO:
26772677
STEPPING_CHECK();
2678-
if (emcStatus->motion.status == RCS_ERROR) {
2678+
if (emcStatus->motion.status == RCS_STATUS::ERROR) {
26792679
// emcOperatorError(0, "error in motion controller");
26802680
emcStatus->task.execState = EMC_TASK_EXEC::ERROR;
2681-
} else if (emcStatus->io.status == RCS_ERROR) {
2681+
} else if (emcStatus->io.status == RCS_STATUS::ERROR) {
26822682
// emcOperatorError(0, "error in IO controller");
26832683
emcStatus->task.execState = EMC_TASK_EXEC::ERROR;
2684-
} else if (emcStatus->motion.status == RCS_DONE &&
2685-
emcStatus->io.status == RCS_DONE) {
2684+
} else if (emcStatus->motion.status == RCS_STATUS::DONE &&
2685+
emcStatus->io.status == RCS_STATUS::DONE) {
26862686
emcStatus->task.execState = EMC_TASK_EXEC::DONE;
26872687
emcTaskEager = 1;
26882688
}
@@ -3434,7 +3434,7 @@ int main(int argc, char *argv[])
34343434
}
34353435

34363436
// toolchanger indicated fault code > 0
3437-
if ((emcStatus->io.status == RCS_ERROR) &&
3437+
if ((emcStatus->io.status == RCS_STATUS::ERROR) &&
34383438
emcStatus->io.fault) {
34393439
static int reported = -1;
34403440
if (emcStatus->io.reason > 0) {
@@ -3443,19 +3443,19 @@ int main(int argc, char *argv[])
34433443
emcStatus->io.fault, emcStatus->io.reason);
34443444
reported = emcStatus->io.fault;
34453445
}
3446-
emcStatus->io.status = RCS_DONE; // let program continue
3446+
emcStatus->io.status = RCS_STATUS::DONE; // let program continue
34473447
} else {
34483448
rcs_print("M6: toolchanger hard fault, reason=%d\n",
34493449
emcStatus->io.reason);
3450-
// abort since io.status is RCS_ERROR
3450+
// abort since io.status is RCS_STATUS::ERROR
34513451
}
34523452

34533453
}
34543454

34553455
if (!emcStatus->motion.on_soft_limit) {gave_soft_limit_message = 0;}
34563456

34573457
// check for subordinate errors, and halt task if so
3458-
if ( emcStatus->motion.status == RCS_ERROR
3458+
if ( emcStatus->motion.status == RCS_STATUS::ERROR
34593459
&& emcStatus->motion.on_soft_limit) {
34603460
if (!gave_soft_limit_message) {
34613461
emcOperatorError(0, "On Soft Limit");
@@ -3466,26 +3466,26 @@ int main(int argc, char *argv[])
34663466
}
34673467
gave_soft_limit_message = 1;
34683468
}
3469-
} else if (emcStatus->motion.status == RCS_ERROR ||
3470-
((emcStatus->io.status == RCS_ERROR) &&
3469+
} else if (emcStatus->motion.status == RCS_STATUS::ERROR ||
3470+
((emcStatus->io.status == RCS_STATUS::ERROR) &&
34713471
(emcStatus->io.reason <= 0))) {
34723472
/*! \todo FIXME-- duplicate code for abort,
34733473
also in emcTaskExecute()
34743474
and in emcTaskIssueCommand() */
34753475

3476-
if (emcStatus->io.status == RCS_ERROR) {
3476+
if (emcStatus->io.status == RCS_STATUS::ERROR) {
34773477
// this is an aborted M6.
34783478
if (emc_debug & EMC_DEBUG_RCS ) {
3479-
rcs_print("io.status=RCS_ERROR, fault=%d reason=%d\n",
3479+
rcs_print("io.status=RCS_STATUS::ERROR, fault=%d reason=%d\n",
34803480
emcStatus->io.fault, emcStatus->io.reason);
34813481
}
34823482
if (emcStatus->io.reason < 0) {
34833483
emcOperatorError(0, io_error, emcStatus->io.reason);
34843484
}
34853485
}
3486-
// motion already should have reported this condition (and set RCS_ERROR?)
3486+
// motion already should have reported this condition (and set RCS_STATUS::ERROR?)
34873487
// an M19 orient failed to complete within timeout
3488-
// if ((emcStatus->motion.status == RCS_ERROR) &&
3488+
// if ((emcStatus->motion.status == RCS_STATUS::ERROR) &&
34893489
// (emcStatus->motion.spindle.orient_state == EMCMOT_ORIENT_FAULTED) &&
34903490
// (emcStatus->motion.spindle.orient_fault != 0)) {
34913491
// emcOperatorError(0, "wait for orient complete timed out");
@@ -3541,23 +3541,23 @@ int main(int argc, char *argv[])
35413541

35423542
if (taskPlanError || taskExecuteError ||
35433543
emcStatus->task.execState == EMC_TASK_EXEC::ERROR ||
3544-
emcStatus->motion.status == RCS_ERROR ||
3545-
emcStatus->io.status == RCS_ERROR) {
3546-
emcStatus->status = RCS_ERROR;
3547-
emcStatus->task.status = RCS_ERROR;
3544+
emcStatus->motion.status == RCS_STATUS::ERROR ||
3545+
emcStatus->io.status == RCS_STATUS::ERROR) {
3546+
emcStatus->status = RCS_STATUS::ERROR;
3547+
emcStatus->task.status = RCS_STATUS::ERROR;
35483548
} else if (!taskPlanError && !taskExecuteError &&
35493549
emcStatus->task.execState == EMC_TASK_EXEC::DONE &&
3550-
emcStatus->motion.status == RCS_DONE &&
3551-
emcStatus->io.status == RCS_DONE &&
3550+
emcStatus->motion.status == RCS_STATUS::DONE &&
3551+
emcStatus->io.status == RCS_STATUS::DONE &&
35523552
mdi_execute_queue.len() == 0 &&
35533553
interp_list.len() == 0 &&
35543554
emcTaskCommand == 0 &&
35553555
emcStatus->task.interpState == EMC_TASK_INTERP::IDLE) {
3556-
emcStatus->status = RCS_DONE;
3557-
emcStatus->task.status = RCS_DONE;
3556+
emcStatus->status = RCS_STATUS::DONE;
3557+
emcStatus->task.status = RCS_STATUS::DONE;
35583558
} else {
3559-
emcStatus->status = RCS_EXEC;
3560-
emcStatus->task.status = RCS_EXEC;
3559+
emcStatus->status = RCS_STATUS::EXEC;
3560+
emcStatus->task.status = RCS_STATUS::EXEC;
35613561
}
35623562

35633563
// write it

src/emc/task/taskclass.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int sendCommand(RCS_CMD_MSG * msg)
179179
while (etime() < send_command_timeout) {
180180
emcIoStatusBuffer->peek();
181181
if (emcIoStatus->echo_serial_number != emcIoCommandSerialNumber ||
182-
emcIoStatus->status == RCS_EXEC) {
182+
emcIoStatus->status == RCS_STATUS::EXEC) {
183183
esleep(0.001);
184184
continue;
185185
} else {
@@ -188,7 +188,7 @@ static int sendCommand(RCS_CMD_MSG * msg)
188188
}
189189

190190
if (emcIoStatus->echo_serial_number != emcIoCommandSerialNumber ||
191-
emcIoStatus->status == RCS_EXEC) {
191+
emcIoStatus->status == RCS_STATUS::EXEC) {
192192
// Still not done, must have timed out.
193193
rcs_print_error
194194
("Command to IO level (%s:%s) timed out waiting for last command done. \n",
@@ -785,9 +785,9 @@ int Task::emcIoUpdate(EMC_IO_STAT * stat)
785785
command, by comparing the command number we sent with the command
786786
number that emcio echoes. If they're different, then the command
787787
hasn't been acknowledged yet and the state should be forced to be
788-
RCS_EXEC. */
788+
RCS_STATUS::EXEC. */
789789
if (stat->echo_serial_number != emcIoCommandSerialNumber) {
790-
stat->status = RCS_EXEC;
790+
stat->status = RCS_STATUS::EXEC;
791791
}
792792
//commented out because it keeps resetting the spindle speed to some odd value
793793
//the speed gets set by the IO controller, no need to override it here (io takes care of increase/decrease speed too)

0 commit comments

Comments
 (0)