static void IdentificationResponseHandler(Packet packet) { if (packet.Ethernet.Destination.Equals(new MacAddress(_macSource1))) { string macsource = packet.Ethernet.Source.ToString(); string content = packet.Buffer.ByteArrayToHex(); try { var dcppacket = new DcpPacket(content); if (dcppacket._xid.Equals(TRANSACT_ID)) { // Matching ID and matching dest. var response = new Response() { mac = macsource, dcpPacket = dcppacket }; int index = _collectedResponses.FindIndex(x => x.mac.Equals(macsource)); if (index >= 0) { _collectedResponses[index] = response; } else { _collectedResponses.Add(response); } } } catch { } PrintAllResponses(); } }
static void SendIdentificationRequest() { var dcppacket = new DcpPacket(); dcppacket.MakeIdentificationRequest(); Send(_macMulticast, dcppacket.Build()); }
static void SendSetRequest(string mac, string option, string contentHex) { var dcpdata = new DcpData(option, contentHex); var dcppacket = new DcpPacket(); dcppacket.MakeSetRequest(dcpdata.Build()); var hex = dcppacket.Build(); Send(mac, hex); }
static void DefaultPacketHandler(Packet packet) { if (packet.Ethernet.Destination.Equals(new MacAddress(_macSource1))) { string macsource = packet.Ethernet.Source.ToString(); string content = packet.Buffer.ByteArrayToHex(); HighlightConsole(true, 2); try { var dcppacket = new DcpPacket(content); if (dcppacket._xid.Equals(TRANSACT_ID)) { Console.WriteLine(packet.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff") + " matching xid to us, length:" + packet.Length); if (dcppacket._serviceType.EndsWith("01")) { HighlightConsole("dcp - success"); } else { Console.WriteLine(dcppacket._serviceType); } // Matching ID and matching dest. Console.WriteLine(packet.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff") + " matching xid to us, length:" + packet.Length); foreach (var dcpdata in dcppacket.GetDcpDataPackages()) { if (dcpdata._statusHex == "00") { HighlightConsole("block - ok"); } else { Console.WriteLine(dcpdata._statusHex); } } } } catch (Exception ex) { LowlightConsole(ex.Message); } Console.WriteLine(""); HighlightConsole(false); } }