static void printDecodedMessage(Decoded message) { insertions.Add(message); Console.WriteLine("---------------------------------------------"); Console.WriteLine(message["unparsedmessage"]); Console.WriteLine("\tType is " + message["messagetype"]); foreach (string key in message["decodedmessage"].Keys) { Console.WriteLine('\t' + key + " -> " + message["decodedmessage"][key]); } }
/// <summary> /// Parses a mesage sent by the Receiver -- for example, a detection or status message. Enqueues the decoded message. /// </summary> /// <param name="unparsedMessage">The unparsed message event generated by the Receiver class.</param> public void Decode(UnparsedMessage unparsedMessage) { Dictionary<String, String> payload = new Dictionary<String, String>(); string message = unparsedMessage["unparsedmessage"]; dynamic config = unparsedMessage["configuration"]; string messageType = getMessageType(message, config); if (messageType == "unknown") return; Match matches; foreach(string word in config.decoder.sentences[messageType].word_order) { String wordRegex = ((String)config.decoder.words[word]); matches = Regex.Match(message, wordRegex); if (matches.Success) payload.Add(word, matches.Groups[1].ToString()); else payload.Add(word, "NULL"); } Decoded d = new Decoded(payload, unparsedMessage, message, messageType); dispatcher.enqueueEvent(d); }
/// <summary> /// Makes an insertion into the receiver_status table of the databse for a status event. /// </summary> /// <param name="status">The RealTimeEvent object containing all necessary information from the status event.</param> /// <returns>The number of rows affected by the insertion.</returns> private int statusInsert(Decoded status) { string receiver_model_id = status["model"] + '-' + status["serialnumber"]; string date = status["decodedmessage"]["date"]; string time = status["decodedmessage"]["time"]; string dc = status["decodedmessage"]["dc"]; string pc = status["decodedmessage"]["pc"]; string lv = status["decodedmessage"]["lv"]; string bv = status["decodedmessage"]["bv"]; string bu = status["decodedmessage"]["bu"]; string i = status["decodedmessage"]["i"]; string t = status["decodedmessage"]["t"]; string du = status["decodedmessage"]["du"]; string ru = status["decodedmessage"]["ru"]; string xyz = status["decodedmessage"]["xyz"]; if (xyz != "NULL") xyz = '\'' + xyz + '\''; string statement = "INSERT INTO receiver_status (id, date, time, detection_count, ping_count, line_voltage, battery_voltage, battery_used, current, temperature, detection_memory, raw_memory, xyz_orientation) VALUES ('" + receiver_model_id + "', '" + date + "', '" + time + "', " + dc + ", " + pc + ", " + lv + ", " + bv + ", " + bu + ", " + i + ", " + t + ", " + du + ", " + ru + ", " + xyz + ");"; int response = doInsert(statement); dispatcher.enqueueEvent(new DatabaseResponse(statement, response, status)); return response; }
// We are no longer responsible for populating the receivers table in the database with new receivers. //private void receiverInsert(ReceiverSlice.RealTimeEvents.NewReceiver newReceiver) //{ // string statement = "INSERT INTO receivers (id) VALUES ('" + newReceiver["serialnumber"] + "');"; // int response = doInsert(statement); // dispatcher.enqueueEvent(new Databases.RealTimeEvents.DatabaseResponse(statement, response, newReceiver)); //} /// <summary> /// Makes an insertion into the vue table of the database for a detection event. /// </summary> /// <param name="detection">The RealTimeEvent object containing all necessary information from the detection.</param> /// <returns>The number of rows affected by the insertion.</returns> private int detectionInsert(Decoded detection) { string date = detection["decodedmessage"]["date"]; string time = detection["decodedmessage"]["time"]; string frequency_codespace = detection["decodedmessage"]["frequency_codespace"]; string transmitter_id = detection["decodedmessage"]["transmitter_id"]; string receiver_model_id = detection["model"] + '-' + detection["serialnumber"]; string sensor_value = detection["decodedmessage"]["sensor_value"]; string sensor_type = "NULL"; string transmitter_codespace_id = frequency_codespace + '-' + transmitter_id; if (sensor_value != "NULL") { if (sensor_calibrations.ContainsKey(transmitter_codespace_id)) { sensor_type = '\'' + sensor_calibrations[transmitter_codespace_id][0] + '\''; sensor_value = getCalibratedSensorValue(sensor_type, double.Parse(sensor_value), double.Parse(sensor_calibrations[transmitter_codespace_id][1]), double.Parse(sensor_calibrations[transmitter_codespace_id][2])).ToString(); } else sensor_type = "'A2D'"; } string statement = "INSERT INTO vue (date, time, frequency_codespace, transmitter_id, sensor_value, sensor_unit, receivers_id) VALUES ('" + date + "', '" + time + "', '" + frequency_codespace + "', " + transmitter_id + ", " + sensor_value + ", " + sensor_type + ", '" + receiver_model_id + "');"; int response = doInsert(statement); dispatcher.enqueueEvent(new DatabaseResponse(statement, response, detection)); return response; }