Skip to content
Draft
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
49 changes: 45 additions & 4 deletions src/emc/motion/motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,70 @@ void emcmot_config_change(void)
}
}

static rtapi_msg_handler_t old_handler = NULL;

void reportError(const char *fmt, ...)
{
va_list args;

va_start(args, fmt);

//Report trough emcmotError() so they are shown
//in the gui in the configured language.
emcmotErrorPutfv(emcmotError, fmt, args);

va_end(args);


//Report trough the old_handler which is typically
//the rtapi handler. These messages are shown on the console.
if(old_handler){
//We must add a \n due to reportError() strings normally
//don't have a newline at the end but rtapi_print() strings
//need one.
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 < EMCMOT_ERROR_LEN-1){
memcpy(fmt_tmp, fmt, fmt_len);
fmt_tmp[fmt_len+0] = '\n';
fmt_tmp[fmt_len+1] = '\0';
}else{
memcpy(fmt_tmp, fmt, EMCMOT_ERROR_LEN-2);
fmt_tmp[EMCMOT_ERROR_LEN-2] = '\n';
fmt_tmp[EMCMOT_ERROR_LEN-1] = '\0';
}

va_start(args, fmt);
old_handler(RTAPI_MSG_ERR, fmt_tmp, args);
Comment thread
hdiethelm marked this conversation as resolved.
va_end(args);
}
}

#ifndef va_copy
#define va_copy(dest, src) ((dest)=(src))
#endif

static rtapi_msg_handler_t old_handler = NULL;
static void emc_message_handler(msg_level_t level, const char *fmt, va_list ap)
{
va_list apc;
// False positive. Cppcheck does not seem to know the properties of va_copy()
// cppcheck-suppress va_list_usedBeforeStarted
va_copy(apc, ap);
// cppcheck-suppress va_list_usedBeforeStarted
if(level == RTAPI_MSG_ERR) emcmotErrorPutfv(emcmotError, fmt, apc);
else if(old_handler) old_handler(level, fmt, ap);

//Report errors trough emcmotError() so they are shown
//in the gui in the configured language.
if(level == RTAPI_MSG_ERR){
// cppcheck-suppress va_list_usedBeforeStarted
emcmotErrorPutfv(emcmotError, fmt, apc);
}

Comment thread
hdiethelm marked this conversation as resolved.
//Report everything trough the old_handler which is typically
//the rtapi handler. These messages are shown on the console.
if(old_handler){
old_handler(level, fmt, ap);
}

// cppcheck-suppress va_list_usedBeforeStarted
va_end(apc);
}
Expand Down
12 changes: 9 additions & 3 deletions src/emc/task/taskintf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2072,10 +2072,16 @@ int emcMotionUpdate(EMC_MOTION_STAT * stat)
}
// read the emcmot error
if (0 != usrmotReadEmcmotError(errorString)) {
// no error, so ignore
// no error, so ignore
} else {
// an error to report
emcOperatorError("%s", errorString);
// an error to report
// Disable stdout print due to this error is from motion
// and already printed to stdout
// emcOperatorError() also forwards the error to the gui
RCS_PRINT_DESTINATION_TYPE prev_dest = get_rcs_print_destination();
set_rcs_print_destination(RCS_PRINT_TO_NULL);
emcOperatorError("%s", errorString);
set_rcs_print_destination(prev_dest);
Comment thread
hdiethelm marked this conversation as resolved.
}

// save the heartbeat and command number locally,
Expand Down
46 changes: 22 additions & 24 deletions src/hal/drivers/mesa-hostmot2/hm2_modbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -2713,26 +2713,26 @@ int rtapi_app_main(void)

// Only touch the message level if requested
if(!debug)
MSG_PRINT(COMP_NAME": warning: Setting debug to 0 (zero) prevents error messages from being printed\n");
MSG_ERR(COMP_NAME": warning: Setting debug to 0 (zero) prevents error messages from being printed\n");
if(debug >= 0)
rtapi_set_msg_level(debug);

if(!ports[0]) {
MSG_PRINT(COMP_NAME": error: The component requires at least one valid pktuart port, eg ports=\"hm2_5i25.0.pktuart.7\"\n");
MSG_ERR(COMP_NAME": error: The component requires at least one valid pktuart port, eg ports=\"hm2_5i25.0.pktuart.7\"\n");
return -EINVAL;
}

