/// <summary> /// Construct message from bytestream. /// </summary> /// <returns>Returns null on failure.</returns> public static Message Deserialize(byte[] data) { eMessageType type = (eMessageType)data[0]; Message message; switch (type) { case eMessageType.LAYOUT: message = new LayoutMessage(); break; case eMessageType.DATA: message = new DataMessage(); break; case eMessageType.PATH: message = new PathMessage(); break; default: message = null; break; } bool isOk = false; if (message != null) { isOk = message.DeserializeSelf(data); } return(isOk ? message : null); }
/// <summary> /// Select which message IDs should be appended, if any. /// </summary> private void ProcessMessage(LayoutMessage msg) { lock (lockObject) { appendIdToPathMapping.Clear(); for (int i = 0; i < msg.Count; i++) { if (msg[i].AppendPathEnabled && !appendIdToPathMapping.ContainsKey(msg[i].Id)) { appendIdToPathMapping.Add(msg[i].Id, msg[i].AppendPathId); } } } }
/// <summary> /// Select which message IDs are to be set to the map. /// </summary> void ProcessMessage(LayoutMessage msg) { lock (lockObject) { activeIds.Clear(); for (int i = 0; i < msg.Count; i++) { if (msg[i].UpdateMap && msg[i].Dimension >= 2) { activeIds.Add(msg[i].Id); } } } }
/// <summary> /// Set layouts to data panel. /// </summary> private void ProcessMessage(LayoutMessage msg) { lock (lockObject) { if (target != null) { target.Invoke(new Action(() => { target.Count = msg.Count; idToIndexMapping.Clear(); for (int i = 0; i < msg.Count; i++) { target[i].Title = msg[i].Name; target[i].Count = msg[i].Dimension; for (int j = 0; j < msg[i].Dimension; j++) { target[i].Labels[j] = msg[i][j]; } idToIndexMapping.Add(msg[i].Id, i); } })); } } }
public static bool Test() { LayoutMessage layoutMsg = new LayoutMessage(); layoutMsg.Count = 3; layoutMsg[0].Name = "GPS"; layoutMsg[0].Id = 0; layoutMsg[0].AppendPathId = 1; layoutMsg[0].UpdateMap = true; layoutMsg[0].AppendPathEnabled = false; layoutMsg[0].Dimension = 3; layoutMsg[0][0] = "Latitude"; layoutMsg[0][1] = "Longitude"; layoutMsg[0][2] = "Altitude"; layoutMsg[1].Name = "Velocity"; layoutMsg[1].Id = 1; layoutMsg[1].AppendPathId = 16; layoutMsg[1].UpdateMap = true; layoutMsg[1].AppendPathEnabled = true; layoutMsg[1].Dimension = 3; layoutMsg[1][0] = "X"; layoutMsg[1][1] = "Y"; layoutMsg[1][2] = "Z"; layoutMsg[2].Name = "Temperature"; layoutMsg[2].Id = 2; layoutMsg[2].AppendPathId = 0; layoutMsg[2].UpdateMap = false; layoutMsg[2].AppendPathEnabled = true; layoutMsg[2].Dimension = 1; layoutMsg[2][0] = "Value"; byte[] layoutMsgBytes = layoutMsg.Serialize(); LayoutMessage layoutMsgRestored = (LayoutMessage)Message.Deserialize(layoutMsgBytes); PathMessage pathMsg = new PathMessage(); pathMsg.action = PathMessage.eAction.UPDATE_POINT; pathMsg.index = 5; pathMsg.path = 9; pathMsg.point = new GeoPoint(47.5, 19, 120); byte[] pathMsgBytes = pathMsg.Serialize(); PathMessage pathMsgRestore = (PathMessage)Message.Deserialize(pathMsgBytes); DataMessage dataMsg = new DataMessage(); dataMsg.Dimension = 3; dataMsg.Id = 12345; dataMsg[0] = 3.1415926f; dataMsg[1] = 2.7182818f; dataMsg[2] = 0.5772156f; byte[] dataMsgBytes = dataMsg.Serialize(); DataMessage dataMsgRestored = (DataMessage)Message.Deserialize(dataMsgBytes); return(true); }