check all targets for valid numbers before driving any

This commit is contained in:
Douglas Clowes
2012-11-29 09:28:16 +11:00
parent ef68c15345
commit 903a472f47

29
drive.c
View File

@ -1,7 +1,7 @@
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
Implementation file for the drive command Implementation file for the drive command
This version as Test for Device Executor. This version as Test for Device Executor.
Mark Koennecke, December 1996 Mark Koennecke, December 1996
@ -66,7 +66,7 @@ int Drive(SConnection * pCon, SicsInterp * pInter, char *name, float fNew)
/* check if user is allowed to drive */ /* check if user is allowed to drive */
if (!SCMatchRights(pCon, usUser)) { if (!SCMatchRights(pCon, usUser)) {
snprintf(pBueffel, 511, "Insuficient Privilege to drive %s", name); snprintf(pBueffel, 511, "Insufficient Privilege to drive %s", name);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }
@ -160,7 +160,7 @@ int Start2Run(SConnection * pCon, SicsInterp * pInter, char *name,
/* check if user is allowed to drive */ /* check if user is allowed to drive */
if (!SCMatchRights(pCon, usUser)) { if (!SCMatchRights(pCon, usUser)) {
snprintf(pBueffel,511, "Insuficient Privilege to drive %s", name); snprintf(pBueffel,511, "Insufficient Privilege to drive %s", name);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
return 0; return 0;
} }
@ -301,7 +301,7 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
return 0; return 0;
} }
/* interprete arguments as pairs name value and try to start */ /* interpret arguments as pairs (name, value) and check */
SetStatus(eDriving); SetStatus(eDriving);
for (i = 1; i < argc; i += 2) { for (i = 1; i < argc; i += 2) {
if (argv[i + 1] == NULL) { if (argv[i + 1] == NULL) {
@ -313,7 +313,22 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget); iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget);
if (iRet == TCL_ERROR) { if (iRet == TCL_ERROR) {
SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError); SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError);
StopExe(GetExecutor(), "ALL"); SetStatus(eOld);
return 0;
} else if (!isfinite(dTarget)) {
snprintf(pBueffel, 511,
"ERROR: target %s value for %s is not a finite number",
argv[i + 1], argv[i]);
SCWrite(pCon, pBueffel, eError);
SetStatus(eOld);
return 0;
}
}
/* interpret arguments as pairs (name, value) and try to start */
for (i = 1; i < argc; i += 2) {
iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget);
if (iRet == TCL_ERROR) {
SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError);
SetStatus(eOld); SetStatus(eOld);
return 0; return 0;
} }
@ -360,7 +375,7 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
SetStatus(eOld); SetStatus(eOld);
return 0; return 0;
} }
SCWrite(pCon, "Driving finished sucessfully", eValue); SCWrite(pCon, "Driving finished successfully", eValue);
SetStatus(eOld); SetStatus(eOld);
return 1; return 1;
} }
@ -398,7 +413,7 @@ int RunWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
return 0; return 0;
} }
/* interprete arguments as pairs name value and try to start */ /* interpret arguments as pairs name value and try to start */
SetStatus(eDriving); SetStatus(eDriving);
for (i = 1; i < argc; i += 2) { for (i = 1; i < argc; i += 2) {
if (argv[i + 1] == NULL) { if (argv[i + 1] == NULL) {