comp_id = hal_init(COMP_NAME);
if(comp_id < 0) {
MSG_PRINT(COMP_NAME": error: hal_init() failed\n");
MSG_ERR(COMP_NAME": error: hal_init() failed\n");
return comp_id;
}

// Count the instances.
for(mb.ninsts = 0; mb.ninsts < MAX_PORTS && ports[mb.ninsts]; mb.ninsts++) {}
// Allocate memory for the instances
if(!(mb.insts = (hm2_modbus_inst_t *)rtapi_kzalloc(mb.ninsts * sizeof(*mb.insts), RTAPI_GFP_KERNEL))) {
MSG_PRINT(COMP_NAME": error: Allocate instance memory failed\n");
MSG_ERR(COMP_NAME": error: Allocate instance memory failed\n");
hal_exit(comp_id);
return -ENOMEM;
}
Expand All @@ -2745,15 +2745,13 @@ int rtapi_app_main(void)
rtapi_strlcpy(inst->uart, ports[i], sizeof(inst->uart)-1);

if(!mbccbs[i]) {
MSG_PRINT("%s: error: Missing mbccb file path for instance %d in 'mbccbs' argument\n", inst->name, i);
MSG_ERR("%s: error: Missing mbccb file path for instance %d in 'mbccbs' argument\n", inst->name, i);
retval = -EINVAL;
goto errout;
}
/*
if('/' != mbccbs[i][0]) {
MSG_PRINT("%s: warning: The 'mbccb' file path '%s' for instance %d in 'mbccbs' argument is not absolute\n", inst->name, mbccbs[i], i);
MSG_ERR("%s: warning: The 'mbccb' file path '%s' for instance %d in 'mbccbs' argument is not absolute\n", inst->name, mbccbs[i], i);
}
*/

if((retval = load_mbccb(inst, mbccbs[i])) < 0) {
// Messages printed in load function
Expand All @@ -2764,33 +2762,33 @@ int rtapi_app_main(void)

// Allocate HAL memory
if(!(inst->hal = (hm2_modbus_hal_t *)hal_malloc(sizeof(*inst->hal)))) {
MSG_PRINT("%s: error: Failed to allocate HAL memory\n", inst->name);
MSG_ERR("%s: error: Failed to allocate HAL memory\n", inst->name);
retval = -ENOMEM;
goto errout;
}
if(!(inst->hal->pins = (mbt_pin_hal_t *)hal_malloc(inst->npins * sizeof(*inst->hal->pins)))) {
MSG_PRINT("%s: error: Failed to allocate HAL pins memory\n", inst->name);
MSG_ERR("%s: error: Failed to allocate HAL pins memory\n", inst->name);
retval = -ENOMEM;
goto errout;
}
if(!(inst->hal->cmds = (mbt_cmd_hal_t *)hal_malloc(inst->ncmds * sizeof(*inst->hal->cmds)))) {
MSG_PRINT("%s: error: Failed to allocate HAL cmds memory\n", inst->name);
MSG_ERR("%s: error: Failed to allocate HAL cmds memory\n", inst->name);
retval = -ENOMEM;
goto errout;
}

if(inst->ninit > 0) {
// Allocate inits memory
if(!(inst->_init = rtapi_kzalloc(inst->ninit * sizeof(*inst->_init), RTAPI_GFP_KERNEL))) {
MSG_PRINT("%s: error: Failed to allocate init commands memory\n", inst->name);
MSG_ERR("%s: error: Failed to allocate init commands memory\n", inst->name);
retval = -ENOMEM;
goto errout;
}
}

// Allocate commands memory
if(!(inst->_cmds = rtapi_kzalloc(inst->ncmds * sizeof(*inst->_cmds), RTAPI_GFP_KERNEL))) {
MSG_PRINT("%s: error: Failed to allocate commands memory\n", inst->name);
MSG_ERR("%s: error: Failed to allocate commands memory\n", inst->name);
retval = -ENOMEM;
goto errout;
}
Expand All @@ -2811,14 +2809,14 @@ int rtapi_app_main(void)

// Export the HAL process function
if((retval = hal_export_functf(process, inst, 1, 0, comp_id, COMP_NAME".%d.process", i)) < 0) {
MSG_PRINT("%s: error: Function export failed\n", inst->name);
MSG_ERR("%s: error: Function export failed\n", inst->name);
goto errout;
}

#define CHECK(x) do { \
retval = (x); \
if(retval < 0) { \
MSG_PRINT("%s: error: Failed to create pin or parameter\n", inst->name); \
MSG_ERR("%s: error: Failed to create pin or parameter\n", inst->name); \
goto errout; \
} \
} while(0)
Expand Down Expand Up @@ -2880,8 +2878,8 @@ int rtapi_app_main(void)
inst->cfg_tx.flags |= HM2_PKTUART_CONFIG_DRIVEEN | HM2_PKTUART_CONFIG_DRIVEAUTO;

