///////////////////////////////oooooooooooooooooooooooooooooooooooooooooooooo/////////////////////////////////////////////////////////////////////////////////// public int Decode(ref BACNET_ADDRESS src, ref byte[] buf) { UInt16 npdu_len = 0; BasicalProcessor.Decode_Unsigned16(ref buf, ref npdu_len, 2); npdu_len = (UInt16)(npdu_len - 4); int function_type = buf[1]; switch (function_type) { case (byte)BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_BROADCAST_NPDU: { byte[] data = new byte[1024]; Array.Copy(buf, 4, data, 0, npdu_len); buf = data; break; } case (byte)BACNET_BVLC_FUNCTION.BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK: { byte[] data = new byte[1024]; Array.Copy(buf, 4, data, 0, npdu_len); buf = data; break; } case (byte)BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_UNICAST_NPDU: { byte[] data = new byte[1024]; Array.Copy(buf, 4, data, 0, npdu_len); buf = data; break; } } return(npdu_len); }
/**********************************************************************************************************************************************************************/ public int Decode(ref byte[] npdu, ref BACNET_ADDRESS dest, ref BACNET_ADDRESS src, ref BACNET_NPDU_DATA npdu_data) { int len = 0; byte i = 0; UInt16 src_net = 0; UInt16 dest_net = 0; byte address_len = 0; byte mac_octet = 0; npdu_data.protocol_version = npdu[0]; npdu_data.network_layer_message = ((npdu[1] & BacnetConst.BIT7) != 0) ? true : false; //是否是网络层的数据报文或者网络层协议报文 npdu_data.data_expecting_reply = ((npdu[1] & BacnetConst.BIT2) != 0) ? true : false; npdu_data.priority = (BACNET_MESSAGE_PRIORITY)(npdu[1] & 0x03); len = 2; if ((npdu[1] & BacnetConst.BIT5) != 0) { len += BasicalProcessor.Decode_Unsigned16(ref npdu, ref dest_net, len); address_len = npdu[len++]; dest.net = dest_net; dest.len = address_len; if (address_len > 0) { for (i = 0; i < address_len; i++) { mac_octet = npdu[len++];//11 dest.adr[i] = mac_octet; } } } else { dest.net = 0; dest.len = 0; for (i = 0; i < 7; i++) { dest.adr[i] = 0; } } //源mac if ((npdu[1] & BacnetConst.BIT3) != 0) { len += BasicalProcessor.Decode_Unsigned16(ref npdu, ref src_net, len); //13 address_len = npdu[len++]; //14 src.net = src_net; src.len = address_len; if (address_len > 0) { for (i = 0; i < address_len; i++) { mac_octet = npdu[len++]; //21 src.adr[i] = mac_octet; } } } else { src.net = 0; src.len = 0; for (i = 0; i < 7; i++) { src.adr[i] = 0; } } //hop count if (dest_net != 0) { npdu_data.hop_count = npdu[len++]; } else { npdu_data.hop_count = 0; } //对于网络层协议无处理功能 if (npdu_data.network_layer_message) { npdu_data.network_message_type = (BACNET_NETWORK_MESSAGE_TYPE)npdu[len++]; } else { npdu_data.network_message_type = BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INVALID; } return(len); }