Beispiel #1
0
/**
 * Parse boolean parameter as described in the spec SCPI-99 7.3 Boolean Program Data
 * @param context
 * @param value
 * @param mandatory
 * @return 
 */
scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t mandatory) {
    const char * param;
    size_t param_len;
    size_t num_len;
    int32_t i;

    if (!value) {
        return FALSE;
    }

    if (!SCPI_ParamString(context, &param, &param_len, mandatory)) {
        return FALSE;
    }

    if (matchPattern("ON", 2, param, param_len)) {
        *value = TRUE;
    } else if (matchPattern("OFF", 3, param, param_len)) {
        *value = FALSE;
    } else {
        num_len = strToLong(param, &i);

        if (num_len != param_len) {
            SCPI_ErrorPush(context, SCPI_ERROR_SUFFIX_NOT_ALLOWED);
            return FALSE;
        }

        *value = i ? TRUE : FALSE;
    }

    return TRUE;
}
Beispiel #2
0
scpi_result_t SCPI_SetPower(scpi_t * context)
{
	const char * param;
	size_t param_len;

	if(!SCPI_ParamString(context, &param, &param_len, true)) 
		return SCPI_RES_ERR;
		
	if(param_len >= 2)
	{
		if(strncmp(param, "ON", 2) == 0)
		{
			enable_12v();
			init_module_peripherals_ap();
			return SCPI_RES_OK;
		}
		else if((param_len > 2) && (strncmp(param, "OFF", 3) == 0))
		{
			deinit_module_peripherals();
			disable_12v();
			return SCPI_RES_OK;
		}
		else
		{
			return SCPI_RES_ERR;
		}
	}
	else
	{
		return SCPI_RES_OK;
	}
	
	return SCPI_RES_OK;
}
Beispiel #3
0
scpi_result_t RP_APP_OscSetMathSources(scpi_t *context) {
    const char * param;
    size_t param_len;
    char string[25];
    if (!SCPI_ParamString(context, &param, &param_len, true)) {
        syslog(LOG_ERR, "*OSC:MATH:SOUR is missing first parameter.");
        return SCPI_RES_ERR;
    }
    strncpy(string, param, param_len);
    string[param_len] = '\0';
    rp_channel_t s1;
    if (getRpChannel(string, &s1)) {
        syslog(LOG_ERR, "*OSC:MATH:SOUR parameter invalid.");
        return SCPI_RES_ERR;
    }

    if (!SCPI_ParamString(context, &param, &param_len, true)) {
        syslog(LOG_ERR, "*OSC:MATH:SOUR is missing first parameter.");
        return SCPI_RES_ERR;
    }
    strncpy(string, param, param_len);
    string[param_len] = '\0';
    rp_channel_t s2;
    if (getRpChannel(string, &s2)) {
        syslog(LOG_ERR, "*OSC:MATH:SOUR parameter invalid.");
        return SCPI_RES_ERR;
    }

    int result = rpApp_OscSetMathSources(s1, s2);
    if (RP_OK != result) {
        syslog(LOG_ERR, "*OSC:MATH:SOUR Failed to set: %s", rp_GetError(result));
        return SCPI_RES_ERR;
    }
    syslog(LOG_INFO, "*OSC:MATH:SOUR set successfully.");
    return SCPI_RES_OK;
}
Beispiel #4
0
/**
 * SCPI: low-level pin actions
 * LOWlevel:SETpin NAME
 * LOWlevel:CLRpin NAME
 * LOWlevel:GETpin NAME
 *
 * @param context - active SCPI context
 * @return success or failure
 */
scpi_result_t LOWLEVEL_PIN_ACTION (scpi_t *context)
{
    char const *str;
    size_t len;
    scpi_result_t (*pin_action) (uint32_t, uint32_t, const char *);

    if (!SCPI_ParamString(context, &str, &len, true)) {
        return SCPI_RES_ERR;
    }

    if (SCPI_IsCmd(context, "LOWlevel:SETpin")) {
        pin_action = &pin_action_set;
    } else if (SCPI_IsCmd(context, "LOWLEVEL:CLRpin")) {
        pin_action = &pin_action_clr;
    } else {
        pin_action = &pin_action_get;
    }

#define buflen 32
    char buffer[buflen];
    if (len > buflen - 1) {
        puts ("String too long\r");
        return SCPI_RES_ERR;
    }

    memcpy(buffer, str, len);
    buffer[len] = 0;

    bool found_pin = false;
    size_t i;
    for (i = 0; PIN_TABLE[i].description; ++i) {
        if (!PIN_TABLE[i].index_str) continue; // Pin group, not pin
        if (!strcmp (PIN_TABLE[i].pin_name_str, buffer)) {
            pin_action(PIN_TABLE[i].index, PIN_TABLE[i].flags, buffer);
            found_pin = true;
            break;
        }
    }

    if (!found_pin) {
        printf ("Pin '%s' not found!\r\n", buffer);
        return SCPI_RES_ERR;
    } else {
        return SCPI_RES_OK;
    }
}
Beispiel #5
0
/**
 * Parse double parameter
 * @param context
 * @param value
 * @param mandatory
 * @return 
 */
scpi_bool_t SCPI_ParamDouble(scpi_t * context, double * value, scpi_bool_t mandatory) {
    const char * param;
    size_t param_len;
    size_t num_len;

    if (!value) {
        return FALSE;
    }

    if (!SCPI_ParamString(context, &param, &param_len, mandatory)) {
        return FALSE;
    }

    num_len = strToDouble(param, value);

    if (num_len != param_len) {
        SCPI_ErrorPush(context, SCPI_ERROR_SUFFIX_NOT_ALLOWED);
        return FALSE;
    }

    return TRUE;
}
Beispiel #6
0
/**
 * Parse integer parameter
 * @param context
 * @param value
 * @param mandatory
 * @return
 */
