Skip to content

Commit

Permalink
halcmd: fix "tune" command locking.
Browse files Browse the repository at this point in the history
The "tune" command wasn't actually applying the desired locks
because it was locking a bitwise 'and' of values 1 & 2, which
gives a value of 0. This should have been a bitwise or of the
values.
Also changed the associated 'unlock' functions so that the "tune"
command unlocks the same locks as it locked.
Created a new #define to represent the locks to locks for the "tune"
command to help make it clearer that that the lock and unlock
functions should alter the same locks.
  • Loading branch information
ChrisNisbet01 committed Oct 10, 2020
1 parent 1784d2e commit 06c333a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 46 deletions.
3 changes: 3 additions & 0 deletions src/hal/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ RTAPI_BEGIN_DECLS
#define HAL_LOCK_PARAMS 4 /* locking of parameter set commands */
#define HAL_LOCK_RUN 8 /* locking of start/stop of HAL threads */

/* locks required for the 'tune' command */
#define HAL_LOCK_TUNE (HAL_LOCK_LOAD | HAL_LOCK_CONFIG)

#define HAL_LOCK_ALL 255 /* locks every action */

/***********************************************************************
Expand Down
42 changes: 20 additions & 22 deletions src/hal/utils/halcmd_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,16 @@ static int match(char **patterns, char *value) {

int do_lock_cmd(char *command)
{
int retval=0;

/* if command is blank or "all", want to lock everything */
if ((command == NULL) || (strcmp(command, "all") == 0)) {
retval = hal_set_lock(HAL_LOCK_ALL);
} else if (strcmp(command, "none") == 0) {
retval = hal_set_lock(HAL_LOCK_NONE);
} else if (strcmp(command, "tune") == 0) {
retval = hal_set_lock(HAL_LOCK_LOAD & HAL_LOCK_CONFIG);
} else if (strcmp(command, "all") == 0) {
retval = hal_set_lock(HAL_LOCK_ALL);
}
int retval = 0;

/* if command is blank or "all", want to lock everything */
if ((command == NULL) || (strcmp(command, "all") == 0)) {
retval = hal_set_lock(HAL_LOCK_ALL);
} else if (strcmp(command, "none") == 0) {
retval = hal_set_lock(HAL_LOCK_NONE);
} else if (strcmp(command, "tune") == 0) {
retval = hal_set_lock(HAL_LOCK_TUNE);
}

if (retval == 0) {
/* print success message */
Expand All @@ -136,16 +134,16 @@ int do_lock_cmd(char *command)

int do_unlock_cmd(char *command)
{
int retval=0;

/* if command is blank or "all", want to unlock everything */
if ((command == NULL) || (strcmp(command, "all") == 0)) {
retval = hal_set_lock(HAL_LOCK_NONE);
} else if (strcmp(command, "all") == 0) {
retval = hal_set_lock(HAL_LOCK_NONE);
} else if (strcmp(command, "tune") == 0) {
retval = hal_set_lock(HAL_LOCK_LOAD & HAL_LOCK_CONFIG);
}
int retval = 0;

/* if command is blank or "all", want to unlock everything */
if ((command == NULL) || (strcmp(command, "all") == 0)) {
retval = hal_set_lock(HAL_LOCK_NONE);
} else if (strcmp(command, "none") == 0) {
retval = hal_set_lock(HAL_LOCK_NONE);
} else if (strcmp(command, "tune") == 0) {
retval = hal_set_lock(hal_get_lock() & ~HAL_LOCK_TUNE);
}

if (retval == 0) {
/* print success message */
Expand Down
45 changes: 21 additions & 24 deletions src/hal/utils/halrmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,21 +622,18 @@ static int release_HAL_mutex(void)

static int doLock(char *command, connectionRecType *context)
{
int retval=0;
const char *nakStr = "SET LOCK NAK";

/* if command is blank, want to lock everything */
if (*command == '\0')
retval = hal_set_lock(HAL_LOCK_ALL);
else
if (strcmp(command, "none") == 0)
retval = hal_set_lock(HAL_LOCK_NONE);
else
if (strcmp(command, "tune") == 0)
retval = hal_set_lock(HAL_LOCK_LOAD & HAL_LOCK_CONFIG);
else
if (strcmp(command, "all") == 0)
retval = hal_set_lock(HAL_LOCK_ALL);
int retval = 0;
const char *nakStr = "SET LOCK NAK";

/* if command is blank, want to lock everything */
if (*command == '\0')
retval = hal_set_lock(HAL_LOCK_ALL);
else if (strcmp(command, "none") == 0)
retval = hal_set_lock(HAL_LOCK_NONE);
else if (strcmp(command, "tune") == 0)
retval = hal_set_lock(HAL_LOCK_TUNE);
else if (strcmp(command, "all") == 0)
retval = hal_set_lock(HAL_LOCK_ALL);

if (retval != 0) {
snprintf(errorStr, sizeof(errorStr), "HAL:%d: Locking failed", linenumber);
Expand All @@ -650,15 +647,15 @@ static int doUnlock(char *command, connectionRecType *context)
int retval=0;
const char *nakStr = "SET UNLOCK NAK";

/* if command is blank, want to lock everything */
if (*command == '\0')
retval = hal_set_lock(HAL_LOCK_NONE);
else
if (strcmp(command, "all") == 0)
retval = hal_set_lock(HAL_LOCK_NONE);
else
if (strcmp(command, "tune") == 0)
retval = hal_set_lock(HAL_LOCK_LOAD & HAL_LOCK_CONFIG);
/* if command is blank, want to unlock everything */
if (*command == '\0')
retval = hal_set_lock(HAL_LOCK_NONE);
else if (strcmp(command, "none") == 0)
retval = hal_set_lock(HAL_LOCK_NONE);
else if (strcmp(command, "tune") == 0)
retval = hal_set_lock(hal_get_lock() & ~HAL_LOCK_TUNE);
else if (strcmp(command, "all") == 0)
retval = hal_set_lock(HAL_LOCK_NONE);

if (retval != 0) {
snprintf(errorStr, sizeof(errorStr), "HAL:%d: Unlocking failed", linenumber);
Expand Down

0 comments on commit 06c333a

Please sign in to comment.