if((retval = hm2_pktuart_get_version(inst->uart)) < 0) {
MSG_PRINT("%s: error: Cannot get PktUART version (error=%d)\n", inst->name, retval);
MSG_PRINT("%s: error: probable cause: port '%s' does not exist (typo?)\n", inst->name, inst->uart);
MSG_ERR("%s: error: Cannot get PktUART version (error=%d)\n", inst->name, retval);
MSG_ERR("%s: error: probable cause: port '%s' does not exist (typo?)\n", inst->name, inst->uart);
goto errout;
}
inst->rxversion = (retval >> 4) & 0x0f;
Expand All @@ -2892,28 +2890,28 @@ int rtapi_app_main(void)
// timing measurement.
if(inst->rxversion < 3 || inst->txversion < 3) {
if(inst->rxversion < 2 || inst->txversion < 2) {
MSG_PRINT("%s: error: The driver does not support PktUART versions before 2 (Rx=%u Tx=%u), aborting.\n",
MSG_ERR("%s: error: The driver does not support PktUART versions before 2 (Rx=%u Tx=%u), aborting.\n",
inst->name, inst->rxversion, inst->txversion);
goto errout;
}
MSG_PRINT("%s: warning: PktUART version is less than 3 (Rx=%u Tx=%u). Please consider upgrading.\n",
MSG_ERR("%s: warning: PktUART version is less than 3 (Rx=%u Tx=%u). Please consider upgrading.\n",
inst->name, inst->rxversion, inst->txversion);
if(stopbits > 1) {
MSG_PRINT("%s: warning: Old PktUART cannot set two stop-bits. Setting to one.\n", inst->name);
MSG_ERR("%s: warning: Old PktUART cannot set two stop-bits. Setting to one.\n", inst->name);
stopbits = 1;
}
if(inst->txversion < 3 && inst->cfg_tx.ifdelay > 0xff) {
MSG_PRINT("%s: warning: Old PktUART cannot set txdelay to 0x%04x. Clamping to 0xff.\n",
MSG_ERR("%s: warning: Old PktUART cannot set txdelay to 0x%04x. Clamping to 0xff.\n",
inst->name, inst->cfg_tx.ifdelay);
inst->cfg_tx.ifdelay = 0xff;
}
if(inst->rxversion < 3 && inst->cfg_rx.ifdelay > 0xff) {
MSG_PRINT("%s: warning: Old PktUART cannot set rxdelay to 0x%04x. Clamping to 0xff.\n",
MSG_ERR("%s: warning: Old PktUART cannot set rxdelay to 0x%04x. Clamping to 0xff.\n",
inst->name, inst->cfg_rx.ifdelay);
inst->cfg_rx.ifdelay = 0xff;
}
if(inst->rxversion < 3 && inst->mbccb->icdelay != 0) {
MSG_PRINT("%s: warning: Old PktUART cannot set icdelay, disabling.\n", inst->name);
MSG_ERR("%s: warning: Old PktUART cannot set icdelay, disabling.\n", inst->name);
inst->mbccb->icdelay = 0;
}
}
Expand Down Expand Up @@ -3124,7 +3122,7 @@ int rtapi_app_main(void)
inst->cfg_rx.flags |= HM2_PKTUART_CONFIG_FLUSH;
inst->cfg_tx.flags |= HM2_PKTUART_CONFIG_FLUSH;
if((retval = hm2_pktuart_config(inst->uart, &inst->cfg_rx, &inst->cfg_tx, 0)) < 0) {
MSG_PRINT("%s: error: PktUART setup problem: error=%d\n", inst->name, retval);
MSG_ERR("%s: error: PktUART setup problem: error=%d\n", inst->name, retval);
goto errout;
}
inst->cfg_rx.flags &= ~HM2_PKTUART_CONFIG_FLUSH;
Expand Down
Loading