Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 25 additions & 51 deletions src/emc/motion/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
Called by task using [KINS]JOINTS= which is typically
the same value as the motmod num_joints= parameter
*/
rtapi_print_msg(RTAPI_MSG_DBG, "SET_NUM_JOINTS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->joint);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_NUM_JOINTS %d", emcmotCommand->joint);
if (( emcmotCommand->joint <= 0 ) ||
( emcmotCommand->joint > EMCMOT_MAX_JOINTS )) {
break;
Expand All @@ -679,9 +678,8 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
the number of spindles configured for the motion module
(motion_num_spindles)
*/
rtapi_print_msg(RTAPI_MSG_DBG, "SET_NUM_SPINDLES");
rtapi_print_msg(RTAPI_MSG_DBG, "SET_NUM_SPINDLES %d", emcmotCommand->spindle);
emcmot_config_change();
rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->spindle);
if ( emcmotCommand->spindle > motion_num_spindles
|| emcmotCommand->spindle <= 0
|| emcmotCommand->spindle > EMCMOT_MAX_SPINDLES
Expand All @@ -706,8 +704,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
break;

case EMCMOT_SET_JOINT_HOMING_PARAMS:
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_HOMING_PARAMS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_HOMING_PARAMS %d", joint_num);
emcmot_config_change();
if (joint == 0) {
break;
Expand All @@ -727,8 +724,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
break;

case EMCMOT_UPDATE_JOINT_HOMING_PARAMS:
rtapi_print_msg(RTAPI_MSG_DBG, "UPDATE_JOINT_HOMING_PARAMS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "UPDATE_JOINT_HOMING_PARAMS %d", joint_num);
emcmot_config_change();
if (joint == 0) {
break;
Expand All @@ -744,8 +740,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
/* this command can be issued with joint < 0 to re-enable
limits, but they are automatically re-enabled at the
end of the next jog */
rtapi_print_msg(RTAPI_MSG_DBG, "OVERRIDE_LIMITS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "OVERRIDE_LIMITS %d", joint_num);
if (joint_num < 0) {
/* don't override limits */
rtapi_print_msg(RTAPI_MSG_DBG, "override off");
Expand Down Expand Up @@ -775,8 +770,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
break;

case EMCMOT_SET_JOINT_MOTOR_OFFSET:
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_MOTOR_OFFSET");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_MOTOR_OFFSET %d", joint_num);
if(joint == 0) {
break;
}
Expand All @@ -786,8 +780,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
case EMCMOT_SET_JOINT_POSITION_LIMITS:
/* set the position limits for the joint */
/* can be done at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_POSITION_LIMITS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_POSITION_LIMITS %d", joint_num);
emcmot_config_change();
if (joint == 0) {
break;
Expand All @@ -799,8 +792,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
case EMCMOT_SET_JOINT_BACKLASH:
/* set the backlash for the joint */
/* can be done at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_BACKLASH");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_BACKLASH %d", joint_num);
emcmot_config_change();
if (joint == 0) {
break;
Expand All @@ -815,8 +807,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
minFerror then OK else if ferror < limiting ferror then OK
else ERROR */
case EMCMOT_SET_JOINT_MAX_FERROR:
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_MAX_FERROR");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_MAX_FERROR %d", joint_num);
emcmot_config_change();
if (joint == 0 || emcmotCommand->maxFerror < 0.0) {
break;
Expand All @@ -825,8 +816,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
break;

case EMCMOT_SET_JOINT_MIN_FERROR:
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_MIN_FERROR");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_MIN_FERROR %d", joint_num);
emcmot_config_change();
if (joint == 0 || emcmotCommand->minFerror < 0.0) {
break;
Expand All @@ -838,8 +828,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
/* do a continuous jog, implemented as an incremental jog to the
limit. When the user lets go of the button an abort will
stop the jog. */
rtapi_print_msg(RTAPI_MSG_DBG, "JOG_CONT");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "JOG_CONT %d", joint_num);
if (!GET_MOTION_ENABLE_FLAG()) {
reportError(_("Can't jog joint when not enabled."));
SET_JOINT_ERROR_FLAG(joint, 1);
Expand Down Expand Up @@ -907,8 +896,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)

case EMCMOT_JOG_INCR:
/* do an incremental jog */
rtapi_print_msg(RTAPI_MSG_DBG, "JOG_INCR");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "JOG_INCR %d", joint_num);
if (!GET_MOTION_ENABLE_FLAG()) {
reportError(_("Can't jog joint when not enabled."));
SET_JOINT_ERROR_FLAG(joint, 1);
Expand Down Expand Up @@ -984,8 +972,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)

case EMCMOT_JOG_ABS:
/* do an absolute jog */
rtapi_print_msg(RTAPI_MSG_DBG, "JOG_ABS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "JOG_ABS %d", joint_num);
if (joint == 0) {
break;
}
Expand Down Expand Up @@ -1208,8 +1195,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
case EMCMOT_SET_JOINT_VEL_LIMIT:
/* set joint max velocity */
/* can do it at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_VEL_LIMIT");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_VEL_LIMIT %d", joint_num);
emcmot_config_change();
/* check joint range */
if (joint == 0) {
Expand All @@ -1221,8 +1207,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
case EMCMOT_SET_JOINT_ACC_LIMIT:
/* set joint max acceleration */
/* can do it at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_ACC_LIMIT");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_ACC_LIMIT %d", joint_num);
emcmot_config_change();
/* check joint range */
if (joint == 0) {
Expand All @@ -1234,8 +1219,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
case EMCMOT_SET_JOINT_JERK_LIMIT:
/* set joint max jerk */
/* can do it at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_JERK_LIMIT");
rtapi_print_msg(RTAPI_MSG_DBG, " j(%d) jerk(%f)", joint_num, emcmotCommand->jerk);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_JERK_LIMIT j(%d) jerk(%f)", joint_num, emcmotCommand->jerk);
emcmot_config_change();
if (joint == 0) {
break;
Expand Down Expand Up @@ -1483,8 +1467,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
/* make joint active, so that amps will be enabled when system is
enabled or disabled */
/* can be done at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "JOINT_ACTIVATE");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "JOINT_ACTIVATE %d", joint_num);
if (joint == 0) {
break;
}
Expand All @@ -1495,8 +1478,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
/* make joint inactive, so that amps won't be affected when system
is enabled or disabled */
/* can be done at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "JOINT_DEACTIVATE");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "JOINT_DEACTIVATE %d", joint_num);
if (joint == 0) {
break;
}
Expand All @@ -1508,8 +1490,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
/* need to be in free mode, enable on */
/* this just sets the initial state, then the state machine in
homing.c does the rest */
rtapi_print_msg(RTAPI_MSG_DBG, "JOINT_HOME");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "JOINT_HOME %d", joint_num);

/* Normally homing requires free (joint) mode. The queued G28.2 path
* (emctaskmain EMC_TASK_EXEC::WAITING_FOR_HOMING) dips motion into
Expand Down Expand Up @@ -1550,8 +1531,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)

case EMCMOT_JOINT_UNHOME:
/* unhome the specified joint, or all joints if -1, or volatile joints if -2 */
rtapi_print_msg(RTAPI_MSG_DBG, "JOINT_UNHOME");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);
rtapi_print_msg(RTAPI_MSG_DBG, "JOINT_UNHOME %d", joint_num);

if ( (emcmotStatus->motion_state != EMCMOT_MOTION_FREE)
&& (emcmotStatus->motion_state != EMCMOT_MOTION_DISABLED)) {
Expand Down Expand Up @@ -2043,8 +2023,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
case EMCMOT_SET_AXIS_POSITION_LIMITS:
/* set the position limits for axis */
/* can be done at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_POSITION_LIMITS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->axis);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_POSITION_LIMITS %d", emcmotCommand->axis);
emcmot_config_change();
if ((emcmotCommand->axis < 0) || (emcmotCommand->axis >= EMCMOT_MAX_AXIS)) {
break;
Expand All @@ -2056,8 +2035,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
case EMCMOT_SET_AXIS_VEL_LIMIT:
/* set the max axis vel */
/* can be done at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_VEL_LIMITS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->axis);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_VEL_LIMITS %d", emcmotCommand->axis);
emcmot_config_change();
if ((emcmotCommand->axis < 0) || (emcmotCommand->axis >= EMCMOT_MAX_AXIS)) {
break;
Expand All @@ -2069,8 +2047,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
case EMCMOT_SET_AXIS_ACC_LIMIT:
/* set the max axis acc */
/* can be done at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_ACC_LIMITS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->axis);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_ACC_LIMITS %d", emcmotCommand->axis);
emcmot_config_change();
if ((emcmotCommand->axis < 0) || (emcmotCommand->axis >= EMCMOT_MAX_AXIS)) {
break;
Expand All @@ -2082,8 +2059,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
case EMCMOT_SET_AXIS_JERK_LIMIT:
/* set the max axis jerk */
/* can be done at any time */
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_JERK_LIMITS");
rtapi_print_msg(RTAPI_MSG_DBG, " %d jerk(%f)", emcmotCommand->axis, emcmotCommand->jerk);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_JERK_LIMITS %d jerk(%f)", emcmotCommand->axis, emcmotCommand->jerk);
emcmot_config_change();
if ((emcmotCommand->axis < 0) || (emcmotCommand->axis >= EMCMOT_MAX_AXIS)) {
break;
Expand All @@ -2092,8 +2068,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
break;

case EMCMOT_SET_AXIS_LOCKING_JOINT:
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_ACC_LOCKING_JOINT");
rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->axis);
rtapi_print_msg(RTAPI_MSG_DBG, "SET_AXIS_ACC_LOCKING_JOINT %d", emcmotCommand->axis);
emcmot_config_change();
if ((emcmotCommand->axis < 0) || (emcmotCommand->axis >= EMCMOT_MAX_AXIS)) {
break;
Expand Down Expand Up @@ -2139,7 +2114,6 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
rtapi_print_msg(RTAPI_MSG_DBG, "ERROR: %d",
emcmotStatus->commandStatus);
}
rtapi_print_msg(RTAPI_MSG_DBG, "\n");
/* synch tail count */
rtapi_seqlock_write_end(&emcmotStatus->tail, &emcmotStatus->head);
rtapi_seqlock_write_end(&emcmotConfig->tail, &emcmotConfig->head);
Expand Down
3 changes: 3 additions & 0 deletions src/emc/motion/motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ void reportError(const char *fmt, ...)
char fmt_tmp[EMCMOT_ERROR_LEN];
size_t fmt_len = strlen(fmt);
//Manually check string length and truncate if it is to long
if(fmt_len > 0 && fmt[fmt_len-1] == '\n'){
fmt_len--;
}
if(fmt_len < EMCMOT_ERROR_LEN-1){
memcpy(fmt_tmp, fmt, fmt_len);
fmt_tmp[fmt_len+0] = '\n';
Expand Down
5 changes: 5 additions & 0 deletions src/emc/task/emctaskmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ static int emcOperatorErrorV(bool echo, const char *fmt, va_list ap)
// force a NULL at the end for safety
error_msg.error[LINELEN - 1] = 0;

// an error is one line: the GUI and the echo below end it
size_t n = strlen(error_msg.error);
while (n > 0 && error_msg.error[n - 1] == '\n')
error_msg.error[--n] = 0;

// write it
if (echo) {
log_info("{}\n", error_msg.error);
Expand Down
9 changes: 4 additions & 5 deletions src/hal/drivers/hal_ppmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,22 +566,21 @@ int rtapi_app_main(void)
slot = &(bus->slot_data[slotnum]);
/* rv1 is used to flag errors that fail one bus */
rv1 = 0;
rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: slot %d: ", slotnum);


/* check slot */
idcode = SelRead(slot->slot_base+SLOT_ID_OFFSET, slot->port_addr);
if ((idcode == 0)||(idcode == 0xFF)||((idcode&0x0f) == 0x0f)) {
// version of 0x0f will not be used so we can detect SLOT_ID_OFFSET
// being left on the bus by a non-implemented device slot
slot->id = 0;
slot->ver = 0;
rtapi_print_msg(RTAPI_MSG_INFO, "nothing detected at addr %x reads %x\n",
slotnum,idcode);
rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: slot %d: nothing detected at addr %x reads %x\n",
slotnum,slotnum,idcode);
ClrTimeout(slot->port_addr);
/* skip to next slot */
continue;
}
rtapi_print_msg(RTAPI_MSG_INFO, "ID code: %02X ", idcode);
rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: slot %d: ID code: %02X\n", slotnum, idcode);
slot->id = id = idcode & 0xF0;
slot->ver = ver = idcode & 0x0F;
slot->use_timestamp = 0; /* default is no timestamp */
Expand Down
25 changes: 19 additions & 6 deletions src/hal/drivers/mesa-hostmot2/hm2_modbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ static inline unsigned mtypesize(unsigned mtype) {
#define MSG_WARN(fmt...) do { rtapi_print_msg(RTAPI_MSG_WARN, fmt); } while(0)
#define MSG_PRINT(fmt...) do { rtapi_print(fmt); } while(0)

#ifdef DEBUG
// Debug dump of a frame, one message for every 16 bytes
static void dump_frame(const char *what, unsigned cmdidx, const rtapi_u8 *data, unsigned len)
{
for(unsigned i = 0; i < len; i += 16) {
char hex[16 * 3 + 1] = "";
unsigned n = 0;
for(unsigned j = i; j < len && j < i + 16; j++)
n += rtapi_snprintf(hex + n, sizeof(hex) - n, " %02x", data[j]);
MSG_DBG("%s cmd=%u [%u]:%s\n", what, cmdidx, i, hex);
}
}
#endif

// State-machine states
enum {
STATE_START = 0,
Expand Down Expand Up @@ -495,9 +509,8 @@ static int send_modbus_pkt(hm2_modbus_inst_t *inst)
cc->data[cc->datalen++] = (checksum >> 8) & 0xff;

#ifdef DEBUG
MSG_DBG("Sending cmd=%u to '%s' %i bytes", inst->cmdidx, inst->uart, cc->datalen);
for(int i = 0; i < cc->datalen; i++) MSG_DBG(" 0x%02x", cc->data[i]);
MSG_DBG("\n");
MSG_DBG("Sending cmd=%u to '%s' %i bytes\n", inst->cmdidx, inst->uart, cc->datalen);
dump_frame("Sending", inst->cmdidx, cc->data, cc->datalen);
#endif

rtapi_u8 frames = 1;
Expand Down Expand Up @@ -1719,13 +1732,13 @@ static int parse_data_frame(hm2_modbus_inst_t *inst)
return -1;
}

MSG_DBG("Return PDU cmd=%u is", inst->cmdidx);
for(unsigned i = 0; i < rxcount; i++) {
bytes[i] = (data[w] >> b) & 0xFF;
MSG_DBG(" %02x", bytes[i]);
if((b += 8) >= 32) { b = 0; w++; }
}
MSG_DBG("\n");
#ifdef DEBUG
dump_frame("Return PDU", inst->cmdidx, bytes, rxcount);
#endif

if(bytes[0] != cc->cmd.mbid) {
MSG_ERR("%s: error: Modbus device address mismatch: got 0x%02x, expected 0x%02x\n", inst->name, bytes[0], cc->cmd.mbid);
Expand Down
7 changes: 5 additions & 2 deletions src/hal/utils/halcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,17 @@ pid_t hal_systemv_nowait(const char *const argv[]) {
if ( pid == 0 ) {
/* child process */
/* print debugging info if "very verbose" (-V) */
char cmdline[1024] = "";
for(n=0; argv[n] != NULL; n++) {
rtapi_print_msg(RTAPI_MSG_DBG, "%s ", argv[n] );
if (n)
strncat(cmdline, " ", sizeof(cmdline) - strlen(cmdline) - 1);
strncat(cmdline, argv[n], sizeof(cmdline) - strlen(cmdline) - 1);
}
if (n == 0) {
halcmd_error("hal_systemv_nowait: empty argv array passed in\n");
exit(1);
}
rtapi_print_msg(RTAPI_MSG_DBG, "\n" );
rtapi_print_msg(RTAPI_MSG_DBG, "%s\n", cmdline);
/* call execv() to invoke command */
execvp(argv[0], (char * const *)argv);
/* should never get here */
Expand Down
13 changes: 11 additions & 2 deletions src/rtapi/rtai_rtapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,19 @@ int rtapi_snprintf(char *buf, unsigned long int size, const char *fmt, ...)

#define BUFFERLEN 1024

/* Every rtapi_print_msg() message is one line: end one that lacks the
newline. rtapi_print() (RTAPI_MSG_ALL) prints like printf. */
void default_rtapi_msg_handler(msg_level_t level, const char *fmt, va_list ap) {
char buf[BUFFERLEN];
rtapi_vsnprintf(buf, BUFFERLEN, fmt, ap);
rt_printk(buf);
size_t n;
/* leave room for the newline */
rtapi_vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
n = strlen(buf);
if (level != RTAPI_MSG_ALL && n > 0 && buf[n - 1] != '\n') {
buf[n] = '\n';
buf[n + 1] = '\0';
}
rt_printk("%s", buf);
}
static rtapi_msg_handler_t rtapi_msg_handler = default_rtapi_msg_handler;

Expand Down
Loading
Loading