public override void Execute() { try { // basic test, interrogate router for Routing Table, check the Port IDs BACnetUtil.SendInitRoutingTable(_apm, _bnm, new DADR(devicTreeNode.device.adr)); BACnetPacket incomingPkt = waitForPacket(5000, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE_ACK); foreach (RoutingTableEntry rte in incomingPkt.routerTableList) { if (rte.portID == 0) { // fails //Console.WriteLine("Illegal Port ID " + rte.ToString()); // Need to mark diagnostic as failed, with a comment MarkDiagnosticFailed("Port ID found to be out of range: " + rte.ToString()); return; } } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } MarkDiagnosticSuccess(); }
public override void Execute() { _apm.MessageLog("Executing " + diagnosticName); bool foundFlag = false; try { BACnetPacket resp; BACnetPacket pkt = new BACnetPacket(this._apm); pkt.EncodeNPCI(new DADR(), BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); pkt.EncodeContextTag(0, (int)devicTreeNode.device.deviceObjectID.objectInstance); pkt.EncodeContextTag(1, (int)devicTreeNode.device.deviceObjectID.objectInstance); BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); // wait for _our_ device to respond do { try { // We expect to timeout resp = waitForPacket(5000, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM); if (resp.srcDevice.deviceObjectID.Equals(devicTreeNode.device.deviceObjectID)) { foundFlag = true; } else { Sleep(5000); ClearIncomingPacketQueue(); MarkDiagnosticFailed(); return; } } catch (TimeoutException) { // remember we expect to time out if (foundFlag == true) { MarkDiagnosticSuccess(); return; } else { MarkDiagnosticFailed(); return; } } }while (true); } catch (Exception ex) { // other types of exception... _apm.MessagePanic(ex.ToString()); return; } }
public override void Execute() { try { ClearIncomingPacketQueue(); BACnetPacket pkt = new BACnetPacket(_apm, BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); pkt.dAdr = new DADR(this.device.adr); pkt.EncodeNPCI(pkt.dAdr, BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); // Encode the rest of the packet according to http://www.bacnetwiki.com/wiki/index.php?title=Read_Property pkt.EncodeContextTag(0, this.device.deviceObjectID); pkt.EncodeContextTag(1, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE); pkt.EncodeContextTag(1, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_IDENTIFIER); BACnetUtil.SendOffPacket(this._apm, this._bnm, pkt, pkt.buffer, pkt.optr); BACnetPacket respPkt = waitForPacket(5000); // Since we made a deliberate mistake with our request, we expect a reject PDU. Make sure we get it if (respPkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_REJECT) { if (respPkt.pduRejectReason == BACnetEnums.BACNET_BACNET_REJECT_REASON.REJECT_REASON_TOO_MANY_ARGUMENTS || respPkt.pduRejectReason == BACnetEnums.BACNET_BACNET_REJECT_REASON.REJECT_REASON_INVALID_TAG) { MarkDiagnosticSuccess(); return; } else { MarkDiagnosticFailed("Reject PDU OK, but reason not OK"); return; } } else { MarkDiagnosticFailed("Reject PDU expected"); return; } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; //BACnetLibrary.Panic(ex.ToString()); //return; } }
public override void Execute() { try { ClearIncomingPacketQueue(); BACnetPacket pkt = new BACnetPacket(_apm, BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); pkt.dAdr = new DADR(this.device.adr); pkt.EncodeNPCI(pkt.dAdr, BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); // Encode the rest of the packet according to http://www.bacnetwiki.com/wiki/index.php?title=Read_Property pkt.EncodeContextTag(0, this.device.deviceObjectID); pkt.EncodeContextTag(1, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE); // Now, by definition, there can only be one device instance. Try and read the 3rd. If the device responds with anything but an error, it fails pkt.EncodeContextTag(2, 3); BACnetUtil.SendOffPacket(this._apm, this._bnm, pkt, pkt.buffer, pkt.optr); BACnetPacket respPkt = waitForPacket(5000); // Since we made a deliberate mistake with our request, we expect a reject PDU. Make sure we get it if (respPkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_ERROR) { if (respPkt.errorClass == (int)BACnetEnums.BACNET_ERROR_CLASS.ERROR_CLASS_PROPERTY && respPkt.errorCode == (int)BACnetEnums.BACNET_ERROR_CODE.ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY) { MarkDiagnosticSuccess(); return; } else { MarkDiagnosticFailed("Error PDU OK, but error class or error code not OK"); return; } } else { MarkDiagnosticFailed("Error PDU expected"); return; } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; } }
public override void Execute() { try { _apm.MessageLog("Executing " + diagnosticName); ClearIncomingPacketQueue(); // find a non-existing network number in the whole attached BACnet internetwork by examining our internal router table that // has been built up during device discovery phase int useThisNetworkNumber = 9; for (int i = 0xfffe; i > 1; i--) { if (_apm.internalRouterInfo.FindRoutingTableEntry(i) == null) { // we have not seen or used this network number yet useThisNetworkNumber = i; break; } } // BACnetUtil.SendReadProperty(_apm, _bnm, deviceNode.device, deviceNode.device.deviceObjectID, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE); BACnetPacket pkt = new BACnetPacket(_apm); // pkt.EncodeBVLL(new DADR(deviceNode.device.adr), BACnetEnums.BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_UNICAST_NPDU); pkt.EncodeNPCI(new DADR(devicTreeNode.device.adr), new ADR((ushort)useThisNetworkNumber, (uint)3), BACnetLibrary.BACnetPacket.MESSAGE_TYPE.APPLICATION); // todonow, put these next steps into functions // build confirmed request header // http://www.bacnetwiki.com/wiki/index.php?title=BACnet-Confirmed-Request-PDU pkt.buffer[pkt.optr++] = (Byte)BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST; pkt.buffer[pkt.optr++] = 0x05; // max segs, max resp. todo pkt.buffer[pkt.optr++] = _apm.invokeID++; // sequence number may come next, dep on flags. todo pkt.buffer[pkt.optr++] = (byte)BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY; // context encoding // http://www.bacnetwiki.com/wiki/index.php?title=Read_Property devicTreeNode.device.deviceObjectID.Encode(pkt.buffer, ref pkt.optr); BACnetUtil.EncodeContextTag(pkt.buffer, ref pkt.optr, 1, (int)BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE); BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); BACnetPacket respPkt = waitForPacket(5000); } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; } MarkDiagnosticSuccess(); }
private void buttonWhoIsLongMAC_Click(object sender, EventArgs e) { // BTL Implementation Guide, Section 2.9 - be prepared to accept a MAC address up to 18 bytes long. Here is the test. I have not found any device that passes this yet. BACnetPacket pkt = new BACnetPacket(_apm); pkt.EncodeBVLL(BACnetEnums.BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_BROADCAST_NPDU); pkt.EncodeNPCI(new DADR(BACnetPacket.ADDRESS_TYPE.GLOBAL_BROADCAST), new ADR(3333, "0102030405060708"), BACnetLibrary.BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); }
private void timerUpdateUItick(object sender, EventArgs e) { if (_apm.DiagnosticLogProtocol.Count > 0) { textBoxProtocol.AppendText(DateTime.Now.ToString("MM/dd HH:mm:ss - ") + _apm.DiagnosticLogProtocol.myDequeue()); tabPageProtocol.Text = "Protocol *"; } if (_apm.DiagnosticLogPanic.Count > 0) { textBoxPanics.BackColor = Color.Pink; textBoxPanics.AppendText(DateTime.Now.ToString("MM/dd HH:mm:ss - ") + _apm.DiagnosticLogPanic.myDequeue()); tabControlLogs.SelectTab(tabPageErrors); tabPageErrors.Text = "Errors *"; } while (_bnm.newPacketQueue.Count != 0) { BACnetPacket p = _bnm.newPacketQueue.myDequeue(); try { _apm.treeViewUpdater.UpdateDeviceTreeView(_bnm, p); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } // now go through and update all the 'lastheardfrom' times - only once per second to avoid flicker, etc. if (_stopWatch.ElapsedMilliseconds > _lastUpdatedTreeView + 1000) { _lastUpdatedTreeView = _stopWatch.ElapsedMilliseconds; foreach (myTreeNode mtnNet in _apm.treeViewUpdater.TreeViewOnUI.Nodes) { // each network node has device subnodes foreach (myTreeNode mtnDev in mtnNet.Nodes) { //mtnDev.Nodes[0].Text = "Seconds since msg " + ((_stopWatch.ElapsedMilliseconds - mtnDev.lastHeardFromTime) / 1000).ToString(); // remove node if gone for too long. (5 days) if (_stopWatch.ElapsedMilliseconds - mtnDev.lastHeardFromTime > 5 * 24 * 60 * 60 * 1000) { mtnDev.Remove(); } } } } }
public override void Execute() { bool someFails = false; WaitForQuietOnIncomingPacketQueue(); ClearIncomingPacketQueue(); try { if (this.devicTreeNode.device.adr.directlyConnected == true) { MarkDiagnosticWithNote("This node is directly connected. Diagnostic not appropriate"); return; } // todo. the ADR constructor is going to use an IP broadcast. We should know the router for this device and transmit the packet only to that router... DADR dadr = new DADR(_bnm, BACnetPacket.ADDRESS_TYPE.REMOTE_BROADCAST, this.devicTreeNode.device.adr.networkNumber); BACnetUtil.SendWhoIs(_apm, _bnm, dadr); WaitForQuietOnIncomingPacketQueue(); // check the incoming packets, make sure that they are all from the desired address if (_apm.pktQueueToApplication.Count == 0) { MarkDiagnosticFailed("No response to the Who-Is"); return; } while (_apm.pktQueueToApplication.Count > 0) { // BACnetPacket pkt = _apm.pktQueueToApplication.myDequeue(); BACnetPacket pkt = waitForPacket(1); if (pkt.srcDevice.adr.networkNumber != this.devicTreeNode.device.adr.networkNumber) { MarkDiagnosticFailed("A device [" + pkt.srcDevice.adr.ToString() + "] from network [" + pkt.srcDevice.adr.networkNumber.ToString() + "] that is not directly connected responded"); someFails = true; } } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; //BACnetLibrary.Panic(ex.ToString()); //return; } if (!someFails) { MarkDiagnosticSuccess(); // Mark this diagnostic a success, any failures will re } }
public BACnetPacket waitForPacket(int timeout, BACnetEnums.BACNET_UNCONFIRMED_SERVICE bus) { do { BACnetPacket pkt = waitForPacket(timeout); if (pkt.messageType == BACnetPacket.MESSAGE_TYPE.APPLICATION && pkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST && pkt.unconfirmedServiceChoice == bus) { return(pkt); } } while (true); }
public BACnetPacket waitForPacket(int timeout, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE netMessage) { long startTime = _apm._stopWatch.ElapsedMilliseconds; while (_apm._stopWatch.ElapsedMilliseconds < startTime + timeout) { BACnetPacket inPkt = waitForPacket(timeout); if (inPkt.messageType == BACnetPacket.MESSAGE_TYPE.NETWORK_LAYER && inPkt.npdu.function == netMessage) { return(inPkt); } // else try again } throw new TimeoutException(); }
public override void Execute() { bool someFails = false; WaitForQuietOnIncomingPacketQueue(); ClearIncomingPacketQueue(); try { if (this.devicTreeNode.device.adr.directlyConnected == true) { MarkDiagnosticWithNote("This node needs to be directly connected for this Diagnostic. Diagnostic not appropriate"); return; } // todo. the ADR constructor is going to use an IP broadcast. We should know the router for this device and transmit the packet only to that router... BACnetUtil.SendWhoIsRouter(_apm, _bnm, BACnetPacket.ADDRESS_TYPE.LOCAL_BROADCAST); WaitForQuietOnIncomingPacketQueue(); // check the incoming packets, make sure that they are all from local addresses if (_apm.pktQueueToApplication.Count == 0) { MarkDiagnosticFailed("No response to the Who-Is-Router"); return; } while (_apm.pktQueueToApplication.Count > 0) { BACnetPacket pkt = waitForPacket(1); if (!pkt.dAdr.isLocalBroadcast) { MarkDiagnosticFailed("A Router [" + pkt.srcDevice.adr.ToString() + "] did not use a local broadcast"); someFails = true; } } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { throw ex; } if (!someFails) { MarkDiagnosticSuccess(); // Mark this diagnostic a success, any failures will re } }
public BACnetPacket waitForPacket(int timeout) { long startTime = _apm._stopWatch.ElapsedMilliseconds; while (_apm._stopWatch.ElapsedMilliseconds < startTime + timeout) { if (_apm.pktQueueToApplication.Count > 0) { BACnetPacket bpk = _apm.pktQueueToApplication.myDequeue(); bpk.DecodeBACnet(); return(bpk); } Sleep(10); } // timeout - todo - one day create a timeout type of exception throw new TimeoutException(); }
// tests that only local devices answer to local broadcasts. (A type of router test). public override void Execute() { bool someFails = false; WaitForQuietOnIncomingPacketQueue(); ClearIncomingPacketQueue(); try { DADR dadr = new DADR(_bnm, BACnetPacket.ADDRESS_TYPE.LOCAL_BROADCAST); BACnetUtil.SendWhoIs(_apm, _bnm, dadr); // Sleep(1000); // and perhaps longer on large networks.... WaitForQuietOnIncomingPacketQueue(); // check the incoming packets, make sure that they are all local addresses while (_apm.pktQueueToApplication.Count > 0) { if (_apm.pktQueueToApplication.Count == 0) { // wait just a while longer, there may be more packets dribbling in. So by pausing here // we wait 1 second longer than the last packet to arrive... seems reasonable to me Sleep(1000); } BACnetPacket pkt = _apm.pktQueueToApplication.myDequeue(); pkt.DecodeBACnet(); if (pkt.srcDevice.adr.directlyConnected != true) { MarkDiagnosticFailed("A device [" + pkt.srcDevice.adr.ToString() + "] that is not directly connected responded"); someFails = true; } } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } if (someFails == false) { MarkDiagnosticSuccess(); // Mark this diagnostic a success, any failures will re } }
public override void Execute() { try { ClearIncomingPacketQueue(); // Create, encode and send a packet BACnetPacket pkt = new BACnetPacket(_apm, _bnm, this.device.adr, this.device.deviceObjectID, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_REVISION); pkt.SendPacket(); // Wait for response BACnetPacket responsePkt = waitForPacket(5000); // Since we made a deliberate mistake with our request, we expect a reject PDU. Make sure we get it if (responsePkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK) { if (responsePkt.confirmedServiceChoice == BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY) { _apm.MessageLog("Protocol revision = " + responsePkt.protocolRevision.ToString()); } else { MarkDiagnosticFailed("errDiag00001 - Wrong confirmedServiceChoice in response"); return; } } else { MarkDiagnosticFailed("errDiag00002 - Complex ACK not received"); return; } } catch (TimeoutException) { MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { _apm.MessagePanic("Diagnostic Exception " + ex.ToString()); return; } MarkDiagnosticSuccess(); }
public override void Execute() { _apm.MessageLog("Executing " + diagnosticName); // create a device object without instance number - this will create a wildcard instance BACnetObjectIdentifier oid = new BACnetObjectIdentifier(BACnetEnums.BACNET_OBJECT_TYPE.OBJECT_DEVICE); try { ClearIncomingPacketQueue(); BACnetUtil.SendReadProperty(_apm, _bnm, devicTreeNode.device, oid, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_IDENTIFIER); BACnetPacket pkt = waitForPacket(5000); if (pkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK && pkt.propertyID == BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_IDENTIFIER) { if (pkt.objectID != null && pkt.objectID.objectInstance == devicTreeNode.device.deviceObjectID.objectInstance) { MarkDiagnosticSuccess(); } else { MarkDiagnosticFailed("Response received, but the Object ID is not that of the Device"); } } else { MarkDiagnosticFailed("Proper Complex-ACK not received"); } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... _apm.MessagePanic(ex.ToString()); return; } }
public override void Execute() { _apm.MessageLog("Executing " + diagnosticName); try { BACnetPacket resp; BACnetPacket pkt = new BACnetPacket(this._apm); pkt.EncodeNPCI(new DADR(), BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); pkt.EncodeContextTag(0, 0); pkt.EncodeContextTag(1, BACnetEnums.BACNET_MAX_INSTANCE); BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); // wait for _our_ device to respond do { resp = waitForPacket(5000, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM); if (resp.srcDevice.deviceObjectID.Equals(devicTreeNode.device.deviceObjectID)) { Sleep(5000); ClearIncomingPacketQueue(); MarkDiagnosticSuccess(); return; } }while (true); } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... _apm.MessagePanic(ex.ToString()); return; } }
public override void Execute() { _apm.MessageLog("Executing " + diagnosticName); try { ClearIncomingPacketQueue(); BACnetPacket pkt = new BACnetPacket(this._apm); pkt.EncodeNPCI(new DADR(), BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); pkt.EncodeContextTag(0, (int)devicTreeNode.device.deviceObjectID.objectInstance); // Ha! Notice we did not encode the second part of the who-is. Devices should not respond. BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); // wait for _our_ device to respond while (true) { try { // We expect to timeout waitForPacket(5000, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM); ClearIncomingPacketQueue(); MarkDiagnosticFailed("There should be NO response from the device"); return; } catch (TimeoutException) { // remember we expect to time out MarkDiagnosticSuccess(); return; } } } catch (Exception ex) { // other types of exception... _apm.MessagePanic(ex.ToString()); return; } }
public PacketLog(bool sending, BACnetPacket packet) { this.sending = sending; this.BACnetPacket = packet; }
public override void Execute() { BACnetPacket incomingPkt; //if (!(deviceNode.device.GetType() == typeof(Router))) //{ // MarkDiagnosticWithNote("Device is not a router, cannot run this test"); // return; //} // todo, block this queue unless a diagnostic is running // clear the queue ClearIncomingPacketQueue(); try { BACnetUtil.SendInitRoutingTable(_apm, _bnm, new DADR(devicTreeNode.device.adr)); incomingPkt = waitForPacket(5000, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE_ACK); // todo, add fromaddress... // got it. foreach (RoutingTableEntry rte in incomingPkt.routerTableList) { Console.WriteLine(rte.ToString()); } // record the number of entries, and record the last item int entrycount = incomingPkt.routerTableList.Count; if (entrycount < 1 || entrycount > 255) { Console.WriteLine("Failed this time around"); // test fails, impossible count return; //throw new Exception("m0525-Totally bogus router table entry count"); } RoutingTableEntry rtDupe = incomingPkt.routerTableList[entrycount - 1]; // now write the last entry again. BACnetPacket outgoingPkt = new BACnetPacket(_apm, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE); outgoingPkt.SetDestination(new DADR(incomingPkt.srcDevice.adr)); outgoingPkt.routerTableList = new List <RoutingTableEntry>(); outgoingPkt.routerTableList.Add(rtDupe); outgoingPkt.EncodeBACnet(); _bnm.insideSocket.OurSendTo(outgoingPkt.buffer, outgoingPkt.optr, incomingPkt.srcDevice.adr.ResolvedIPEP()); // wait for the ack incomingPkt = waitForPacket(5000, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE_ACK); // drop the packet // re-read the routing table BACnetUtil.SendInitRoutingTable(_apm, _bnm, new DADR(devicTreeNode.device.adr)); incomingPkt = waitForPacket(5000, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE_ACK); foreach (RoutingTableEntry rte in incomingPkt.routerTableList) { Console.WriteLine(rte.ToString()); } // record the number of entries, and record the last item if (incomingPkt.routerTableList.Count != entrycount) { Console.WriteLine("m0165-Failed entrycount"); // Todo, check if this _IS_ OK. MarkDiagnosticFailed("The entrycount did not remain the same, i.e. The router allowed the addition of a duplicate Network Number"); return; } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; //BACnetLibrary.Panic(ex.ToString()); //return; } MarkDiagnosticSuccess(); Console.WriteLine("Diag done"); }
public override void Execute() { try { List <BACnetEnums.BACNET_PROPERTY_ID> propList = new List <BACnetEnums.BACNET_PROPERTY_ID>(new BACnetEnums.BACNET_PROPERTY_ID[] { BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_IDENTIFIER, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_NAME, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE, BACnetEnums.BACNET_PROPERTY_ID.PROP_SYSTEM_STATUS, BACnetEnums.BACNET_PROPERTY_ID.PROP_VENDOR_NAME, BACnetEnums.BACNET_PROPERTY_ID.PROP_VENDOR_IDENTIFIER, BACnetEnums.BACNET_PROPERTY_ID.PROP_MODEL_NAME, BACnetEnums.BACNET_PROPERTY_ID.PROP_FIRMWARE_REVISION, BACnetEnums.BACNET_PROPERTY_ID.PROP_APPLICATION_SOFTWARE_VERSION, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_VERSION, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_REVISION, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_SERVICES_SUPPORTED, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_LIST, BACnetEnums.BACNET_PROPERTY_ID.PROP_MAX_APDU_LENGTH_ACCEPTED, BACnetEnums.BACNET_PROPERTY_ID.PROP_SEGMENTATION_SUPPORTED, BACnetEnums.BACNET_PROPERTY_ID.PROP_APDU_TIMEOUT, BACnetEnums.BACNET_PROPERTY_ID.PROP_NUMBER_OF_APDU_RETRIES, // todo, only mstp BACnetEnums.BACNET_PROPERTY_ID.PROP_MAX_MASTER, // todo, only mstp BACnetEnums.BACNET_PROPERTY_ID.PROP_MAX_INFO_FRAMES, BACnetEnums.BACNET_PROPERTY_ID.PROP_DEVICE_ADDRESS_BINDING, BACnetEnums.BACNET_PROPERTY_ID.PROP_DATABASE_REVISION }); foreach (BACnetEnums.BACNET_PROPERTY_ID pid in propList) { ClearIncomingPacketQueue(); BACnetPacket pkt = new BACnetPacket(_apm, BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); pkt.dAdr = new DADR(this.device.adr); pkt.EncodeNPCI(pkt.dAdr, BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); // Encode the rest of the packet according to http://www.bacnetwiki.com/wiki/index.php?title=Read_Property pkt.EncodeContextTag(0, this.device.deviceObjectID); pkt.EncodeContextTag(1, pid); BACnetUtil.SendOffPacket(this._apm, this._bnm, pkt, pkt.buffer, pkt.optr); BACnetPacket respPkt = waitForPacket(5000); // Since we made a deliberate mistake with our request, we expect a reject PDU. Make sure we get it if (respPkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK) { if (respPkt.confirmedServiceChoice == BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY) { // so far, so good, continue if (respPkt.invokeID + 1 != _apm.invokeID) { MarkDiagnosticFailed("Bad Invoke ID in the response"); return; } if (respPkt.propertyID != pid) { MarkDiagnosticFailed("Bad Property in the response"); return; } } else { MarkDiagnosticFailed("Did not receive a response to the confirmed read property"); return; } } else { MarkDiagnosticFailed("Expected a Complex ACK response"); return; } } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; } MarkDiagnosticSuccess(); }
public override void Execute() { int protocolRevision; try { ClearIncomingPacketQueue(); BACnetPacket pkt = new BACnetPacket(_apm, _bnm, this.device.adr, this.device.deviceObjectID, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_REVISION); pkt.SendPacket(); BACnetPacket respPkt = waitForPacket(5000); protocolRevision = respPkt.protocolRevision; pkt = new BACnetPacket(_apm, _bnm, this.device.adr, this.device.deviceObjectID, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED); pkt.SendPacket(); respPkt = waitForPacket(5000); // Since we made a deliberate mistake with our request, we expect a reject PDU. Make sure we get it if (respPkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK) { if (respPkt.confirmedServiceChoice == BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY) { // so far, so good, continue switch (protocolRevision) { case 2: if (respPkt.bitString != null && respPkt.bitString.Count() != 0x19) { MarkDiagnosticFailed("Object Type List not the correct length for the protocol"); return; } break; case 6: if (respPkt.bitString != null && respPkt.bitString.Count() != 38) { MarkDiagnosticFailed("Object Type List not the correct length for the protocol"); return; } break; case 10: if (respPkt.bitString != null && respPkt.bitString.Count() != 0x33) { MarkDiagnosticFailed("Object Type List not the correct length for the protocol"); return; } break; default: MarkDiagnosticFailed("Unknown protocol revision"); return; } } else { MarkDiagnosticFailed("Did not receive a response to the confirmed read property"); return; } } else { MarkDiagnosticFailed("Expected a Complex ACK response"); return; } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; } MarkDiagnosticSuccess(); }
public PacketLog(bool sending, IPEndPoint ipep, BACnetPacket packet) { this.sending = sending; this.ipep = ipep; this.BACnetPacket = packet; }