Exemplo n.º 1
0
const static jsmntok_t * findNode(const jsmntok_t *node, const char * name){

	while (!(node->start == 0 && node->end == 0)){
		if (strcmp(name, jsmn_trimData(node)->data) == 0) return node;
		node++;
	}
	return NULL;
}
Exemplo n.º 2
0
static void setConfigGeneric(Serial *serial, const jsmntok_t * json, void *cfg, setExtField_func setExtField){
	int size = json->size;
	if (json->type == JSMN_OBJECT && json->size % 2 == 0){
		json++;
		for (int i = 0; i < size; i += 2 ){
			const jsmntok_t *nameTok = json;
			jsmn_trimData(nameTok);
			json++;
			const jsmntok_t *valueTok = json;
			json++;
			if (valueTok->type == JSMN_PRIMITIVE || valueTok->type == JSMN_STRING) jsmn_trimData(valueTok);

			const char *name = nameTok->data;
			const char *value = valueTok->data;

			setExtField(valueTok, name, value, cfg);
		}
	}

}
Exemplo n.º 3
0
static const jsmntok_t * setScalingRow(ADCConfig *adcCfg, const jsmntok_t *mapRow){
	if (mapRow->type == JSMN_STRING){
		jsmn_trimData(mapRow);
		if (NAME_EQU(mapRow->data, "raw")) mapRow = setScalingMapRaw(adcCfg, mapRow + 1);
		else if (NAME_EQU("scal", mapRow->data)) mapRow = setScalingMapValues(adcCfg, mapRow + 1);
	}
	else{
		mapRow++;
	}
	return mapRow;
}
Exemplo n.º 4
0
void setTargetConfig(const jsmntok_t *cfg, GPSTargetConfig *targetConfig){
	if (cfg->type == JSMN_OBJECT && cfg->size % 2 == 0){
		int size = cfg->size;
		cfg++;
		for (int i = 0; i < size; i += 2 ){
			const jsmntok_t *nameTok = cfg;
			jsmn_trimData(nameTok);
			cfg++;
			const jsmntok_t *valueTok = cfg;
			cfg++;
			if (valueTok->type == JSMN_PRIMITIVE || valueTok->type == JSMN_STRING) jsmn_trimData(valueTok);

			char *name = nameTok->data;
			char *value = valueTok->data;

			if (NAME_EQU("lat",name)) targetConfig->latitude = modp_atof(value);
			else if (NAME_EQU("long", name)) targetConfig->longitude = modp_atof(value);
			else if (NAME_EQU("rad", name)) targetConfig->targetRadius = modp_atof(value);
		}
	}
}
Exemplo n.º 5
0
static void setMultiChannelConfigGeneric(Serial *serial, const jsmntok_t * json, getConfigs_func getConfigs, setExtField_func setExtFieldFunc){
	if (json->type == JSMN_OBJECT && json->size % 2 == 0){
		for (int i = 1; i <= json->size; i += 2){
			const jsmntok_t *idTok = json + i;
			const jsmntok_t *cfgTok = json + i + 1;
			jsmn_trimData(idTok);
			size_t id = modp_atoi(idTok->data);
			void *baseCfg;
			ChannelConfig *channelCfg;
			getConfigs(id, &baseCfg, &channelCfg);
			setChannelConfig(serial, cfgTok, channelCfg, setExtFieldFunc, baseCfg);
		}
	}
}
Exemplo n.º 6
0
int api_log(Serial *serial, const jsmntok_t *json){
	int doLogging = 0;
	if (json->type == JSMN_PRIMITIVE && json->size == 0){
		jsmn_trimData(json);
		doLogging = modp_atoi(json->data);
		if (doLogging){
			//startLogging();
		}
		else{
			//stopLogging();
		}
	}
	return API_SUCCESS;
}
Exemplo n.º 7
0
int api_sampleData(Serial *serial, const jsmntok_t *json){

	int sendMeta = 0;
	if (json->type == JSMN_OBJECT && json->size == 2){
		const jsmntok_t * meta = json + 1;
		const jsmntok_t * value = json + 2;

		jsmn_trimData(meta);
		jsmn_trimData(value);

		if (NAME_EQU("meta",meta->data)){
			sendMeta = modp_atoi(value->data);
		}
	}
	SampleRecord * sr = (SampleRecord *)portMalloc(sizeof(SampleRecord));
	if (sr == 0) return API_ERROR_SEVERE;

	LoggerConfig * config = getWorkingLoggerConfig();
	initSampleRecord(config, sr);
	populateSampleRecord(sr,0, config);
	api_sendSampleRecord(serial, sr, 0, sendMeta);
	portFree(sr);
	return API_SUCCESS_NO_RETURN;
}
Exemplo n.º 8
0
static const jsmntok_t * setScalingMapValues(ADCConfig *adcCfg, const jsmntok_t *mapArrayTok){
	if (mapArrayTok->type == JSMN_ARRAY){
		int size = mapArrayTok->size;
		for (int i = 0; i < size; i++){
			mapArrayTok++;
			if (mapArrayTok->type == JSMN_PRIMITIVE){
				jsmn_trimData(mapArrayTok);
				if (i < ANALOG_SCALING_BINS){
					adcCfg->scalingMap.scaledValues[i] = modp_atof(mapArrayTok->data);
				}
			}
		}
	}
	return mapArrayTok + 1;
}
Exemplo n.º 9
0
static const jsmntok_t * setChannelConfig(Serial *serial, const jsmntok_t *cfg, ChannelConfig *channelCfg, setExtField_func setExtField, void *extCfg){
	if (cfg->type == JSMN_OBJECT && cfg->size % 2 == 0){
		int size = cfg->size;
		cfg++;
		for (int i = 0; i < size; i += 2 ){
			const jsmntok_t *nameTok = cfg;
			jsmn_trimData(nameTok);
			cfg++;
			const jsmntok_t *valueTok = cfg;
			cfg++;
			if (valueTok->type == JSMN_PRIMITIVE || valueTok->type == JSMN_STRING) jsmn_trimData(valueTok);

			char *name = nameTok->data;
			char *value = valueTok->data;
			unescapeTextField(value);

			if (NAME_EQU("nm",name)) setLabelGeneric(channelCfg->label, value);
			else if (NAME_EQU("ut", name)) setLabelGeneric(channelCfg->units, value);
			else if (NAME_EQU("sr", name)) channelCfg->sampleRate = encodeSampleRate(modp_atoi(value));
			else if (setExtField != NULL) cfg = setExtField(valueTok, name, value, extCfg);
		}
	}
	return cfg;
}
Exemplo n.º 10
0
static int execute_api(Serial * serial, const jsmntok_t *json)
{
    const jsmntok_t *root = &json[0];
    if (root->type == JSMN_OBJECT && root->size == 2) {
        const jsmntok_t *apiMsgName = &json[1];
        const jsmntok_t *payload = &json[2];
        if (apiMsgName->type == JSMN_STRING) {
            jsmn_trimData(apiMsgName);
            return dispatch_api(serial, apiMsgName->data, payload);
        } else {
            return API_ERROR_MALFORMED;
        }
    } else {
        return API_ERROR_MALFORMED;
    }
}
Exemplo n.º 11
0
int api_getTimerConfig(Serial *serial, const jsmntok_t *json){
	size_t startIndex = 0;
	size_t endIndex = 0;
	if (json->type == JSMN_PRIMITIVE){
		if (jsmn_isNull(json)){
			startIndex = 0;
			endIndex = CONFIG_TIMER_CHANNELS - 1;
		}
		else{
			jsmn_trimData(json);
			startIndex = endIndex = modp_atoi(json->data);
		}
	}
	if (startIndex >= 0 && startIndex <= CONFIG_TIMER_CHANNELS){
		sendTimerConfig(serial, startIndex, endIndex);
		return API_SUCCESS_NO_RETURN;
	}
	else{
		return API_ERROR_PARAMETER;
	}
}