static AnsCmd createAnsCmd() { AnsCmd ans = new AnsCmd(RESOURCE.TLM, Operation.AN); ans.Header.Address = 2; ans.Header.Dest = 1; ans.Header.TimeStamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; ans.Telemetria = createTelemetriaData(); return(ans); }
/* * * Decodifica uma resposta completa cabeçalho+payload * */ public bool decode(out AnsCmd ans, CommunicationFrame frame) { bool ret = false; ans = new AnsCmd(); string[] list = frame.Data.Split(CONST_CHAR.SEPARATOR); if (list != null && list.Length >= 8) { // Exclui CheckSum frame.Data = frame.Data.Substring(0, frame.Data.Length - 2); byte cheksumRx = (byte)Convert.ToInt16(list[list.Length - 1], 16); if (frame.checkSum() == cheksumRx) { ans.Header = decoderHeader(list); if (ans.Header.Resource.Equals(RESOURCE.TLM) && ans.Header.Operation.Equals(Operation.AN) && list.Length >= 9) { ans.Telemetria = decoderTLM(list); ret = true; } else if (ans.Header.Resource.Equals(RESOURCE.LCK) && ans.Header.Operation.Equals(Operation.AN) && list.Length >= 8) { ret = true; } else { ret = false; throw new Exception("Payload(Resource =" + ans.Header.Resource + ") não reconhecido"); } } else { ret = false; throw new Exception("Erro de CheckSum"); } } else { ret = false; throw new ArgumentException("Error ao fazer o split do payload: " + frame.Data, "frame"); } return(ret); }
internal void encode(AnsCmd ans) { PayLoad pl; if (ans.Header.Resource.Equals(RESOURCE.TLM)) { serialization.encode(out pl, ans.Telemetria); } else { pl = new PayLoad(); } Header = ans.Header; PayLoad = pl; }
static void publishAnswer() { Communic communic = GTracker.Communic; if (communic != null && TrackerController.TrackerCtrl.anyRoute() && TrackerController.TrackerCtrl.Routes[0].MapRoute.Points.Count > count_publish) { if (Communication.isAnyTxCmd() && !Communication.isAnyAns() && Communication.TxCmds.ContainsKey(RESOURCE.TLM)) { AnsCmd ans = createAnsCmd(); if (ans != null) { communic.send(createAnsCmd()); } } } }
protected abstract void onReceiveAnswer(AnsCmd ans);
protected override void onReceiveAnswer(AnsCmd ans) { throw new NotImplementedException(); }