// given a packet body only (no checksum), packs it // and sends. public override void Send(string packetBodyOut) { string strToSend = packetBodyOut + NmeaPacket.checksum(packetBodyOut); logPacket("sending packet=" + strToSend); base.Send(strToSend); if (m_handshake) { try { string csResponse = base.Receive(); log(String.Format("received handshake response: {0}", csResponse)); // watch for "UNABLE" responses, indicating invalid route linkage (0 length leg) etc: if (csResponse.StartsWith("$PMGNCMD,UNABLE")) { m_errorCount++; } } catch (CommPortException e) { logError("exception waiting for handshake response: " + e.Message); base.Open(); } } }
public void Receive(MPacketReceived packetIn) { packetIn.isGood = false; int tries = 0; while (!packetIn.isGood && tries++ <= 3) { //log("Receive() - waiting... try " + tries); packetIn.m_string = base.Receive(); //log("received: " + packetIn.m_string); if (packetIn.m_string.StartsWith("$PMGNCSM")) { log("received astray CSM: " + packetIn.m_string); tries--; continue; } if (m_handshake) { string cs = NmeaPacket.checksumReceived(packetIn.m_string); MPacketCsm packet = new MPacketCsm(cs); string str = packet.ToString() + NmeaPacket.checksum(packet.ToString()); log("sending handshake response: " + str); base.Send(str); } if (!NmeaPacket.checksumVerify(packetIn.m_string)) { packetIn.isGood = false; if (m_handshake) { logError("bad checksum, waiting for resent packet"); } else { logError("bad checksum, returning bad packet"); break; // just report the received package, isGood = false } } else { packetIn.isGood = packetIn.basicParse(packetIn.m_string); // packet is good and parsed, so the fields array is filled } } logPacket("received " + (packetIn.isGood?"good":"bad") + " packet=" + packetIn); }