int KSI_HttpClient_init(KSI_CTX *ctx, KSI_HttpClient *client) { int res = KSI_UNKNOWN_ERROR; KSI_ERR_clearErrors(ctx); if (ctx == NULL || client == NULL) { KSI_pushError(ctx, res = KSI_INVALID_ARGUMENT, NULL); goto cleanup; } res = KSI_NetworkClient_init(ctx, &client->parent); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } client->agentName = NULL; client->sendRequest = NULL; client->urlExtender = NULL; client->urlPublication = NULL; client->urlAggregator = NULL; client->httpStatus = 0; client->parent.sendExtendRequest = prepareExtendRequest; client->parent.sendSignRequest = prepareAggregationRequest; client->parent.sendPublicationRequest = preparePublicationsFileRequest; client->parent.getStausCode = getHttpStatusCode; client->parent.implFree = (void (*)(void *))httpClient_free; setIntParam(&client->connectionTimeoutSeconds, 10); setIntParam(&client->readTimeoutSeconds, 10); setStringParam(&client->urlPublication, KSI_DEFAULT_URI_PUBLICATIONS_FILE); setStringParam(&client->agentName, "KSI HTTP Client"); /** Should be only user provided */ res = KSI_HttpClientImpl_init(client); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } res = KSI_OK; cleanup: return res; }
bool PRS10::command(int cmd,int cmdModifier,int NewValue,int chan) { // chan is only used by the SD and AD commands bool res; char msgbuf[256]; int i,itmp,ivtmp[8]; float ftmp; string stmp; switch (cmd) { case PRS10_RS: if (!(res=writeString("RS 1\r"))) error("RS 1 failed"); break; case PRS10_VB: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.verboseMode),"VB");break; case PRS10_SET:res=setIntParam(&(s.verboseMode),"VB",NewValue);break; } break; case PRS10_ID: if ((res=query("ID?\r",&stmp))) s.IDString=stmp; else error("ID? failed"); break; case PRS10_SN: if ((res = query("SN?\r",&itmp))) s.serialNumber=itmp; else error("SN failed"); break; case PRS10_ST: if ((res=query("ST?\r",ivtmp,6))) { for (i=0;i<6;i++) s.status[i]=ivtmp[i]; } else error("ST? failed"); break; case PRS10_LM: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.lockModePinConfiguration),"LM");break; case PRS10_SET:res=setIntParam(&(s.lockModePinConfiguration),"LM",NewValue);break; case PRS10_QUERY_EEPROM:break; case PRS10_WRITE_EEPROM:break; } break; case PRS10_RC: if (!(res=writeString("RC 1\r"))) error("RC 1 failed"); break; case PRS10_LO: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.fLockOn),"LO");break; case PRS10_SET:res=setIntParam(&(s.fLockOn),"LO",NewValue);break; } break; case PRS10_FC: switch (cmdModifier) { case PRS10_QUERY: if ((res=query("FC?\r",ivtmp,2))) { res=s.fControlHigh.setValue(ivtmp[0]); res=res && s.fControlLow.setValue(ivtmp[1]); if (!res) error("FC? out of range error"); } else error("FC? failed"); break; case PRS10_SET:break; case PRS10_QUERY_EEPROM:break; case PRS10_WRITE_EEPROM:break; } break; case PRS10_DS: if ((res=query("DS?\r",ivtmp,2))) { s.errorSignal=ivtmp[0]; s.signalStrength=ivtmp[1]; } else error("DS? failed"); break; case PRS10_SF: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.fOffset),"SF");break; case PRS10_SET:res=setIntParam(&(s.fOffset),"SF",NewValue);break; } break; case PRS10_SS: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.slopeCalibration),"SS");break; case PRS10_SET:res = setIntParam(&(s.slopeCalibration),"SS",NewValue);break;break; case PRS10_QUERY_EEPROM:break; default:error("SS wrong modifier");break; } break; case PRS10_GA: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.gainParameter),"GA");break; case PRS10_SET:res=setIntParam(&(s.gainParameter),"GA",NewValue);break; case PRS10_QUERY_EEPROM:break; case PRS10_WRITE_EEPROM:break; default:error("GA wrong modifier");break; } break; break; case PRS10_PH: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.phase),"PH");break; case PRS10_QUERY_EEPROM:break; default:error("PH wrong modifier");break; } break; case PRS10_SP: switch (cmdModifier) { case PRS10_QUERY: if ((res=query("SP?\r",ivtmp,3))) { res=s.fsR.setValue(ivtmp[0]); res=res && s.fsN.setValue(ivtmp[1]); res=res && s.fsA.setValue(ivtmp[2]); if (!res) error("SP? out of range error"); } else error("SP? failed"); break; case PRS10_SET:break; // FIXME case PRS10_QUERY_EEPROM:break; case PRS10_WRITE_EEPROM:break; } break; case PRS10_MS: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.magneticSwitching),"MS");break; case PRS10_SET:res=setIntParam(&(s.magneticSwitching),"MS",NewValue);break;break; default:error("MS wrong modifier");break; } break; case PRS10_MO: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.magneticOffset),"MO");break; case PRS10_SET:res=setIntParam(&(s.magneticOffset),"MO",NewValue);break; case PRS10_QUERY_EEPROM: res = getIntParam(&(s.eeprom.magneticOffset),"MO!");break; case PRS10_WRITE_EEPROM: res = writeEEPROM("MO");break; default:error("MO wrong modifier");break; } break; case PRS10_MR: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.magneticRead),"MR");break; default:error("MR wrong modifier");break; } break; case PRS10_TT: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.timeTag),"TT");break; default:error("TT wrong modifier");break; } break; case PRS10_TS: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.timeSlope),"TS");break; case PRS10_QUERY_EEPROM:break; default:error("TS wrong modifier");break; } break; case PRS10_TO: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.timeOffset),"TO");break; case PRS10_QUERY_EEPROM:break; default:error("TO wrong modifier");break; } break; case PRS10_PP: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.ppsOffset),"PP");break; case PRS10_SET:res=setIntParam(&(s.ppsOffset),"PP",NewValue);break; default:error("PP wrong modifier");break; } break; case PRS10_PS: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.ppsSlopeCalibration),"PS");break; case PRS10_QUERY_EEPROM:break; default:error("PS wrong modifier");break; } break; case PRS10_PL: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.ppsPLLOn),"PL");break; case PRS10_SET:res=setIntParam(&(s.ppsPLLOn),"PL",NewValue);break; case PRS10_QUERY_EEPROM: res = getIntParam(&(s.eeprom.ppsPLLOn),"PL!");break; case PRS10_WRITE_EEPROM: res = writeEEPROM("PL");break; default:error("PL wrong modifier");break; } break; case PRS10_PT: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.ppsPLLTimeConstant),"PT");break; case PRS10_SET:res=setIntParam(&(s.ppsPLLTimeConstant),"PT",NewValue);break; case PRS10_QUERY_EEPROM:break; case PRS10_WRITE_EEPROM:break; default:error("PT wrong modifier");break; } break; case PRS10_PF: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.ppsPLLStabilityFactor),"PF");break; case PRS10_SET:res=setIntParam(&(s.ppsPLLStabilityFactor),"PF",NewValue);break; case PRS10_QUERY_EEPROM:break; case PRS10_WRITE_EEPROM:break; default:error("PF wrong modifier");break; } break; case PRS10_PI: switch (cmdModifier) { case PRS10_QUERY:res = getIntParam(&(s.ppsPLLIntegrator),"PI");break; case PRS10_SET:res=setIntParam(&(s.ppsPLLIntegrator),"PI",NewValue);break;break; default:error("PI wrong modifier");break; } break; case PRS10_SD: switch (cmdModifier) { case PRS10_QUERY: sprintf(msgbuf,"SD%i?\r",chan); if ((res=query(msgbuf,&itmp))) s.DACSettings[chan]=itmp; else error("SD? failed"); break; case PRS10_QUERY_EEPROM:break; default:error("SD wrong modifier");break; } break; case PRS10_AD: sprintf(msgbuf,"AD%i?\r",chan); if ((res=query(msgbuf,&ftmp))) s.testVoltages[chan]=scaleFactors[chan]*ftmp; break; } return res; }