static const jsmntok_t * setConnectivityExtendedField(const jsmntok_t *valueTok, const char *name, const char *value, void *cfg){ ConnectivityConfig *connCfg = (ConnectivityConfig *)cfg; if (NAME_EQU("sdMode", name)) connCfg->sdLoggingMode = filterSdLoggingMode(modp_atoi(value)); else if (NAME_EQU("connMode", name)) connCfg->connectivityMode = filterConnectivityMode(modp_atoi(value)); else if (NAME_EQU("bgStream", name)) connCfg->backgroundStreaming = (modp_atoi(value) == 1); return valueTok + 1; }
static const jsmntok_t * setAccelExtendedField(const jsmntok_t *valueTok, const char *name, const char *value, void *cfg){ AccelConfig *accelCfg = (AccelConfig *)cfg; if (NAME_EQU("mode",name)) accelCfg->mode = filterAccelMode(modp_atoi(value)); else if (NAME_EQU("chan",name)) accelCfg->accelChannel = filterAccelChannel(modp_atoi(value)); else if (NAME_EQU("zeroVal",name)) accelCfg->zeroValue = modp_atoi(value); return valueTok + 1; }
static const jsmntok_t * setPwmExtendedField(const jsmntok_t *valueTok, const char *name, const char *value, void *cfg){ PWMConfig *pwmCfg = (PWMConfig *)cfg; if (NAME_EQU("logPrec", name)) pwmCfg->loggingPrecision = modp_atoi(value); if (NAME_EQU("outMode", name)) pwmCfg->outputMode = filterPwmOutputMode(modp_atoi(value)); if (NAME_EQU("logMode", name)) pwmCfg->loggingMode = filterPwmLoggingMode(modp_atoi(value)); if (NAME_EQU("stDutyCyc", name)) pwmCfg->startupDutyCycle = filterPwmDutyCycle(modp_atoi(value)); if (NAME_EQU("stPeriod", name)) pwmCfg->startupPeriod = filterPwmPeriod(modp_atoi(value)); if (NAME_EQU("vScal", name)) pwmCfg->voltageScaling = modp_atof(value); return valueTok + 1; }
static const jsmntok_t * setAnalogExtendedField(const jsmntok_t *valueTok, const char *name, const char *value, void *cfg){ ADCConfig *adcCfg = (ADCConfig *)cfg; if (NAME_EQU("prec",name)) adcCfg->loggingPrecision = modp_atoi(value); else if (NAME_EQU("scalMod", name)) adcCfg->scalingMode = filterAnalogScalingMode(modp_atoi(value)); else if (NAME_EQU("linScal", name)) adcCfg->linearScaling = modp_atof(value); else if (NAME_EQU("map", name)){ if (valueTok->type == JSMN_OBJECT) { valueTok++; valueTok = setScalingRow(adcCfg, valueTok); valueTok = setScalingRow(adcCfg, valueTok); valueTok--; } } return valueTok + 1; }
void WriteScriptPage(Serial *serial, unsigned int argc, char **argv){ if (argc < 2){ put_commandError(serial, ERROR_CODE_INVALID_PARAM); return; } unsigned int page = modp_atoi(argv[1]); char *scriptPage = ""; if (argc >= 3) scriptPage = argv[2]; if (page >=0 && page < SCRIPT_PAGES){ if (argc >= 2) unescape(scriptPage); lockLua(); vPortEnterCritical(); pr_info_int(strlen(scriptPage)); pr_info("="); pr_info(scriptPage); pr_info("\r\n"); int result = flashScriptPage(page, scriptPage); vPortExitCritical(); unlockLua(); if (result == 0){ put_commandOK(serial); } else{ put_commandError(serial, result); } } else{ put_commandError(serial, ERROR_CODE_INVALID_PARAM); } }
static int getSignalStrength(Serial *serial) { int res = sendCommand(serial, "AT+CSQ\r", "+CSQ:"); if (res != NO_CELL_RESPONSE && strlen(g_cellBuffer) > 6) { char *next_start = NULL; char *rssi_string = strtok_r(g_cellBuffer + 6, ",", &next_start); if (rssi_string != NULL) { g_cell_signal_strength = modp_atoi(rssi_string); pr_debug_int_msg("Cell: signal strength: ", g_cell_signal_strength); } } return res; }
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); } } }
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; }
static const jsmntok_t * setTimerExtendedField(const jsmntok_t *valueTok, const char *name, const char *value, void *cfg){ TimerConfig *timerCfg = (TimerConfig *)cfg; int iValue = modp_atoi(value); if (NAME_EQU("prec", name)) timerCfg->loggingPrecision = iValue; if (NAME_EQU("sTimer", name)) timerCfg->slowTimerEnabled = (iValue != 0); if (NAME_EQU("mode", name)) timerCfg->mode = filterTimerMode(iValue); if (NAME_EQU("ppRev", name)) { timerCfg->pulsePerRevolution = iValue; calculateTimerScaling(BOARD_MCK, timerCfg); } if (NAME_EQU("timDiv", name)) timerCfg->timerDivider = filterTimerDivider(iValue); return valueTok + 1; }
static const jsmntok_t * setScalingMapRaw(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.rawValues[i] = modp_atoi(mapArrayTok->data); } } } } return mapArrayTok + 1; }
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; } }
void ReadScriptPage(Serial *serial, unsigned int argc, char **argv){ if (argc < 2){ put_commandError(serial, ERROR_CODE_INVALID_PARAM); return; } int page = modp_atoi(argv[1]); if (page >=0 && page < SCRIPT_PAGES){ const char * script = getScript(); //forward to the requested page script += (MEMORY_PAGE_SIZE * page); //check for truncated page size_t scriptLen = strlen(script); if (scriptLen > MEMORY_PAGE_SIZE) scriptLen = MEMORY_PAGE_SIZE; put_nameEscapedString(serial, "script",script,scriptLen); } else{ put_commandError(serial, ERROR_CODE_INVALID_PARAM); } }
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; }
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; }
static const jsmntok_t * setGpioExtendedField(const jsmntok_t *valueTok, const char *name, const char *value, void *cfg){ GPIOConfig *gpioCfg = (GPIOConfig *)cfg; if (NAME_EQU("mode", name)) gpioCfg->mode = filterGpioMode(modp_atoi(value)); return valueTok + 1; }