From: John K. <cv...@cv...> - 2008-11-19 04:21:51
|
Modified file emc2/src/hal/hal.h Full file: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/hal.h?rev=1.38> Difference: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/hal.h.diff?r1=1.37;r2=1.38> Branch: TRUNK Log: revision 1.38 date: 2008/11/19 03:17:08; author: jmkasunich; state: Exp; lines: +15 -0 incremental progress on 'alias' command - untested, but no way to invoke it at the moment, should be safe --- hal.h 2008/11/07 22:12:41 1.37 +++ hal.h 2008/11/19 03:17:08 1.38 @@ -400,6 +400,14 @@ calls 'hal_exit()'. */ +/** 'hal_pin_alias()' assigns an alternate name, aka an alias, to + a pin. Once assigned, the pin can be referred to by either its + original name or the alias. Calling this function with 'alias' + set to NULL will remove any existing alias. +*/ +extern int hal_pin_alias(const char *pin_name, const char *alias); + + /*********************************************************************** * "SIGNAL" FUNCTIONS * ************************************************************************/ @@ -551,6 +559,13 @@ extern int hal_param_float_set(const char *name, double value); extern int hal_param_u32_set(const char *name, unsigned long value); extern int hal_param_s32_set(const char *name, signed long value); + +/** 'hal_param_alias()' assigns an alternate name, aka an alias, to + a parameter. Once assigned, the parameter can be referred to by + either its original name or the alias. Calling this function + with 'alias' set to NULL will remove any existing alias. +*/ +extern int hal_param_alias(const char *pin_name, const char *alias); /** 'hal_param_set()' is a generic function that sets the value of a parameter. It is provided ONLY for those special cases where a Modified file emc2/src/hal/hal_lib.c Full file: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/hal_lib.c?rev=1.67> Difference: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/hal_lib.c.diff?r1=1.66;r2=1.67> Branch: TRUNK Log: revision 1.67 date: 2008/11/19 03:17:09; author: jmkasunich; state: Exp; lines: +107 -0 incremental progress on 'alias' command - untested, but no way to invoke it at the moment, should be safe --- hal_lib.c 2008/11/19 02:33:21 1.66 +++ hal_lib.c 2008/11/19 03:17:09 1.67 @@ -658,6 +658,7 @@ return HAL_SUCCESS; } ptr = SHMPTR(next); + // TODO - should use ptr->alias if present cmp = strcmp(ptr->name, new->name); if (cmp > 0) { /* found the right place for it, insert here */ @@ -680,6 +681,96 @@ } } +int hal_pin_alias(const char *pin_name, const char *alias) +{ + int *prev, next, cmp; + hal_pin_t *pin; + hal_alias_t *new, *ptr; + + if (hal_data == 0) { + rtapi_print_msg(RTAPI_MSG_ERR, + "HAL: ERROR: pin_alias called before init\n"); + return HAL_INVAL; + } + if (hal_data->lock & HAL_LOCK_CONFIG) { + rtapi_print_msg(RTAPI_MSG_ERR, + "HAL: ERROR: pin_alias called while HAL locked\n"); + return HAL_PERM; + } + if (alias != NULL ) { + if (strlen(alias) >= HAL_NAME_LEN) { + rtapi_print_msg(RTAPI_MSG_ERR, + "HAL: ERROR: alias name '%s' is too long\n", alias); + return HAL_INVAL; + } + } + /* get mutex before accessing shared data */ + rtapi_mutex_get(&(hal_data->mutex)); + if (alias != NULL ) { + pin = halpr_find_pin_by_name(alias); + if ( pin != NULL ) { + rtapi_mutex_give(&(hal_data->mutex)); + rtapi_print_msg(RTAPI_MSG_ERR, + "HAL: ERROR: duplicate pin/alias name '%s'\n", alias); + return HAL_INVAL; + } + } + pin = halpr_find_pin_by_name(pin_name); + if ( pin == NULL ) { + rtapi_mutex_give(&(hal_data->mutex)); + rtapi_print_msg(RTAPI_MSG_ERR, + "HAL: ERROR: pin '%s' not found\n", pin_name); + return HAL_INVAL; + } + /* remove any existing alias */ + remove_alias_from_pin(pin); + /* is that all we needed to do? */ + if ( alias == NULL ) { + rtapi_mutex_give(&(hal_data->mutex)); + return HAL_SUCCESS; + } + /* allocate a new structure */ + new = halpr_alloc_alias_struct(); + if (new == 0) { + /* alloc failed */ + rtapi_mutex_give(&(hal_data->mutex)); + rtapi_print_msg(RTAPI_MSG_ERR, + "HAL: ERROR: insufficient memory for alias '%s'\n", alias); + return HAL_NOMEM; + } + /* initialize the structure */ + new->owner_ptr = SHMOFF(pin); + rtapi_snprintf(new->name, HAL_NAME_LEN, "%s", alias); + /* attach it to the pin */ + pin->alias = SHMOFF(new); + // TODO - unlink pin from pin list, relink using alias instead of name + /* insert new structure in alias list */ + prev = &(hal_data->pin_alias_list_ptr); + next = *prev; + while (1) { + if (next == 0) { + /* reached end of list, insert here */ + new->next_ptr = next; + *prev = SHMOFF(new); + rtapi_mutex_give(&(hal_data->mutex)); + return HAL_SUCCESS; + } + ptr = SHMPTR(next); + cmp = strcmp(ptr->name, new->name); + if (cmp > 0) { + /* found the right place for it, insert here */ + new->next_ptr = next; + *prev = SHMOFF(new); + rtapi_mutex_give(&(hal_data->mutex)); + return HAL_SUCCESS; + } |