static void OnSensorDataPacketReceived(SensorDataPacket packet) { ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads; Console.WriteLine("Thread count: " + currentThreads.Count); string mood = string.Empty; if (packet.Temperature > 30) { mood = "super hot"; } else if (packet.Temperature > 15) { mood = "warm"; } else if (packet.Temperature > 0) { mood = "cold"; } else if (packet.Temperature <= 0) { mood = "freezing"; } Console.Out.WriteLine("It's a {0} day at the clients site, temperature is {1}°C", mood, packet.Temperature); }
public void OnDataAvailable(SensorDataPacket packet) { HandleTimeout(); if (IsCancelled) { return; } if (packet.DataType != SensorDataType.Video) { // only video data supported return; } var frame = packet.GenericData as VideoFrame; if (frame == null) { // unsupported content return; } // generate a base64 string from the video frame string imageString = string.Empty; if (includeImage) { imageString = CompressImage(frame); } // craete a message that contains the compressed image // and send it through the consumer to the client var message = new JsonString(messageTemplate); var subject = JsonString.CreateDict(); { subject.AddTerminal("type", JsonString.StringifyString("post")); subject.AddTerminal("topic", JsonString.StringifyString("sensorCapture")); subject.AddTerminal("position", JsonString.Stringify(sensorIndex)); var dataArray = JsonString.CreateArray(); { var dataEntry = JsonString.CreateDict(); { if (includeImage && imageString.Length > 2) { dataEntry.AddTerminal("image", imageString); } dataEntry.AddTerminal("frameWidth", JsonString.Stringify(frame.Width)); dataEntry.AddTerminal("frameHeight", JsonString.Stringify(frame.Height)); var metadata = frame.Metadata; dataEntry.AddTerminal("frameRate", JsonString.Stringify(metadata.FrameRate)); dataEntry.AddTerminal("frameTime", JsonString.Stringify(metadata.FrameTime)); dataEntry.AddTerminal("frameTimeDeviation", JsonString.Stringify(metadata.FrameTimeDeviation)); } dataArray.AddJsonString(string.Empty, dataEntry); } subject.AddJsonString("data", dataArray); } message.AddJsonString("subject", subject); string str = message.ToJsonString(); consumer.EnqueueMessage(message); }
public static IPacket Decode(short opcode, byte[] data) { IPacket packet = null; switch (opcode) { case (short)PacketCode.SensorData: packet = new SensorDataPacket(); break; default: packet = new UnknownPacket(); break; } packet.FromBytes(data); return(packet); }