UInt32 CreateTokenKey(byte[] token, PhysicalIdentifier type) { if (token == null || token.Length != 2) { throw new Exception("Token must be an array with 2 elements"); } var key = new byte[] { token[0], token[1], 0, (byte)type }; return(BitConverter.ToUInt32(key, 0)); }
//downlink transmission public PhysicalPayload(byte[] _token, PhysicalIdentifier type, byte[] _message) { //0x01 PUSH_ACK That packet type is used by the server to acknowledge immediately all the PUSH_DATA packets received. //0x04 PULL_ACK That packet type is used by the server to confirm that the network route is open and that the server can send PULL_RESP packets at any time. if (type == PhysicalIdentifier.PUSH_ACK || type == PhysicalIdentifier.PULL_ACK) { token = _token; identifier = type; } //0x03 PULL_RESP That packet type is used by the server to send RF packets and metadata that will have to be emitted by the gateway. if (type == PhysicalIdentifier.PULL_RESP) { token = _token; identifier = type; message = new byte[_message.Length]; Array.Copy(_message, 0, message, 0, _message.Length); } }
internal void SubscribeOnce(byte[] token, PhysicalIdentifier type, Action <byte[]> value) { subscribers.TryAdd(CreateTokenKey(token, type), value); }