public POCT() { _decoder = new POCTDecoderA(); string strHELR01 = Helpers.GetStringFromFile(@"CategoryA\SampleMessages\POCT_HELR01.xml"); string strOBSR01 = Helpers.GetStringFromFile(@"CategoryA\SampleMessages\POCT_OBSR01.xml"); OBSR01 _obsr01 = Serialization.DeserializeObject <OBSR01>(strOBSR01); Service _svc = _obsr01.services[0]; _message = new POCTMessage { svc = _svc, helr01 = strHELR01 }; _deviceMessage = new DeviceMessage { ClientId = ClientId, DeviceCategory = "A", SendingFacility = SendingFacility, MessageType = "POCT", ContentsList = new List <string> { strOBSR01, strHELR01 } }; _processor = new POCTMessageProcessor(_decoder); }
private static async Task SendMessage(Device device) { // simulate the device moving device.Speed += rand.NextDouble(-0.0001, 0.0001); device.Direction += rand.NextDouble(-0.001, 0.001); var lastLat = device.Lat; var lastLon = device.Lon; UpdateDevicePosition(device); if (lastLat == device.Lat || lastLon == device.Lon) { // the device has hit the boundary, so reverse it's direction device.Speed = -device.Speed; UpdateDevicePosition(device); } // send the message to WebAPI DeviceMessage message = new DeviceMessage(device.Lat, device.Lon, counter, device.DeviceId, DateTime.UtcNow); HttpClient webAPIClient = new HttpClient(); HttpResponseMessage responseMessage = await webAPIClient.PostAsJsonAsync <DeviceMessage>(baseURL, message); Interlocked.Increment(ref counter); }
public List <PatientDiagnosticRecord> ProcessMessage(DeviceMessage deviceMessage) { List <PatientDiagnosticRecord> records = new List <PatientDiagnosticRecord>(); try { string strOBSR01 = deviceMessage.ContentsList[0]; string strHELR01 = deviceMessage.ContentsList[1]; OBSR01 _obsr01 = Serialization.DeserializeObject <OBSR01>(strOBSR01); Service[] services = _obsr01.services; List <Service> lstService = services.OfType <Service>().ToList(); foreach (Service svc in lstService) { POCTMessage message = new POCTMessage { svc = svc, helr01 = strHELR01 }; records = Helpers.GetPatientDiagnosticRecords <POCTMessage>( _messageDecoder, message, deviceMessage); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(records); }
public IHttpActionResult DeviceLocation([FromBody] DeviceMessage deviceMessage) { string message = string.Empty; TrackingCollection.Instance.DeviceLocation(deviceMessage); return(Ok(new { Constants.WebApiStatusOk, data = true })); }
public Task ProcessMessage([FromBody] DeviceMessage message) { // send the message to Orleans var deviceGrain = DeviceGrainFactory.GetGrain(message.DeviceId); return(deviceGrain.ProcessMessage(message)); }
public void WriteToRobot(DeviceMessage msg) { if (ConnectionState == ConnectionState.Connected) { _session.WriteToRobot(msg); } }
static void Main(string[] args) { //var l = new LocationDetails(); //l.fix = '0'; //l.UnitId = 212; //l.loc= "123.152,158.0"; //l.speed = 789; //l.sat = 454; //l.alt = 2342; //l.msgid = 12; //l.odo = 53; //l.deviceDatetime = DateTime.Now; //TrackingCollection.Instance.Init(6000); //TrackingCollection.Instance.LocationDetailSubmit(l); //var t= new Random(6).Next(); string[] string_array = Array.ConvertAll(new decimal[] { 2324.53m, 2323.23m }, x => x.ToString()); var str = string.Join(",", new decimal[] { 2324.53m, 2323.23m }); //var str = string.Join(",", string_array); DeviceMessage dm = new DeviceMessage(); dm.gps.loc = new decimal[] { 2324.53m, 2323.23m }; dm.dbg.status = new int[] { 2, 55, 34, 6 }; var result = JsonConvert.SerializeObject(dm); Console.ReadKey(); }
internal async Task <List <RequestResponse> > SendDeviceUpdate(Dictionary <string, IDevice> devices, bool store = false) { var responses = new List <RequestResponse>(); foreach (var device in devices.Values) { IHttpRequestMessage message; var deviceMessage = device.GetDeviceMessage(); if (deviceMessage == null) { continue; } if (store) { message = new DeviceMessage(device, deviceMessage); } else { message = new DeviceUpdateMessage(device, deviceMessage); } responses.Add(new RequestResponse(device, await client.Request(message))); } return(responses); }
public void UpdateResourceFile() { using (var stream = File.OpenRead(@"C:\temp\idle-screen.zip")) { int count, offset = 0; byte[] buffer = new byte[3000]; while ((count = stream.Read(buffer, 0, buffer.Length)) != 0) { string data = Convert.ToBase64String(buffer).Trim(); DeviceMessage message = TerminalUtilities.BuildRequest( "A18", offset, ControlCodes.FS, data, ControlCodes.FS, ((offset + count) == stream.Length) ? "0" : "1" ); var response = device.SendCustomMessage(message); Assert.IsNotNull(response); Assert.IsTrue(response.Contains("OK")); offset += count; } } }
public void SetSafParams() { DeviceMessage message = TerminalUtilities.BuildRequest( "A54", "1", ControlCodes.FS, // start date, ControlCodes.FS, // end date, ControlCodes.FS, // duration in days, ControlCodes.FS, // max number, ControlCodes.FS, "500", // total ceiling, ControlCodes.FS, // ceiling per card brand, ControlCodes.FS, "100", // halo per card type, ControlCodes.FS, // upload mode, ControlCodes.FS, // auto upload interval time, ControlCodes.FS // delete SAF confirmation ); var response = device.SendCustomMessage(message); Assert.IsNotNull(response); }
public async Task <ActionResult <string> > ReceiveRequest(DeviceMessage message, [FromServices] DaprClient daprClient)// [FromBody]DeviceMessage message, [FromServices] DaprClient daprClient) { _logger.LogInformation("Enter receive request messages"); // var deviceMessage = JsonConvert.DeserializeObject<DeviceMessage>(message.Data.ToString()); if (message != null) { _logger.LogInformation("Received device message:" + message.ToString()); if (message.Name != null) { _logger.LogInformation("Message from:" + message.Name.ToString()); } if (message.Id != null) { _logger.LogInformation("Message id:" + message.Id.ToString()); } if (message.Message != null) { _logger.LogInformation("Message says:" + message.Message.ToString()); } } return(Ok("Thanks")); }
internal static Task <ButtplugFFIServerMessage> SendVibrateCmd(ButtplugFFIMessageSorter aSorter, ButtplugFFIDeviceHandle aHandle, uint aDeviceIndex, Dictionary <uint, double> aSpeeds, ButtplugCallback aCallback, IntPtr aCallbackCtx) { var command_list = new List <DeviceMessage.Types.VibrateComponent>(); foreach (var pair in aSpeeds) { command_list.Add(new DeviceMessage.Types.VibrateComponent { Index = pair.Key, Speed = pair.Value, }); } var cmd = new DeviceMessage.Types.VibrateCmd(); cmd.Speeds.Add(command_list); var msg = new DeviceMessage { Index = aDeviceIndex, Message = new DeviceMessage.Types.FFIMessage { VibrateCmd = cmd } }; return(SendDeviceMessage(aSorter, aHandle, msg, aCallback, aCallbackCtx)); }
private void OnMenuFile_Open(object sender, EventArgs e) { OpenFileDialog sFD = new OpenFileDialog(); sFD.Title = "保存文件"; sFD.ShowHelp = true; sFD.Filter = "工程文件(*.cfg)|*.cfg"; //过滤格式 sFD.FilterIndex = 1; //格式索引 sFD.RestoreDirectory = false; sFD.InitialDirectory = "c:\\"; //默认路径 if (sFD.ShowDialog() == DialogResult.OK) { string filePath = sFD.FileName; List <DeviceForXml> list = ReadXml(filePath); foreach (DeviceForXml item in list) { DeviceMessage devMsg = item.devMsg; Device429 device = new Device429(); device.BoardNo = devMsg.BoardNo; device.BoardType = devMsg.BoardType; device.ChannelCount = devMsg.ChannelCount; device.ChannelType = devMsg.ChannelType; device.DevID = devMsg.DevID; device.filterStr = devMsg.filter; TopMenuVM topMenuVM = new TopMenuVM(device); topMenuVM.OpenSetting();//将xml初始化设备及软件 } } }
public async Task <ActionResult <string> > ReceiveRequest(DeviceMessage message, [FromServices] DaprClient daprClient)// [FromBody]DeviceMessage message, [FromServices] DaprClient daprClient) { _logger.LogInformation("Enter receive request messages"); // var deviceMessage = JsonConvert.DeserializeObject<DeviceMessage>(message.Data.ToString()); if (message != null) { _logger.LogInformation("Received device message:" + message.ToString()); if (message.Name != null) { _logger.LogInformation("Message from:" + message.Name.ToString()); } if (message.Id != null) { _logger.LogInformation("Message id:" + message.Id.ToString()); } if (message.Message != null) { _logger.LogInformation("Message says:" + message.Message.ToString()); try{ await daprClient.InvokeMethodAsync <DeviceMessage>("message-receiver", "receiverequest", message); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(BadRequest()); } } } return(Ok(message.Id)); }
public async Task <ActionResult <string> > ReceiveDeviceMessages([FromBody] DeviceMessage message, [FromServices] DaprClient daprClient)// [FromBody]DeviceMessage message, [FromServices] DaprClient daprClient) { _logger.LogInformation("Enter receive new device messages"); // var deviceMessage = JsonConvert.DeserializeObject<DeviceMessage>(message.Data.ToString()); if (message != null) { _logger.LogInformation("Received device message:" + message.ToString()); if (message.Name != null) { _logger.LogInformation("Message from:" + message.Name.ToString()); } if (message.Id != null) { _logger.LogInformation("Message id:" + message.Id.ToString()); } if (message.Message != null) { _logger.LogInformation("Message says:" + message.Message.ToString()); try{ await daprClient.PublishEventAsync <DeviceMessage>("dzpubsub", "important", message); _logger.LogInformation("Message has been published to important topic:" + message.Message.ToString()); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(BadRequest()); } } } return(Ok(message.Id)); }
public void SendCustomResetMessage() { DeviceMessage message = TerminalUtilities.BuildRequest("<SIP><Version>1.0</Version><ECRId>1004</ECRId><Request>Reset</Request></SIP>", MessageFormat.HeartSIP); var response = device.SendCustomMessage(message); Assert.IsNotNull(response); }
static void Main(string[] args) { Console.WriteLine("************************************************************"); Console.WriteLine("* B I O M A X S E N S O R E V E N T G E N E R A T O R *"); Console.WriteLine("************************************************************"); Console.WriteLine(); Console.WriteLine("Press Enter to start the generator."); Console.WriteLine("Press Ctrl-C to stop the generator."); Console.WriteLine(); Console.ReadLine(); Console.Write("Working...."); _configM = new ConfigM(); _registryM = new DeviceM(); _profilesM = new ProfileM(); // the endpoiont for ConfigM is defined in the app config _configM.ApiUrl = ConfigurationManager.AppSettings["ConfigM"]; var deviceManifest = _configM.GetByName("DeviceM"); var profileManifest = _configM.GetByName("ProfileM"); _registryM.ApiUrl = deviceManifest.lineitems[LineitemsKey.AdminAPI]; _profilesM.ApiUrl = profileManifest.lineitems[LineitemsKey.PublicAPI]; // get the device registry from the device microservice _devices = _registryM.GetAll(); // get all the participants in the study _profiles = _profilesM.GetAllByType("Participant"); var random = new Random(); var spin = new ConsoleSpiner(); // connect to Event Hub var servicebus = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"]; var eventhub = ConfigurationManager.AppSettings["EventHub"]; var eventHubClient = EventHubClient.CreateFromConnectionString(servicebus, eventhub); while (true) { spin.Turn(); try { var deviceReading = new DeviceMessage(); var index = random.Next(0, _devices.list.Count - 1); // randomly select a device from the registry var device = _devices.list[index]; // lookup the participant var participant = _profiles.Find(p => p.id == device.participantid); // beging to create the simulated device message deviceReading.deviceid = device.id; deviceReading.participantid = participant.id; deviceReading.location.latitude = participant.location.latitude; deviceReading.location.longitude = participant.location.longitude; // generate simulated sensor reaings var glucose = new SensorReading { type = SensorType.Glucose, value = random.Next(70, 210) }; var heartrate = new SensorReading { type = SensorType.Heartrate, value = random.Next(60, 180) }; var temperature = new SensorReading { type = SensorType.Temperature, value = random.Next(98, 105) + (.1 * random.Next(0, 9)) }; var bloodoxygen = new SensorReading { type = SensorType.Bloodoxygen, value = random.Next(80, 100) }; deviceReading.sensors.Add(glucose); deviceReading.sensors.Add(heartrate); deviceReading.sensors.Add(temperature); deviceReading.sensors.Add(bloodoxygen); deviceReading.reading = DateTime.Now; // serialize the message to JSON var json = ModelManager.ModelToJson<DeviceMessage>(deviceReading); // use these lines to gen JSON files for SA test input //var filename = AppDomain.CurrentDomain.BaseDirectory + @"\data\device-" + DateTime.Now.Ticks + ".json"; //System.IO.File.WriteAllText(filename, json); // send the message to EventHub eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(json))); } catch (Exception exception) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("{0} > Exception: {1}", DateTime.Now, exception.Message); Console.ResetColor(); } Thread.Sleep(200); } }
public void sendMsg(BaseDevice device, String s) { DeviceMessage msg = new DeviceMessage(); msg.Device = device; msg.Msg = s; msg.Type = DeviceMessage.DeviceMessageType.OUT; msg.Time = DateTime.Now.ToShortTimeString(); lock (allMessages) { allMessages.Add(msg); } }
private static async void SendDeviceToCloudMessagesAsync() { var random = new Random(); var spin = new ConsoleSpiner(); while (true) { spin.Turn(); try { var deviceReading = new DeviceMessage(); var index = random.Next(0, _devices.list.Count - 1); // randomly select a device from the registry var device = _devices.list[index]; // lookup the participant associated with this device var participant = _profiles.Find(p => p.id == device.participantid); // create an IoT Hub client for this device if necessary if (DeviceClients[index] == null) { // connect to the IoT Hub using unique device registration settings (deviceid, devicekey) var deviceid = device.model + "-" + device.id; DeviceClients[index] = DeviceClient.Create( ConfigurationManager.AppSettings["IoTHubUri"], new DeviceAuthenticationWithRegistrySymmetricKey(deviceid, device.key)); } // begin to create the simulated device message deviceReading.deviceid = device.id; deviceReading.participantid = participant.id; deviceReading.location.latitude = participant.location.latitude; deviceReading.location.longitude = participant.location.longitude; // generate simulated sensor reaings var glucose = new SensorReading { type = SensorType.Glucose, value = random.Next(70, 210) }; var heartrate = new SensorReading { type = SensorType.Heartrate, value = random.Next(60, 180) }; var temperature = new SensorReading { type = SensorType.Temperature, value = random.Next(98, 105) + (.1 * random.Next(0, 9)) }; var bloodoxygen = new SensorReading { type = SensorType.Bloodoxygen, value = random.Next(80, 100) }; deviceReading.sensors.Add(glucose); deviceReading.sensors.Add(heartrate); deviceReading.sensors.Add(temperature); deviceReading.sensors.Add(bloodoxygen); deviceReading.reading = DateTime.Now; // serialize the message to JSON var json = ModelManager.ModelToJson<DeviceMessage>(deviceReading); // send the message to EventHub DeviceClients[index].SendEventAsync(new Message(Encoding.ASCII.GetBytes(json))).Wait(); } catch (Exception exception) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("{0} > Exception: {1}", DateTime.Now, exception.Message); Console.ResetColor(); } Thread.Sleep(1000); } }