/** * <summary> * Builds a list of all data streams hold by the data logger. * <para> * The caller must pass by reference an empty array to hold YDataStream * objects, and the function fills it with objects describing available * data sequences. * </para> * </summary> * <param name="v"> * an array of YDataStream objects to be filled in * </param> * <returns> * YAPI.SUCCESS if the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public int get_dataStreams(List <YDataStream> v) { int functionReturnValue = 0; YAPI.TJsonParser j = null; int i = 0; int res = 0; YAPI.TJSONRECORD root = default(YAPI.TJSONRECORD); YAPI.TJSONRECORD el = default(YAPI.TJSONRECORD); v.Clear(); res = getData(0, 0, ref j); if ((res != YAPI.SUCCESS)) { functionReturnValue = res; return(functionReturnValue); } root = j.GetRootNode(); for (i = 0; i <= root.itemcount - 1; i++) { el = root.items[i]; v.Add(new YDataStream(this, el.items[0].ivalue, el.items[1].ivalue, el.items[2].ivalue, el.items[3].ivalue)); } j = null; functionReturnValue = YAPI.SUCCESS; return(functionReturnValue); }
// Token: 0x060000B5 RID: 181 RVA: 0x000058E8 File Offset: 0x00003AE8 public int load(int msValidity) { YAPI.YDevice dev = null; string errmsg = ""; YAPI.TJsonParser apires = null; string errbuf = ""; string funcId = ""; int devdesc = 0; string serial = ""; string funcName = ""; string funcVal = ""; YAPI.TJSONRECORD?node = null; int res = this._getDevice(ref dev, ref errmsg); if (YAPI.YISERR(res)) { this._throw(res, errmsg); return(res); } res = dev.requestAPI(out apires, ref errmsg); if (YAPI.YISERR(res)) { this._throw(res, errmsg); return(res); } int fundescr = YAPI.yapiGetFunction(this._className, this._func, ref errmsg); if (YAPI.YISERR(fundescr)) { this._throw(res, errmsg); return(fundescr); } devdesc = 0; res = YAPI.yapiGetFunctionInfo(fundescr, ref devdesc, ref serial, ref funcId, ref funcName, ref funcVal, ref errbuf); if (YAPI.YISERR(res)) { this._throw(res, errmsg); return(res); } node = apires.GetChildNode(null, funcId); if (node == null) { this._throw(-8, "unexpected JSON structure: missing function " + funcId); return(-8); } this._parse(node.GetValueOrDefault()); this._cacheExpiration = YAPI.GetTickCount() + (long)msValidity; return(0); }
//--- (end of generated code: YFileRecord definitions) public YFileRecord(string data) { YAPI.TJsonParser p; Nullable<YAPI.TJSONRECORD> node; //--- (generated code: YFileRecord attributes initialization) //--- (end of generated code: YFileRecord attributes initialization) p = new YAPI.TJsonParser(data, false); node = p.GetChildNode(null, "name"); this._name = node.Value.svalue; node = p.GetChildNode(null, "size"); this._size = (int)node.Value.ivalue; node = p.GetChildNode(null, "crc"); this._crc = (int)node.Value.ivalue; }
//--- (end of generated code: YFileRecord definitions) public YFileRecord(string data) { YAPI.TJsonParser p; Nullable <YAPI.TJSONRECORD> node; //--- (generated code: YFileRecord attributes initialization) //--- (end of generated code: YFileRecord attributes initialization) p = new YAPI.TJsonParser(data, false); node = p.GetChildNode(null, "name"); this._name = node.Value.svalue; node = p.GetChildNode(null, "size"); this._size = (int)node.Value.ivalue; node = p.GetChildNode(null, "crc"); this._crc = (int)node.Value.ivalue; }
/** * <summary> * Builds a list of all data streams hold by the data logger (legacy method). * <para> * The caller must pass by reference an empty array to hold YDataStream * objects, and the function fills it with objects describing available * data sequences. * </para> * <para> * This is the old way to retrieve data from the DataLogger. * For new applications, you should rather use <c>get_dataSets()</c> * method, or call directly <c>get_recordedData()</c> on the * sensor object. * </para> * <para> * </para> * </summary> * <param name="v"> * an array of YDataStream objects to be filled in * </param> * <returns> * <c>YAPI.SUCCESS</c> if the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public int get_dataStreams(List <YDataStream> v) { YAPI.TJsonParser j = null; int i = 0; int res = 0; YAPI.TJSONRECORD root = default(YAPI.TJSONRECORD); YAPI.TJSONRECORD el = default(YAPI.TJSONRECORD); v.Clear(); res = getData(0, 0, ref j); if (res != YAPI.SUCCESS) { return(res); } root = j.GetRootNode(); if (root.itemcount == 0) { return(YAPI.SUCCESS); } if (root.items[0].recordtype == YAPI.TJSONRECORDTYPE.JSON_ARRAY) { // old datalogger format: [runIdx, timerel, utc, interval] for (i = 0; i <= root.itemcount - 1; i++) { el = root.items[i]; v.Add(new YOldDataStream(this, (int)el.items[0].ivalue, (int)el.items[1].ivalue, (UInt32)el.items[2].ivalue, (int)el.items[3].ivalue)); } } else { // new datalogger format: {"id":"...","unit":"...","streams":["...",...]} string json_buffer = j.convertToString(root, false); List <YDataSet> sets = this.parse_dataSets(YAPI.DefaultEncoding.GetBytes(json_buffer)); for (int sj = 0; sj < sets.Count; sj++) { List <YDataStream> ds = sets[sj].get_privateDataStreams(); for (int si = 0; si < ds.Count; si++) { v.Add(ds[si]); } } } j = null; return(YAPI.SUCCESS); }
//--- (end of generated code: YWlanRecord definitions) public YWlanRecord(string data) { YAPI.TJsonParser p; Nullable <YAPI.TJSONRECORD> node; //--- (generated code: YWlanRecord attributes initialization) //--- (end of generated code: YWlanRecord attributes initialization) p = new YAPI.TJsonParser(data, false); node = p.GetChildNode(null, "ssid"); this._ssid = node.Value.svalue; node = p.GetChildNode(null, "sec"); this._sec = node.Value.svalue; node = p.GetChildNode(null, "rssi"); this._rssi = (int)node.Value.ivalue; node = p.GetChildNode(null, "channel"); this._channel = (int)node.Value.ivalue; }
//--- (end of generated code: YDataLogger implementation) public int getData(long runIdx, long timeIdx, ref YAPI.TJsonParser jsondata) { YAPI.YDevice dev = null; string errmsg = ""; string query = null; string buffer = ""; int res = 0; if (_dataLoggerURL == "") { _dataLoggerURL = "/logger.json"; } // Resolve our reference to our device, load REST API res = _getDevice(ref dev, ref errmsg); if (YAPI.YISERR(res)) { _throw(res, errmsg); return(res); } if (timeIdx > 0) { query = "GET " + _dataLoggerURL + "?run=" + runIdx.ToString() + "&time=" + timeIdx.ToString() + " HTTP/1.1\r\n\r\n"; } else { query = "GET " + _dataLoggerURL + " HTTP/1.1\r\n\r\n"; } res = dev.HTTPRequest(query, ref buffer, ref errmsg); if (YAPI.YISERR(res)) { res = YAPI.UpdateDeviceList(ref errmsg); if (YAPI.YISERR(res)) { _throw(res, errmsg); return(res); } res = dev.HTTPRequest("GET " + _dataLoggerURL + " HTTP/1.1\r\n\r\n", ref buffer, ref errmsg); if (YAPI.YISERR(res)) { _throw(res, errmsg); return(res); } } try { jsondata = new YAPI.TJsonParser(buffer); } catch (Exception e) { errmsg = "unexpected JSON structure: " + e.Message; _throw(YAPI.IO_ERROR, errmsg); return(YAPI.IO_ERROR); } if (jsondata.httpcode == 404 && _dataLoggerURL != "/dataLogger.json") { // retry using backward-compatible datalogger URL _dataLoggerURL = "/dataLogger.json"; return(this.getData(runIdx, timeIdx, ref jsondata)); } return(YAPI.SUCCESS); }
public new int loadStream() { YAPI.TJsonParser json = null; int res = 0; int count = 0; YAPI.TJSONRECORD root = default(YAPI.TJSONRECORD); YAPI.TJSONRECORD el = default(YAPI.TJSONRECORD); string name = null; List <int> coldiv = new List <int>(); List <int> coltype = new List <int>(); List <int> udat = new List <int>(); List <double> date = new List <double>(); List <double> colscl = new List <double>(); List <int> colofs = new List <int>(); List <int> caltyp = new List <int>(); List <YAPI.yCalibrationHandler> calhdl = new List <YAPI.yCalibrationHandler>(); List <List <int> > calpar = new List <List <int> >(); List <List <double> > calraw = new List <List <double> >(); List <List <double> > calref = new List <List <double> >(); int x = 0; int i = 0; int j = 0; res = _dataLogger.getData(_runNo, _timeStamp, ref json); if ((res != YAPI.SUCCESS)) { return(res); } _nRows = 0; _nCols = 0; _columnNames.Clear(); _values = new List <List <double> >(); root = json.GetRootNode(); for (i = 0; i <= root.membercount - 1; i++) { el = root.members[i]; name = el.name; if (name == "time") { _timeStamp = (int)el.ivalue; } else if (name == "UTC") { _utcStamp = (UInt32)el.ivalue; } else if (name == "interval") { _interval = (int)el.ivalue; } else if (name == "nRows") { _nRows = (int)el.ivalue; } else if (name == "keys") { _nCols = el.itemcount; for (j = 0; j <= _nCols - 1; j++) { _columnNames.Add(el.items[j].svalue); } } else if (name == "div") { _nCols = el.itemcount; for (j = 0; j <= _nCols - 1; j++) { coldiv.Add((int)el.items[j].ivalue); } } else if (name == "type") { _nCols = el.itemcount; for (j = 0; j <= _nCols - 1; j++) { coltype.Add((int)el.items[j].ivalue); } } else if (name == "scal") { _nCols = el.itemcount; for (j = 0; j <= _nCols - 1; j++) { colscl.Add(el.items[j].ivalue / 65536.0); if (coltype[j] != 0) { colofs.Add(-32767); } else { colofs.Add(0); } } } else if (name == "cal") { //fixme no calibration } else if (name == "data") { if (colscl.Count <= 0) { for (j = 0; j <= _nCols - 1; j++) { colscl.Add(1.0 / coldiv[j]); if (coltype[j] != 0) { colofs.Add(-32767); } else { colofs.Add(0); } } } udat.Clear(); if (el.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRING) { udat = YAPI._decodeWords(el.svalue); } else { count = el.itemcount; for (j = 0; j <= count - 1; j++) { int tmp = (int)(el.items[j].ivalue); udat.Add(tmp); } } _values = new List <List <double> >(); List <double> dat = new List <double>(); foreach (int uval in udat) { double value; if (coltype[x] < 2) { value = (uval + colofs[x]) * colscl[x]; } else { value = YAPI._decimalToDouble(uval - 32767); } if (caltyp[x] > 0 && calhdl[x] != null) { YAPI.yCalibrationHandler handler = calhdl[x]; if (caltyp[x] <= 10) { value = handler((uval + colofs[x]) / coldiv[x], caltyp[x], calpar[x], calraw[x], calref[x]); } else if (caltyp[x] > 20) { value = handler(value, caltyp[x], calpar[x], calraw[x], calref[x]); } } dat.Add(value); x++; if (x == _nCols) { _values.Add(dat); dat.Clear(); x = 0; } } } } json = null; return(YAPI.SUCCESS); }
public int getData(long runIdx, long timeIdx, ref YAPI.TJsonParser jsondata) { int functionReturnValue = 0; YAPI.YDevice dev = null; string errmsg = ""; string query = null; string buffer = ""; int res = 0; if (_dataLoggerURL == "") _dataLoggerURL = "/logger.json"; // Resolve our reference to our device, load REST API res = _getDevice(ref dev, ref errmsg); if ((YAPI.YISERR(res))) { _throw(res, errmsg); functionReturnValue = res; return functionReturnValue; } if ((timeIdx > 0)) { query = "GET " + _dataLoggerURL + "?run=" + runIdx.ToString() + "&time=" + timeIdx.ToString() + " HTTP/1.1\n\r\n\r"; } else { query = "GET " + _dataLoggerURL + " HTTP/1.1\n\r\n\r"; } res = dev.HTTPRequest(query, ref buffer, ref errmsg); if ((YAPI.YISERR(res))) { res = YAPI.UpdateDeviceList(ref errmsg); if ((YAPI.YISERR(res))) { _throw(res, errmsg); functionReturnValue = res; return functionReturnValue; } res = dev.HTTPRequest("GET " + _dataLoggerURL + " HTTP/1.1\n\r\n\r", ref buffer, ref errmsg); if ((YAPI.YISERR(res))) { _throw(res, errmsg); functionReturnValue = res; return functionReturnValue; } } try { jsondata = new YAPI.TJsonParser(buffer); } catch (Exception e) { errmsg = "unexpected JSON structure: " + e.Message; _throw(YAPI.IO_ERROR, errmsg); functionReturnValue = YAPI.IO_ERROR; return functionReturnValue; } if (jsondata.httpcode == 404 && _dataLoggerURL != "/dataLogger.json") { // retry using backward-compatible datalogger URL _dataLoggerURL = "/dataLogger.json"; return this.getData(runIdx, timeIdx, ref jsondata); } functionReturnValue = YAPI.SUCCESS; return functionReturnValue; }
//--- (end of generated code: YWlanRecord definitions) public YWlanRecord(string data) { YAPI.TJsonParser p; Nullable<YAPI.TJSONRECORD> node; //--- (generated code: YWlanRecord attributes initialization) //--- (end of generated code: YWlanRecord attributes initialization) p = new YAPI.TJsonParser(data, false); node = p.GetChildNode(null, "ssid"); this._ssid = node.Value.svalue; node = p.GetChildNode(null, "sec"); this._sec = node.Value.svalue; node = p.GetChildNode(null, "rssi"); this._rssi = (int)node.Value.ivalue; node = p.GetChildNode(null, "channel"); this._channel = (int)node.Value.ivalue; }
private int loadStream() { YAPI.TJsonParser json = null; int res = 0; int count = 0; YAPI.TJSONRECORD root = default(YAPI.TJSONRECORD); YAPI.TJSONRECORD el = default(YAPI.TJSONRECORD); string name = null; List <int> coldiv = new List <int>(); List <int> coltype = new List <int>(); List <uint> udat = new List <uint>(); List <double> date = new List <double>(); List <double> colscl = new List <double>(); int x = 0; int y = 0; int i = 0; int j = 0; double value = 0; res = dataLogger.getData(runNo, timeStamp, ref json); if ((res != YAPI.SUCCESS)) { return(res); } nRows = 0; nCols = 0; columnNames.Clear(); values = new double[1, 1]; root = json.GetRootNode(); for (i = 0; i <= root.membercount - 1; i++) { el = root.members[i]; name = el.name; if (name == "time") { timeStamp = el.ivalue; } else if (name == "UTC") { utcStamp = el.ivalue; } else if (name == "interval") { interval = el.ivalue; } else if (name == "nRows") { nRows = el.ivalue; } else if (name == "keys") { nCols = el.itemcount; for (j = 0; j <= nCols - 1; j++) { columnNames.Add(el.items[j].svalue); } } else if (name == "div") { nCols = el.itemcount; for (j = 0; j <= nCols - 1; j++) { coldiv.Add(el.items[j].ivalue); } } else if (name == "type") { nCols = el.itemcount; for (j = 0; j <= nCols - 1; j++) { coltype.Add(el.items[j].ivalue); } } else if (name == "scal") { nCols = el.itemcount; for (j = 0; j <= nCols - 1; j++) { colscl.Add(el.items[j].ivalue / 65536.0); } } else if (name == "data") { if (colscl.Count <= 0) { for (j = 0; j <= nCols - 1; j++) { colscl.Add(1.0 / coldiv[j]); } } udat.Clear(); if (el.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRING) { string sdat = el.svalue; for (int p = 0; p < sdat.Length;) { uint val; uint c = sdat[p++]; if (c >= 'a') { int srcpos = (int)(udat.Count - 1 - (c - 'a')); if (srcpos < 0) { dataLogger.throw_friend(YAPI.IO_ERROR, "Unexpected JSON reply format"); return(YAPI.IO_ERROR); } val = udat[srcpos]; } else { if (p + 2 > sdat.Length) { dataLogger.throw_friend(YAPI.IO_ERROR, "Unexpected JSON reply format"); return(YAPI.IO_ERROR); } val = (c - '0'); c = sdat[p++]; val += (c - '0') << 5; c = sdat[p++]; if (c == 'z') { c = '\\'; } val += (c - '0') << 10; } udat.Add(val); } } else { count = el.itemcount; for (j = 0; j <= count - 1; j++) { u32 tmp = (u32)(el.items[j].ivalue); udat.Add(tmp); } } values = new double[nRows, nCols]; foreach (u32 uval in udat) { value = uval; if (coltype[x] == 0) { value = value * colscl[x]; } else { if (coltype[x] == 1) { value = (value - 32767) * colscl[x]; } } values[y, x] = value; x++; if (x == nCols) { x = 0; y++; } } } } json = null; return(YAPI.SUCCESS); }
protected string _json_get_key(byte[] data, string key) { Nullable<YAPI.TJSONRECORD> node; string st = YAPI.DefaultEncoding.GetString(data); YAPI.TJsonParser p; if (!YAPI.ExceptionsDisabled) p= new YAPI.TJsonParser(st, false); else try { p = new YAPI.TJsonParser(st, false); } catch { return ""; } node = p.GetChildNode(null, key); return node.Value.svalue; }
protected List<string> _json_get_array(byte[] data) { string st = YAPI.DefaultEncoding.GetString(data); YAPI.TJsonParser p; if (!YAPI.ExceptionsDisabled) p = new YAPI.TJsonParser(st, false); else try { p = new YAPI.TJsonParser(st, false); } catch { return null; } return p.GetAllChilds(null); }
public string _json_get_string(byte[] data) { Nullable<YAPI.TJSONRECORD> node; string json_str = YAPI.DefaultEncoding.GetString(data); YAPI.TJsonParser p = new YAPI.TJsonParser('[' + json_str + ']', false); node = p.GetRootNode(); return node.Value.items[0].svalue; }
protected int _parse(string data) { YAPI.TJsonParser p; if (!YAPI.ExceptionsDisabled) p= new YAPI.TJsonParser(data, false); else try { p = new YAPI.TJsonParser(data, false); } catch { return YAPI.IO_ERROR; } Nullable<YAPI.TJSONRECORD> node, arr; YDataStream stream; long streamStartTime; long streamEndTime; long startTime = 0x7fffffff; long endTime = 0; double summaryMinVal = Double.MaxValue; double summaryMaxVal = -Double.MaxValue; double summaryTotalTime = 0; double summaryTotalAvg = 0; node = p.GetChildNode(null, "id"); this._functionId = node.Value.svalue; node = p.GetChildNode(null, "unit"); this._unit = node.Value.svalue; node = p.GetChildNode(null, "calib"); if (node != null) { this._calib = YAPI._decodeFloats(node.Value.svalue); this._calib[0] = this._calib[0] / 1000; } else { node = p.GetChildNode(null, "cal"); this._calib = YAPI._decodeWords(node.Value.svalue); } arr = p.GetChildNode(null, "streams"); this._streams = new List<YDataStream>(); this._preview = new List<YMeasure>(); this._measures = new List<YMeasure>(); for (int i = 0; i < arr.Value.itemcount; i++) { stream = _parent._findDataStream(this, arr.Value.items[i].svalue); streamStartTime = stream.get_startTimeUTC() - stream.get_dataSamplesIntervalMs() / 1000; streamEndTime = stream.get_startTimeUTC() + stream.get_duration(); if (_startTime > 0 && streamEndTime <= _startTime) { // this stream is too early, drop it } else if (_endTime > 0 && stream.get_startTimeUTC() > this._endTime) { // this stream is too late, drop it } else { _streams.Add(stream); if (startTime > streamStartTime) { startTime = streamStartTime; } if (endTime < streamEndTime) { endTime = streamEndTime; } if (stream.isClosed() && stream.get_startTimeUTC() >= this._startTime && (this._endTime == 0 || streamEndTime <= this._endTime)) { if (summaryMinVal > stream.get_minValue()) { summaryMinVal = stream.get_minValue(); } if (summaryMaxVal < stream.get_maxValue()) { summaryMaxVal = stream.get_maxValue(); } summaryTotalAvg += stream.get_averageValue() * stream.get_duration(); summaryTotalTime += stream.get_duration(); YMeasure rec = new YMeasure( stream.get_startTimeUTC(), streamEndTime, stream.get_minValue(), stream.get_averageValue(), stream.get_maxValue()); this._preview.Add(rec); } } } if ((this._streams.Count > 0) && (summaryTotalTime>0)) { // update time boundaries with actual data if (this._startTime < startTime) { this._startTime = startTime; } if (this._endTime == 0 || this._endTime > endTime) { this._endTime = endTime; } this._summary = new YMeasure( _startTime, _endTime, summaryMinVal, summaryTotalAvg / summaryTotalTime, summaryMaxVal); } this._progress = 0; return this.get_progress(); }