Permalink
Browse files

Hey this thing might actually work.

  • Loading branch information...
1 parent 694d0e6 commit 1f568602643aa80355109e8d42c96180298c4c84 @Teltnuag Teltnuag committed Nov 15, 2012
@@ -2,8 +2,8 @@
"log_file":"C:\\databaseErrorLog.txt",
"firmware_version":0,
"transmitters":{
- "A69-9001-50":{"m", "3.55", "2.52"},
- "A69-9023-623":{"p", "74.2", "130"},
+ "A69-9001-50":"m,3.55,2.52",
+ "A69-9023-623":"p,74.2,130",
},
"discovery_commands":[
"*BROADC.A#ST,QUIT",
@@ -53,11 +53,12 @@
"bv":"BV=([0-9]+\\.[0-9]+)",
"bu":"BU=([0-9]+\\.[0-9]+)",
"i":"I=([0-9]+\\.[0-9]+)",
+ "t":"T=([0-9]+\\.[0-9]+)",
"du":"DU=([0-9]+\\.[0-9]+)",
"ru":"RU=([0-9]+\\.[0-9]+)",
"xyz":"XYZ=(-?[0-9]+\\.[0-9]+:-?[0-9]+\\.[0-9]+:-?[0-9]+\\.[0-9]+)",
"state":":-?[0-9]+\\.[0-9]+,([A-Z]+)",
- "rtm_mode":"(OFF|232|485)",
+ "rtm_mode":",(OFF|232|485),",
"si":"SI=(POLL|[0-9]+)",
"bl":"BL=(U|[0-9]+)",
"bi":"BI=(WFS|[0-9]+)",
@@ -76,15 +77,15 @@
},
"rtm_info_response": {
"format":"(OFF|232|485),SI=(POLL|[0-9]+),BL=(U|[0-9]+),BI=(WFS|[0-9]+),MA=(U|[0-9]+),FMT=([A-Z_ ])*",
- "word_order":["rtm_mode","si","bl","bi","ma","fmt"]
+ "word_order":["receivers_id","p","decimal_sum","byte_count","rtm_mode","si","bl","bi","ma","fmt"]
},
"info_response": {
"format":"([0-9A-Z]+-[0-9A-Z]+):([0-9]{6}),'([0-9A-Z]*)',([A-Z0-9]+-[0-9]+)",
"word_order":["receiver_model","receivers_id","study_name","map","code_space","firmware_version","hardware_version"]
},
"status_response": {
"format":"STS,DC=([0-9]+),PC=([0-9]+)",
- "word_order":["date","time","dc","pc","lv","bc","bu","i","t","du","ru","xyz"]
+ "word_order":["receivers_id","date","time","dc","pc","lv","bv","bu","i","t","du","ru","xyz"]
}
}
}
@@ -49,10 +49,16 @@ public override string getModuleName()
/// <param name="calibrations">The JSON file containing the calibration values.</param>
public void updateSensorCalibrations(dynamic config)
{
- this.sensor_calibrations = new Dictionary<string,List<string>>();
- foreach (dynamic transmitter in config.transmitters)
+ this.sensor_calibrations = new Dictionary<string, List<string>>();
+ foreach (string transmitter in config.transmitters.Keys)
{
-
+ List<string> temp = new List<string>(((string)config.transmitters[transmitter]).Split(','));
+ if (temp.Count == 3)
+ {
+ double test;
+ if (double.TryParse(temp[1], out test) && double.TryParse(temp[2], out test))
+ sensor_calibrations.Add((string)transmitter, temp);
+ }
}
}
@@ -99,21 +105,14 @@ private int detectionInsert(Decoder.RealTimeEvents.Decoded detection)
string receiver_model_id = detection["model"] + '-' + detection["serialnumber"];
string sensor_value = detection["decodedmessage"]["sensor_value"];
string sensor_type = "A2D";
- string statement;
- if (sensor_value == null)
- statement = "INSERT INTO vue (date, time, frequency_codespace, transmitter_id, receivers_id) VALUES ('" +
- date + "', '" + time + "', '" + frequency_codespace + "', " + transmitter_id + ", '" + receiver_model_id + "');";
- else
+ string transmitter_codespace_id = frequency_codespace + '-' + transmitter_id;
+ if (sensor_value != "NULL" && sensor_calibrations.ContainsKey(transmitter_codespace_id))
{
- string transmitter_codespace_id = frequency_codespace + '-' + transmitter_id;
- 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();
- }
- 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 + "');";
+ 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();
}
+ 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 Databases.RealTimeEvents.DatabaseResponse(statement, response, detection));
return response;
@@ -158,12 +157,7 @@ private int statusInsert(Decoder.RealTimeEvents.Decoded status)
string du = status["decodedmessage"]["du"];
string ru = status["decodedmessage"]["ru"];
string xyz = status["decodedmessage"]["xyz"];
- string statement;
- if(xyz == null)
- statement = "INSERT INTO receiver_status (id, date, time, detection_count, ping_count, line_voltage, battery_used, current, temperature, detection_memory, raw_memory) VALUES ('" +
- receiver_model_id + "', '" + date + "', '" + time + "', " + dc + ", " + pc + ", " + lv + ", " + bc + ", " + bu + ", " + i + ", " + t + ", " + du + ", " + ru + ");";
- else
- statement = "INSERT INTO receiver_status (id, date, time, detection_count, ping_count, line_voltage, battery_used, current, temperature, detection_memory, raw_memory, xyz_orientation) VALUES ('" +
+ string statement = "INSERT INTO receiver_status (id, date, time, detection_count, ping_count, line_voltage, battery_used, current, temperature, detection_memory, raw_memory, xyz_orientation) VALUES ('" +
receiver_model_id + "', '" + date + "', '" + time + "', " + dc + ", " + pc + ", " + lv + ", " + bc + ", " + bu + ", " + i + ", " + t + ", " + du + ", " + ru + ", '" + xyz + "');";
int response = doInsert(statement);
dispatcher.enqueueEvent(new Databases.RealTimeEvents.DatabaseResponse(statement, response, status));
View
@@ -39,16 +39,16 @@ public void Decode(ReceiverSlice.RealTimeEvents.UnparsedMessage unparsedMessage)
dynamic config = unparsedMessage["configuration"];
string messageType = getMessageType(message, config);
Match matches;
- foreach(string word in config.decoder[messageType].word_order)
+ 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);
+ payload.Add(word, "NULL");
}
- dispatcher.enqueueEvent(new RealTimeEvents.Decoded(payload, unparsedMessage, message, messageType));
+ dispatcher.enqueueEvent(new Decoded(payload, unparsedMessage, message, messageType));
}
/// <summary>
@@ -58,28 +58,21 @@ public void Decode(ReceiverSlice.RealTimeEvents.UnparsedMessage unparsedMessage)
/// <param name="unparsedMessage">The unparsed message event generated by the Receiver class.</param>
/// <param name="config">json configuration file corresponding to a receivers firmware version</param>
/// <returns>type of message</returns>
- private string getMessageType(string unparsedMessage, dynamic config)
- {
- foreach (dynamic sentence in config.decoder.sentences)
+ private string getMessageType(string unparsedMessage, dynamic config)
+ {
+ foreach (string sentence in config.decoder.sentences.Keys)
{
try
{
- List<String> wordExpansions = new List<String>();
- foreach(Object o in sentence.word_orders)
- {
- wordExpansions.Add(config.decoder.words[((String)o)]);
- }
- if(Regex.IsMatch(unparsedMessage, String.Format(sentence.format, wordExpansions)))
- {
+ if (Regex.IsMatch(unparsedMessage, config.decoder.sentences[sentence].format))
return sentence;
- }
-
- } finally {
}
+ finally
+ { }
}
- EventSlice.Interfaces.ModuleException me = new ModuleException(this,
+ ModuleException me = new ModuleException(this,
"Unparsed message (" + unparsedMessage + ") does not match definition in this config.");
- //dispatcher.enqueueEvent(new RealTimeEvents.RealTimeEventUnknown(me.exceptionText,config));
+ dispatcher.enqueueEvent(new RealTimeEvents.RealTimeEventUnknown(me.exceptionText,config));
throw me;
}
@@ -48,11 +48,15 @@ public override string getModuleName()
public void updateSensorCalibrations(dynamic config)
{
this.sensor_calibrations = new Dictionary<string, List<string>>();
- foreach (string transmitter in config.transmitters)
+ foreach (string transmitter in config.transmitters.Keys)
{
List<string> temp = new List<string>(((string)config.transmitters[transmitter]).Split(','));
if (temp.Count == 3)
- sensor_calibrations.Add((string)transmitter, temp);
+ {
+ double test;
+ if(double.TryParse(temp[1], out test) && double.TryParse(temp[2], out test))
+ sensor_calibrations.Add((string)transmitter, temp);
+ }
}
}
@@ -99,21 +103,14 @@ private int detectionInsert(Decoded detection)
string receiver_model_id = detection["model"] + '-' + detection["serialnumber"];
string sensor_value = detection["decodedmessage"]["sensor_value"];
string sensor_type = "A2D";
- string statement;
- if (sensor_value == null)
- statement = "INSERT INTO vue (date, time, frequency_codespace, transmitter_id, receivers_id) VALUES ('" +
- date + "', '" + time + "', '" + frequency_codespace + "', " + transmitter_id + ", '" + receiver_model_id + "');";
- else
+ string transmitter_codespace_id = frequency_codespace + '-' + transmitter_id;
+ if (sensor_value != "NULL" && sensor_calibrations.ContainsKey(transmitter_codespace_id))
{
- string transmitter_codespace_id = frequency_codespace + '-' + transmitter_id;
- 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();
- }
- 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 + "');";
+ 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();
}
+ 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 Databases.RealTimeEvents.DatabaseResponse(statement, response, detection));
return response;
@@ -158,12 +155,7 @@ private int statusInsert(Decoded status)
string du = status["decodedmessage"]["du"];
string ru = status["decodedmessage"]["ru"];
string xyz = status["decodedmessage"]["xyz"];
- string statement;
- if (xyz == null)
- statement = "INSERT INTO receiver_status (id, date, time, detection_count, ping_count, line_voltage, battery_used, current, temperature, detection_memory, raw_memory) VALUES ('" +
- receiver_model_id + "', '" + date + "', '" + time + "', " + dc + ", " + pc + ", " + lv + ", " + bc + ", " + bu + ", " + i + ", " + t + ", " + du + ", " + ru + ");";
- else
- statement = "INSERT INTO receiver_status (id, date, time, detection_count, ping_count, line_voltage, battery_used, current, temperature, detection_memory, raw_memory, xyz_orientation) VALUES ('" +
+ string statement = "INSERT INTO receiver_status (id, date, time, detection_count, ping_count, line_voltage, battery_used, current, temperature, detection_memory, raw_memory, xyz_orientation) VALUES ('" +
receiver_model_id + "', '" + date + "', '" + time + "', " + dc + ", " + pc + ", " + lv + ", " + bc + ", " + bu + ", " + i + ", " + t + ", " + du + ", " + ru + ", '" + xyz + "');";
int response = doInsert(statement);
//dispatcher.enqueueEvent(new Databases.RealTimeEvents.DatabaseResponse(statement, response, status));
View
@@ -37,14 +37,14 @@ public Decoded Decode(UnparsedMessage unparsedMessage)
dynamic config = unparsedMessage["configuration"];
string messageType = getMessageType(message, config);
Match matches;
- foreach(string word in config.decoder[messageType].word_order)
+ 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);
+ payload.Add(word, "NULL");
}
return new Decoded(payload, unparsedMessage, message, messageType);
}
@@ -58,16 +58,16 @@ public Decoded Decode(UnparsedMessage unparsedMessage)
/// <returns>type of message</returns>
private string getMessageType(string unparsedMessage, dynamic config)
{
- foreach (dynamic sentence in config.decoder.sentences)
+ foreach (string sentence in config.decoder.sentences.Keys)
{
try
{
- List<String> wordExpansions = new List<String>();
- foreach(Object o in sentence.word_orders)
- {
- wordExpansions.Add(config.decoder.words[((String)o)]);
- }
- if(Regex.IsMatch(unparsedMessage, String.Format(sentence.format, wordExpansions)))
+ //List<String> wordExpansions = new List<String>();
+ //foreach(Object o in config.decoder.sentences[sentence].word_order)
+ //{
+ // wordExpansions.Add(config.decoder.words[((String)o)]);
+ //}
+ if(Regex.IsMatch(unparsedMessage, config.decoder.sentences[sentence].format))
{
return sentence;
}
@@ -24,7 +24,7 @@ static void Main(string[] args)
//testEncoder(encoder);
testDecoder(decoder);
- testDatabase(database);
+ //testDatabase(database);
return;
}
@@ -71,9 +71,12 @@ static void testDecoder(Decoder decoder)
static void printDecodedMessage(Decoded message)
{
insertions.Add(message);
- foreach (string key in message.Keys)
+ Console.WriteLine("---------------------------------------------");
+ Console.WriteLine(message["unparsedmessage"]);
+ Console.WriteLine("\tType is " + message["messagetype"]);
+ foreach (string key in message["decodedmessage"].Keys)
{
- Console.WriteLine(key + " -> " + message[key]);
+ Console.WriteLine('\t' + key + " -> " + message["decodedmessage"][key]);
}
}

0 comments on commit 1f56860

Please sign in to comment.