static void Main(string[] args) { var jsonParser = new JsonParser() { CamelizeProperties = false }; dynamic config = jsonParser.Parse(System.IO.File.ReadAllText("config.txt")); Dispatcher dispatcher = new Dispatcher(); Database database = new Database(dispatcher, config); Decoder decoder = new Decoder(dispatcher); Receiver receiver = new Receiver("450052", "VR2C-69", dispatcher); Encoder encoder = new Encoder("*450052.0#16,", config); ConsoleLogger consoleLogger = new ConsoleLogger(dispatcher); dispatcher.addModule(database); dispatcher.addModule(decoder); dispatcher.addModule(consoleLogger); dispatcher.run(); testUnparsedMessages(dispatcher, receiver, config); //testEncoder(encoder); //testDecoder(decoder); //testDatabase(database); }
/// <summary> /// Public constructor for the Receiver class. /// </summary> /// <param name="serialPort">The serial port object to which the receiver is connected</param> /// <param name="portName">The name of the port (i.e. COM1, COM2, etc.)</param> /// <param name="dispatcher">The event queue dispatcher where events generated by this class are sent</param> /// <remarks> /// After opening the port, the constructor calls the init() method which determines whether the hardware connect /// is, in fact, a VEMCO reciever and then proceeds to configure it. After returning, the constructor then instructs /// the receiver to start sending "Real Time" data. Finally the run() method is called and the objects stays in /// the run method until it shutdown() is called. With the exception of whether the class in run()ing or not, no state /// is maintained by the class. /// </remarks> public Receiver(string serialNumber, string model, Dispatcher dispatcher) { VEMCO_SerialNumber = serialNumber; VEMCO_Model = model; Dictionary<int, string> configFiles = new Dictionary<int, string>(); this.TTL = DEFAULT_TTL; this.serialPort = serialPort; this.portName = portName; this.dispatcher = dispatcher; //serialPort.Open(); encoder = null; //init(); if (encoder != null) { //this.textReader = new StreamReader(serialPort.BaseStream, serialPort.Encoding); //Object[] r = {"0"}; //write("RTMPROFILE", r); //write("START"); //Thread.Sleep(500); //while (serialPort.BytesToRead > 0) //{ // dispatcher.enqueueEvent(new NoteReceiver("Read: " + serialPort.ReadExisting(), // this, this.portName, this.VEMCO_SerialNumber, this.VEMCO_Model, this.encoder.encoderConfig)); //} //run(); dispatcher.enqueueEvent(new NewReceiver(this, this.portName, this.VEMCO_SerialNumber, this.VEMCO_Model, this.encoder.encoderConfig)); } else { ReceiverExceptions re = new ReceiverExceptions(this, "(FATAL) Failed to configure encoder during init().", true); //dispatcher.enqueueEvent(new ExcepReceiver(re,re.fatal, // this, "test port name", this.VEMCO_SerialNumber, this.VEMCO_Model, this.encoder.encoderConfig)); //serialPort.Close(); //throw re; } }
/// <summary> /// The constructor for the Database module. /// </summary> /// <param name="dispatcher">The Dispatcher this object will receive messages from.</param> /// <param name="transmitters">The JSON file containing the sensor tag calibrations.</param> /// <param name="host">The host name of the database to connect to.</param> /// <param name="db">The name of the database to connect to.</param> /// <param name="user">The username of the database to connect to.</param> /// <param name="pass">The password for the user.</param> public Database(Dispatcher dispatcher, dynamic config, string host = "localhost", string db = "csulbsha_sharktopus", string user = "******", string pass = "******") : base(dispatcher) { this.config = config; if (config.database.use == "true") { host = config.database.host; db = config.database.name; user = config.database.user; pass = config.database.pass; } connectionString = "Server=" + host + ";Database=" + db + ";Uid=" + user + ";Pwd=" + pass + ";"; updateSensorCalibrations(config); insertions = new List<string>(); try { logWriter = new System.IO.StreamWriter(config.log_file, false); } catch (Exception e) { } }
static void testUnparsedMessages(Dispatcher dispatcher, Receiver receiver, dynamic config) { dispatcher.enqueueEvent(new UnparsedMessage("*450052.0#16[0099],2012-10-02 21:14:45,STS,DC=0,PC=0,LV=0.0,BV=3.2,BU=3.6,I=5.3,T=23.9,DU=0.0,RU=0.0,STORAGE,OK,#E3", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("*450052.0#16[0014],INVALID,#07", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("*450052.0#16[0009],OK,#9A", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("450052,000,2012-10-02 21:19:19,STS,DC=0,PC=0,LV=0.0,BV=3.2,BU=3.6,I=2.7,T=23.7,DU=0.0,RU=0.0,XYZ=-0.06:-0.22:0.94,#8C", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("450052,001,2012-10-02 21:20:01,A69-9001,30444,#B3", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("450052,032,2012-10-02 21:40:42,A69-1303,48823,#C5", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("450052,039,2012-10-02 21:42:17,A69-9001,30,444,#CA", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("*450052.0#16[0099],VR2C-69:450052,'VEMCO',MAP-113 [ 1105 1303 9001/9002 1420 1430 1601 1602 ],FW=0.0.25,HW=3,OK,#57", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("*450052.0#16[0125],2012-10-02 21:47:06,STS,DC=108,PC=1199,LV=0.0,BV=3.2,BU=3.6,I=5.3,T=23.1,DU=0.0,RU=0.1,XYZ=-0.06:-0.22:0.94,STOPPED,OK,#89", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("*450052.0#16[0053],232,SI=60,BL=U,BI=1,MA=U,FMT=SER SEQ UTC CS,OK,#8A", receiver, null, "450052", "VR2C-69", config)); dispatcher.enqueueEvent(new UnparsedMessage("this is some garbage", receiver, null, "450052", "VR2C-69", config)); }
/// <summary> /// Default constructor. /// </summary> public Decoder(Dispatcher dispatcher) : base(dispatcher) { }
public ConsoleLogger(Dispatcher dispatcher) : base(dispatcher) { }
public Module(Dispatcher dispatcher) { this.dispatcher = dispatcher; }
public ExceptionLogger(Dispatcher dispatcher) : base(dispatcher) { }