void agent_DataArrived(object sender, ProtocalParseEventArg e) { switch (e.Data.TypeName) { case CPBProtolType.Power: PowerFrameType frame = (PowerFrameType)e.Data.Content; ShowMessageforView(string.Format("{0} :", e.Data.IPAddress)); ShowMessageforView(frame.PowerGroup + " " + frame.Status.ToString() + " " + frame.DayTime + " " + frame.StartTime + " " + frame.Duration + "\n"); break; } }
private void ProcessProtocal(string ipAddress, string frame) { string tag = frame.Substring(0, 1); if (tag.Equals("8")) { string[] strArray = frame.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length == 5) { PowerFrameType group = new PowerFrameType(); group.PowerGroup = strArray[0].Substring(strArray[0].Length - 2, 2); group.Status = strArray[1].Equals("ON") ? true : false; group.DayTime = strArray[2]; group.StartTime = strArray[3]; group.Duration = strArray[4]; DataArrived(this, new ProtocalParseEventArg(new cpbProtocalDataCls(CPBProtolType.Power, ipAddress, group))); } } // end of get power // get time if (tag.Equals("1")) { string dateStr = frame.Substring(6, frame.Length - 6); DataArrived(this, new ProtocalParseEventArg(new cpbProtocalDataCls(CPBProtolType.Date, ipAddress, dateStr))); } // get temp if (tag.Equals("0")) { string tempStr = frame.Substring(frame.Length - 4, 4); DataArrived(this, new ProtocalParseEventArg(new cpbProtocalDataCls(CPBProtolType.Temp, ipAddress, tempStr))); } // get valotage if (tag.Equals("6")) { string volStr = frame.Substring(frame.Length - 4, 4); DataArrived(this, new ProtocalParseEventArg(new cpbProtocalDataCls(CPBProtolType.Valtage, ipAddress, volStr))); } // get version if (tag.Equals("5")) { string verStr = frame.Substring(frame.Length - 5, 5); DataArrived(this, new ProtocalParseEventArg(new cpbProtocalDataCls(CPBProtolType.Version, ipAddress, verStr))); } //get gps error if (tag.Equals("3")) { DataArrived(this, new ProtocalParseEventArg(new cpbProtocalDataCls(CPBProtolType.GPSErr, ipAddress, "Error"))); } //get gps UTC if (tag.Equals("2") || frame.StartsWith("utcerror")) { string gpsDateStr = frame.Substring(5, frame.Length - 5); DataArrived(this, new ProtocalParseEventArg(new cpbProtocalDataCls(CPBProtolType.GPSTime, ipAddress, gpsDateStr))); } }