myTreeNode findTreeNodeObject(myTreeNode mtn, BACnetObjectIdentifier bno) { for (int i = 0; i < mtn.Nodes.Count; i++) { // there may be a mix of myTreeNodes and TreeNodes. Only peer at myTreeNode types if (mtn.Nodes[i].GetType() == typeof(myTreeNode)) { if (((myTreeNode)mtn.Nodes[i]).oID != null) { if (((myTreeNode)mtn.Nodes[i]).oID.Equals(bno) == true) { return((myTreeNode)mtn.Nodes[i]); } } } } return(null); }
private void DecodeConfirmedService(byte[] apdu_buf) { if ((apdu_buf[0] & 0x08) != 0) { _apm.MessageTodo("m0002 Need to implement confirmed service types with seg=1 still"); return; } int iptr = 3; confirmedServiceChoice = (BACnetEnums.BACNET_CONFIRMED_SERVICE)apdu_buf[iptr++]; apduConfirmedServiceTypeFlag = true; switch (confirmedServiceChoice) { case BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY: // Expecting 2-3 context tags. // First, mandatory, context 0, object ID objectID = new BACnetObjectIdentifier(); objectID.DecodeContextTag(apdu_buf, ref iptr); // Second, mandatory, Property ID propertyID = (BACnetEnums.BACNET_PROPERTY_ID)BACnetEncoding.DecodeTagContextUint(apdu_buf, ref iptr, 1); // Third, Array Index, Optional if (iptr < apdu_length) { arrayIndex = (int)BACnetEncoding.DecodeTagContextUint(apdu_buf, ref iptr, 2); arrayIndexDecoded = true; } break; default: _apm.MessageTodo("m0024 all the other service types"); break; } }
void DecodeComplexACK(byte[] buf, int offset) { if ((buf[offset] & 0x0f) != 0) { throw new Exception("m0020 - Not ready to handle segmented messages yet"); } // invoke ID - ignoring for now // Service ACK choice BACnetEnums.BACNET_CONFIRMED_SERVICE sc = (BACnetEnums.BACNET_CONFIRMED_SERVICE)buf[offset + 2]; switch (sc) { case BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY: offset += 3; // Decode Object ID of the object whos property we are reading BACnetObjectIdentifier oid = new BACnetObjectIdentifier(buf, ref offset, BACnetEnums.TAG.CONTEXT, 0); // Decode the property ID propertyID = (BACnetEnums.BACNET_PROPERTY_ID)BACnetEncoding.DecodeTagContextUint(buf, ref offset, 1); // Now decode the Property Value itself. Variable encoding, variable length, etc.... switch (oid.objectType) { case BACnetEnums.BACNET_OBJECT_TYPE.OBJECT_DEVICE: switch (propertyID) { case BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_LIST: // decode the list of objects // process the opening context tag, 0x3e if (buffer[offset++] != 0x3e) { throw new Exception("m0033 - Opening context tag not found " + buffer[offset - 1].ToString()); } objectList = new List <BACnetObjectIdentifier>(); // now loop until closing tag found while (buffer[offset] != 0x3f) { // we should get a list of object IDs, add these to our backnet packet object as they are discovered. objectList.Add(new BACnetObjectIdentifier(buffer, ref offset, BACnetEnums.TAG.APPLICATION, BACnetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OBJECT_ID)); } break; case BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_NAME: _apm.MessageTodo("m0032 - Decode object name"); break; default: _apm.MessageTodo("m0026 Unimplemented Property ID " + propertyID.ToString()); break; } break; default: _apm.MessageTodo("m0061 Unhandled object type " + oid.objectType.ToString()); break; } break; default: _apm.MessageTodo("m0028 - Not ready to deal with this service yet " + sc.ToString()); return; } }
public void EncodeBACnetNew(byte[] outbuf, ref int optr) { int startBACnetPacket = optr; // BVLC Part // http://www.bacnetwiki.com/wiki/index.php?title=BACnet_Virtual_Link_Control outbuf[optr++] = BACnetEnums.BACNET_BVLC_TYPE_BIP; if (npdu.isBroadcast) { outbuf[optr++] = (byte)BACnetEnums.BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_BROADCAST_NPDU; } else { outbuf[optr++] = (byte)BACnetEnums.BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_UNICAST_NPDU; } int store_length_here = optr; optr += 2; // Start of NPDU // http://www.bacnetwiki.com/wiki/index.php?title=NPDU outbuf[optr++] = 0x01; // Always 1 int store_NPCI = optr; outbuf[optr++] = 0x00; // Control if (npdu.isNPDUmessage) { outbuf[store_NPCI] |= 0x80; // Indicating Network Layer Message } if (npdu.expectingReply) { outbuf[store_NPCI] |= 0x04; // todo- magic number } if (npdu.isBroadcast) { outbuf[store_NPCI] |= 0x20; // Control byte - indicate DADR present outbuf[optr++] = 0xff; // DNET Network - B'cast outbuf[optr++] = 0xff; outbuf[optr++] = 0x00; // DLEN } else { // insert dadr - but only if the device is NOT directly coupled. See page 59. If the device is directly coupled // then the ethernet address in the packet will suffice. if (!dadr.directlyConnected) { // need to insert destination DADR here outbuf[store_NPCI] |= 0x20; // Control byte - indidate DADR present dadr.Encode(outbuf, ref optr); } } // we are a router, so we need to add source address under most circumstances. (not broadcast who-is) if (srcDevice.adr != null) { outbuf[store_NPCI] |= 0x08; // Control byte - indidate SADR present srcDevice.adr.Encode(outbuf, ref optr); } if (npdu.isBroadcast || !dadr.directlyConnected) { // insert hopcount here. hopcount -= 10; outbuf[optr++] = (byte)hopcount; } // APDU start // http://www.bacnetwiki.com/wiki/index.php?title=APDU if (apdu_present) { // APDU start // http://www.bacnetwiki.com/wiki/index.php?title=APDU for (int i = 0; i < apdu_length; i++) { outbuf[optr++] = buffer[apdu_offset + i]; // Encoded APDU type == 01 == Unconfirmed Request } } else if (npdu.isNPDUmessage) { // Build the Nsdu // http://www.bacnetwiki.com/wiki/index.php?title=Network_Layer_Message outbuf[optr++] = (byte)npdu.function; switch (npdu.function) { case BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: break; case BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE: outbuf[optr++] = 0x00; // Number of port mappings break; case BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: if (numberList != null) { foreach (uint i in numberList) { BACnetLibraryCL.InsertUint16(outbuf, ref optr, i); } } break; default: _apm.MessageTodo("m0023 Implement " + npdu.function.ToString()); break; } } else { // build an APDU. switch (this.pduType) { case BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST: switch (this.unconfirmedServiceChoice) { case BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM: // APDU start // http://www.bacnetwiki.com/wiki/index.php?title=APDU outbuf[optr++] = 0x10; // Encoded APDU type == 01 == Unconfirmed Request outbuf[optr++] = 0x00; // Unconfirmed Service Choice: I-Am // object identifier, device object BACnetObjectIdentifier bnoid = new BACnetObjectIdentifier(); bnoid.SetType(BACnetEnums.BACNET_OBJECT_TYPE.OBJECT_DEVICE); _apm.MessageTodo("m0038 - Establish a mechanism to determine our OWN Device ID"); bnoid.SetInstance(_apm.ourDeviceId); bnoid.EncodeApplicationTag(outbuf, ref optr); // Maximum APDU length (Application Tag, Integer) Unsigned apdulen = new Unsigned(1476); apdulen.Encode(outbuf, ref optr); // Segmentation supported, (Application Tag, Enum) BACnetSegmentation bsg = new BACnetSegmentation(); bsg.Encode(outbuf, ref optr); // Vendor ID, (Application Tag, Integer) BACnetLibraryCL.InsertApplicationTagUint16(outbuf, ref optr, _apm.ourVendorID); break; default: _apm.MessageTodo("m0022 Build missing service type"); break; } break; default: _apm.MessageTodo("m0021 Build missing PDU type"); break; } } outbuf[store_length_here] = (byte)(((optr - startBACnetPacket) >> 8) & 0xff); outbuf[store_length_here + 1] = (byte)((optr - startBACnetPacket) & 0xff); }
public bool Equals(BACnetObjectIdentifier deviceID) { return(this.deviceObjectID.Equals(deviceID)); }