scpi_bool_t SCPIParser::SCPI_ParamInt(int32_t * value, scpi_bool_t mandatory) {
    const char * param;
    size_t param_len;
    size_t num_len;

    if (!value) {
        return FALSE;
    }

    if (!SCPI_ParamString(&param, &param_len, mandatory)) {
        return FALSE;
    }

    num_len = strToLong(param, value);

    if (num_len != param_len) {
        SCPI_ErrorPush(SCPI_ERROR_SUFFIX_NOT_ALLOWED);
        return FALSE;
    }

    return TRUE;
}
Beispiel #7
0
/**
 * Parse parameter as number, number with unit or special value (min, max, default, ...)
 * @param context
 * @param value return value
 * @param mandatory if the parameter is mandatory
 * @return
 */
scpi_bool_t SCPIParser::SCPI_ParamNumber(scpi_number_t * value, scpi_bool_t mandatory) {
    scpi_bool_t result;
    const char * param;
    size_t len;
    size_t numlen;

    /* read parameter and shift to the next one */
    result = SCPI_ParamString(&param, &len, mandatory);

    /* value not initializes */
    if (!value) {
        return FALSE;
    }

    value->type = SCPI_NUM_DEF;

    /* if parameter was not found, return TRUE or FALSE according
     * to fact that parameter was mandatory or not */
    if (!result) {
        return mandatory ? FALSE : TRUE;
    }

    /* convert string to special number type */
    if (translateSpecialNumber(context.special_numbers, param, len, value)) {
        /* found special type */
        return TRUE;
    }

    /* convert text from double - no special type */
    numlen = strToDouble(param, &value->value);

    /* transform units of value */
    if (numlen <= len) {
        return transformNumber(param + numlen, len - numlen, value);
    }
    return FALSE;

}
Beispiel #8
0
/**
 * Parse choice parameter
 * @param context
 * @param options
 * @param value
 * @param mandatory
 * @return 
 */
scpi_bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, scpi_bool_t mandatory) {
    const char * param;
    size_t param_len;
    size_t res;

    if (!options || !value) {
        return FALSE;
    }

    if (!SCPI_ParamString(context, &param, &param_len, mandatory)) {
        return FALSE;
    }

    for (res = 0; options[res]; ++res) {
        if (matchPattern(options[res], strlen(options[res]), param, param_len)) {
            *value = res;
            return TRUE;
        }
    }

    SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
    return FALSE;
}
Beispiel #9
0
scpi_result_t RP_APP_OscSetInputGain(rp_channel_t channel, scpi_t *context) {
    const char * param;
    size_t param_len;
    char string[25];
    if (!SCPI_ParamString(context, &param, &param_len, true)) {
        syslog(LOG_ERR, "*OSC:CH<n>:IN:GAIN is missing first parameter.");
        return SCPI_RES_ERR;
    }
    strncpy(string, param, param_len);
    string[param_len] = '\0';
    rpApp_osc_in_gain_t value;
    if (getRpAppInputGain(string, &value)) {
        syslog(LOG_ERR, "*OSC:CH<n>:IN:GAIN parameter invalid.");
        return SCPI_RES_ERR;
    }

    int result = rpApp_OscSetInputGain(channel, value);
    if (RP_OK != result) {
        syslog(LOG_ERR, "*OSC:CH<n>:IN:GAIN Failed to set: %s", rp_GetError(result));
        return SCPI_RES_ERR;
    }
    syslog(LOG_INFO, "*OSC:CH<n>:IN:GAIN set successfully.");
    return SCPI_RES_OK;
}
Beispiel #10
0
scpi_result_t RP_APP_OscSetTriggerSlope(scpi_t *context) {
    const char * param;
    size_t param_len;
    char string[25];
    if (!SCPI_ParamString(context, &param, &param_len, true)) {
        syslog(LOG_ERR, "*OSC:TRIG:SLOPE is missing first parameter.");
        return SCPI_RES_ERR;
    }
    strncpy(string, param, param_len);
    string[param_len] = '\0';
    rpApp_osc_trig_slope_t value;
    if (getRpAppTrigSlope(string, &value)) {
        syslog(LOG_ERR, "*OSC:TRIG:SLOPE parameter invalid.");
        return SCPI_RES_ERR;
    }

    int result = rpApp_OscSetTriggerSlope(value);
    if (RP_OK != result) {
        syslog(LOG_ERR, "*OSC:TRIG:SLOPE Failed to set: %s", rp_GetError(result));
        return SCPI_RES_ERR;
    }
    syslog(LOG_INFO, "*OSC:TRIG:SLOPE set successfully.");
    return SCPI_RES_OK;
}
Beispiel #11
0
scpi_result_t RP_APP_OscSetMathOperation(scpi_t *context) {
    const char * param;
    size_t param_len;
    char string[25];
    if (!SCPI_ParamString(context, &param, &param_len, true)) {
        syslog(LOG_ERR, "*OSC:MATH:OP is missing first parameter.");
        return SCPI_RES_ERR;
    }
    strncpy(string, param, param_len);
    string[param_len] = '\0';
    rpApp_osc_math_oper_t op;
    if (getRpAppMathOperation(string, &op)) {
        syslog(LOG_ERR, "*OSC:MATH:OP parameter invalid.");
        return SCPI_RES_ERR;
    }

    int result = rpApp_OscSetMathOperation(op);
    if (RP_OK != result) {
        syslog(LOG_ERR, "*OSC:MATH:OP Failed to set: %s", rp_GetError(result));
        return SCPI_RES_ERR;
    }
    syslog(LOG_INFO, "*OSC:MATH:OP set successfully.");
    return SCPI_RES_OK;
}