protected DataBlock computeState(double time) { MechanicalState state = orbitPredictor.getECFState(time); // send to output DataBlock stateData = (lastRecord == null) ? outputDef.createDataBlock() : lastRecord.renew(); stateData.setDoubleValue(0, state.julianTime); stateData.setDoubleValue(1, state.linearPosition.x); stateData.setDoubleValue(2, state.linearPosition.y); stateData.setDoubleValue(3, state.linearPosition.z); stateData.setDoubleValue(4, state.linearVelocity.x); stateData.setDoubleValue(5, state.linearVelocity.y); stateData.setDoubleValue(6, state.linearVelocity.z); return stateData; }
/* TODO: only using HV message; add support for HT and ML */ private synchronized void pollAndSendMeasurement() { long msgTime = System.currentTimeMillis(); double hd = Double.NaN; double incl = Double.NaN; double az = Double.NaN; double sd = Double.NaN; try { boolean gotHvMsg = false; while (!gotHvMsg) { String line = msgReader.readLine(); String val, unit; // parse the data string TruPulseSensor.log.debug("Message received: {}", line); String[] tokens = line.split(","); val = tokens[0]; if (!val.equals(MSG_PREFIX)) { TruPulseSensor.log.warn( "Message initial token does NOT equal expected string {}", MSG_PREFIX); continue; } // check for desired message type HV val = tokens[1]; if (!val.equals(MSG_TYPE_HV)) { TruPulseSensor.log.warn("Unsupported message type {}", val); continue; } // get horizontal distance measure and check units (convert if not meters) val = tokens[2]; unit = tokens[3]; if (val.length() > 0 && unit.length() > 0) { hd = Double.parseDouble(val); hd = convert(hd, unit); } // get azimuth angle measure (units should be degrees) val = tokens[4]; unit = tokens[5]; if (val.length() > 0 && unit.length() > 0) az = Double.parseDouble(val); // get inclination angle measure (units should be degrees) val = tokens[6]; unit = tokens[7]; if (val.length() > 0 && unit.length() > 0) incl = Double.parseDouble(val); // get slope distance measure and check units (should be meters) val = tokens[8]; unit = tokens[9]; if (val.length() > 0 && unit.length() > 0) { sd = Double.parseDouble(val); sd = convert(hd, unit); } gotHvMsg = true; } } catch (IOException e) { TruPulseSensor.log.error("Unable to parse TruPulse message", e); } // create and populate datablock DataBlock dataBlock; if (latestRecord == null) dataBlock = laserData.createDataBlock(); else dataBlock = latestRecord.renew(); dataBlock.setDoubleValue(0, msgTime / 1000.); dataBlock.setDoubleValue(1, hd); dataBlock.setDoubleValue(2, sd); dataBlock.setDoubleValue(4, az); dataBlock.setDoubleValue(3, incl); // update latest record and send event latestRecord = dataBlock; latestRecordTime = msgTime; eventHandler.publishEvent( new SensorDataEvent(latestRecordTime, TruPulseOutput.this, dataBlock)); }
private void pollAndSendMeasurement() { double julianTime = 0.0; String mdtID = " "; String vehID = " "; String unitID = " "; double lat = Double.NaN; double lon = Double.NaN; String status = " "; String eventID = " "; try { boolean gotMsg = false; while (!gotMsg) { String line = msgReader.readLine(); if (line == null || line.length() == 0) return; String timeString; Date time; // parse the data string AVLDriver.log.debug("Message received: {}", line); // split tokens based on one or more white spaces String[] tokens = line.trim().split("\\s+"); // get time tag in pseudo standard string timeString = tokens[0]; // add "T" at end to make recognizable time zone (e.g. CDT) and then // parse according to predefined Intergraph 911 format try { time = timeFormat.parse(timeString + "T"); } catch (ParseException e) { AVLDriver.log.warn("Exception parsing date-time string ", timeString + "T"); continue; } if (time != null) julianTime = time.getTime() / 1000.0; // skip tokens[1] mdtID = tokens[2]; unitID = tokens[3]; vehID = tokens[4]; lat = Double.parseDouble(tokens[5]); lon = Double.parseDouble(tokens[6]); // skip tokens[7 - 15] status = tokens[16]; if (tokens.length > 17) // event id is not always present eventID = tokens[17]; else eventID = "NONE"; gotMsg = true; } } catch (IOException e) { if (sendData) AVLDriver.log.error("Unable to parse AVL message", e); return; } // create new FOI if needed parentSensor.addFoi(julianTime, vehID); // create and populate datablock DataBlock dataBlock; if (latestRecord == null) dataBlock = dataStruct.createDataBlock(); else dataBlock = latestRecord.renew(); dataBlock.setDoubleValue(0, julianTime); dataBlock.setStringValue(1, mdtID); dataBlock.setStringValue(2, unitID); dataBlock.setStringValue(3, vehID); dataBlock.setDoubleValue(4, lat); dataBlock.setDoubleValue(5, lon); dataBlock.setStringValue(6, status); dataBlock.setStringValue(7, eventID); // update latest record and send event latestRecord = dataBlock; latestRecordTime = System.currentTimeMillis(); eventHandler.publishEvent( new SensorDataEvent(latestRecordTime, vehID, AVLOutput.this, dataBlock)); }