Example #1
0
static void cliSet(char *cmdline)
{

    int i;
    int len;
    const clivalue_t *val;
    char *eqptr = NULL;
    int value = 0;
    float valuef = 0;

    len = strlen(cmdline);


    if (len == 0 || (len == 1 && cmdline[0] == '*')) {
        cliPrint("Current settings: \r\n");
        for (i = 0; i < VALUE_COUNT; i++) {
            val = &valueTable[i];
            printf("%s = ", valueTable[i].name);
            cliPrintVar(val, len);      // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui
            cliPrint("\r\n");
        }
    } else if ((eqptr = strstr(cmdline, "=")) != NULL) {
        // has equal, set var
        eqptr++;
        len--;
        value = atoi(eqptr);
        valuef = _atof(eqptr);
        for (i = 0; i < VALUE_COUNT; i++) {
            val = &valueTable[i];
            if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0) {
                if (valuef >= valueTable[i].min && valuef <= valueTable[i].max) {       // here we compare the float value since... it should work, RIGHT?
                    int_float_value_t tmp;
                    if (valueTable[i].type == VAR_FLOAT)
                        tmp.float_value = valuef;
                    else
                        tmp.int_value = value;
                    cliSetVar(val, tmp);
                    printf("%s set to ", valueTable[i].name);
                    cliPrintVar(val, 0);
                } else {
                    cliPrint("ERR: Value assignment out of range\r\n");
                }
                return;
            }
        }
        cliPrint("ERR: Unknown variable name\r\n");
    } else {
        // no equals, check for matching variables.
        for (i = 0; i < VALUE_COUNT; i++) {
            if (strstr(valueTable[i].name, cmdline)) {
                val = &valueTable[i];
                printf("%s = ", valueTable[i].name);
                cliPrintVar(val, 0);
                printf("\r\n");
            }
        }
    }
}
Example #2
0
 void cliSet(char *cmdline)
{
    uint32_t i;
    uint32_t len;
    const clivalue_t *val;
    char *eqptr = NULL;
    int32_t value = 0;
    float valuef = 0;

    len = strlen(cmdline);

	    if (len == 3 && cmdline[0] == '*') {
//        printf("Current settings: \r\n");
			for (i = 0; i < VALUE_COUNT; i++) {
				val = &valueTable[i];
				printf("%s=", valueTable[i].name);
//				cliPrintVar(val, len); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui
				cliPrintVar(val, 0);
				printf("\r");
			}
//			f.IMU_GRAPH_OUT=1;
	}


			
 	 
	 else if (strstr(cmdline, "=")) {
			void (*Func) (void);
			eqptr = strstr(cmdline, "=");
			// has equal, set var
			eqptr++;
			len--;
			value= atoi(eqptr);
			valuef = _atof(eqptr);
			for (i = 0; i < VALUE_COUNT; i++) {
				val = &valueTable[i];
				if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0) {
					if (valuef >= valueTable[i].min && valuef <= valueTable[i].max) { // here we compare the float value since... it should work, RIGHT?
						cliSetVar(val, valueTable[i].type == VAR_FLOAT ? *(uint32_t *)&valuef : value); // this is a silly dirty hack. please fix me later.
						if(valueTable[i].function!=NULL) {
							Func = valueTable[i].function;		//관련된 함수 호출
							Func();
						}
						printf("%s=", valueTable[i].name);
		//                printf("%d  ", value);
						cliPrintVar(val, 0);
						printf("\r");
	//					printf(" %d",cfg.gyroPitchKi);
					} else {
						printf("ERR: Value assignment out of range\r\n");
					}
					return;
				}
			}
			printf("ERR: Unknown variable name\r\n");
		}
}
Example #3
0
static void cliSet(char *cmdline)
{
    uint32_t i;
    uint32_t len;
    const clivalue_t *val;
    char *eqptr = NULL;
    int32_t value = 0;
    float valuef = 0;

    len = strlen(cmdline);

    if (len == 0 || (len == 1 && cmdline[0] == '*')) {
        cliPrint("Current settings: \r\n");
        for (i = 0; i < VALUE_COUNT; i++) {
            val = &valueTable[i];
            printf("%s = ", valueTable[i].name);
            cliPrintVar(val, len); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui
            cliPrint("\r\n");
        }
    } else if ((eqptr = strstr(cmdline, "=")) != NULL) {
        // has equal, set var
        char *lastNonSpaceCharacter = eqptr;
        while (*(lastNonSpaceCharacter - 1) == ' ') {
            lastNonSpaceCharacter--;
        }
        uint8_t variableNameLength = lastNonSpaceCharacter - cmdline;

        eqptr++;
        len--;
        value = atoi(eqptr);
        valuef = fastA2F(eqptr);
        for (i = 0; i < VALUE_COUNT; i++) {
            val = &valueTable[i];
            // ensure exact match when setting to prevent setting variables with shorter names
            if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0 && variableNameLength == strlen(valueTable[i].name)) {
                if (valuef >= valueTable[i].min && valuef <= valueTable[i].max) { // here we compare the float value since... it should work, RIGHT?
                    int_float_value_t tmp;
                    if (valueTable[i].type & VAR_FLOAT)
                        tmp.float_value = valuef;
                    else
                        tmp.int_value = value;
                    cliSetVar(val, tmp);
                    printf("%s set to ", valueTable[i].name);
                    cliPrintVar(val, 0);
                } else {
                    cliPrint("Value assignment out of range\r\n");
                }
                return;
            }
        }
        cliPrint("Unknown variable name\r\n");
    } else {
        // no equals, check for matching variables.
    	cliGet(cmdline);
    }
}
Example #4
0
static void
cli_cmd_fsnum(char *cmdline) {
    /* Abuse cli function to parse the hex */
    int16_t status;
    static const clivalue_t snum_value = { NULL, VAR_HEX, &snum, 8 };
    cliSetVar(&snum_value, cmdline);
    status = eeprom_write_page(0, (uint8_t*)&snum);
    if (status == EERR_OK) {
        cliInfo(NULL);
    } else {
        show_eeprom_error(status);
    }
}
Example #5
0
File: cli.c Project: DuinoPilot/TMR
static void cliSet(char *cmdline)
{
    uint32_t i;
    uint32_t len;
    const clivalue_t *val;
    char *eqptr = NULL;
    int32_t value = 0;

    len = strlen(cmdline);

    if (len == 0 || (len == 1 && cmdline[0] == '*')) {
        uartPrint("Current settings: \r\n");
        for (i = 0; i < VALUE_COUNT; i++) {
            val = &valueTable[i];
            printf("%s = ", valueTable[i].name);
            cliPrintVar(val, len); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui
            uartPrint("\r\n");
        }
    } else if ((eqptr = strstr(cmdline, "="))) {
        // has equal, set var
        eqptr++;
        len--;
        value = atoi(eqptr);
        for (i = 0; i < VALUE_COUNT; i++) {
            val = &valueTable[i];
            if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0) {
                // found
                if (value >= valueTable[i].min && value <= valueTable[i].max) {
                    cliSetVar(val, value);
                    printf("%s set to ", valueTable[i].name);
                    cliPrintVar(val, 0);
                } else {
                    uartPrint("ERR: Value assignment out of range\r\n");
                }
                return;
            }
        }
        uartPrint("ERR: Unknown variable name\r\n");
    }
}
void
cli_cmd_set(char *cmdline) {
    uint32_t len;
    const clivalue_t *val;
    char *eqptr, *ptr2;

    len = strlen(cmdline);
    if (len == 0 || (len == 1 && cmdline[0] == '*')) {
        cli_puts("Current settings:\r\n");
        for (val = &value_table[0]; val->name != NULL; val++) {
            cli_printf("%s = ", val->name);
            cliPrintVar(val, len);
            cli_puts("\r\n");
        }
    } else if ((eqptr = strstr(cmdline, "="))) {
        /* Null-terminate the setting name */
        ptr2 = eqptr;
        *ptr2 = 0;
        while (*--ptr2 == ' ') {
            *ptr2 = 0;
        }
        eqptr++;
        len--;
        while (*eqptr == ' ') {
            eqptr++;
            len--;
        }
        for (val = &value_table[0]; val->name != NULL; val++) {
            if (!strcmp(cmdline, val->name)) {
                cliSetVar(val, eqptr);
                cli_printf("%s set to ", val->name);
                cliPrintVar(val, 0);
                return;
            }
        }
        cli_puts("ERR: Unknown variable name\r\n");
    }
}