public byte SendAtCommand(XBeeCommand command, XBeeCallback callback, uint value, int size) { ApiFrame frame = new ApiFrame(); byte frameId = GetNextFrameId(); byte[] buffer = new byte[4 + size]; buffer[ApiIdentifier] = (byte)ApiFrameName.ATCommand; buffer[FrameIdentifier] = frameId; ushort commandUShort = (ushort)command; buffer[2] = (byte)(commandUShort >> 8); buffer[3] = (byte)commandUShort; if (size > 0) { Utility.InsertValueIntoArray(buffer, 4, size, value); } frame.FrameData = buffer; frame.Callback = callback; return SendApiFrame(frame); }
internal byte SendApiFrame(ApiFrame frame) { byte frameId = frame.FrameData[FrameIdentifier]; _frameBuffer[frameId] = frame; var buffer = frame.Serialize(); _uart.Write(buffer, 0, frame.Length + 4); return frameId; }
private void ReceivedApiFrame(ApiFrame frame) { switch (frame.FrameData[ApiIdentifier]) { case (byte)ApiFrameName.ZigBeeIODataSampleRxIndicator: if (frame.Length >= 18) { int analogSampleIndex = 16; int digitalChannelMask = (frame.FrameData[13] << 8) | frame.FrameData[14]; if (digitalChannelMask > 0) { if (StatusReceived != null) { StatusReceived(frame.FrameData[17]); } analogSampleIndex = 18; } if (AnalogStatusReceived != null) { int[] analogSamples = new int[4]; int analogChannelMask = frame.FrameData[15]; for (int i = 0; i < 4; i++) { if ((analogChannelMask >> i) == 1) { analogSamples[i] = (frame.FrameData[analogSampleIndex] << 8) | frame.FrameData[analogSampleIndex + 1]; analogSampleIndex += 2; } else { analogSamples[i] = -1; } } AnalogStatusReceived(analogSamples); } } break; case (byte)ApiFrameName.ATCommandResponse: ReceivedAtCommandResponse(frame); break; case (byte)ApiFrameName.RemoteCommandResponse: ReceivedAtCommandResponse(frame); break; case (byte)ApiFrameName.ZigBeeReceivePacket: ReceivedZigBeePacket(frame); break; } }
internal void ReceivedZigBeePacket(ApiFrame frame) { byte[] data = Utility.ExtractRangeFromArray(frame.FrameData, 12, frame.Length - 12); if (FrameReceived != null) FrameReceived(data); }
internal void ReceivedAtCommandResponse(ApiFrame frame) { byte frameID = frame.FrameData[FrameIdentifier]; XBeeCommand command = (XBeeCommand)(frame.FrameData[2] << 8 | frame.FrameData[3]); ApiFrame sentFrame = _frameBuffer[frameID]; if (sentFrame != null && sentFrame.Callback != null) { sentFrame.Callback(frame); if (!(command == XBeeCommand.NodeDiscover && frame.Length > 0)) { _frameBuffer[frameID] = null; } } }
public byte SendRemoteAtCommand(ulong destinationSerialNumber, XBeeCommand command, XBeeCallback callback, byte value) { ApiFrame frame = new ApiFrame(); byte frameId = GetNextFrameId(); int txDataLenght; if (value == 0x0) txDataLenght = 3; else txDataLenght = 4; byte[] txDataContent = new byte[txDataLenght]; txDataContent[0] = 0x02; // appply changes on remote ushort commandUShort = (ushort)command; txDataContent[1] = (byte)(commandUShort >> 8); txDataContent[2] = (byte)commandUShort; if (value != 0x0) txDataContent[3] = value; byte[] txData = Utility.CombineArrays(_txDataBase, txDataContent); txData[0] = (byte)ApiFrameName.RemoteCommandRequest; txData[1] = frameId; for (int i = 0; i < 8; i++) { txData[9 - i] = (byte)(destinationSerialNumber >> (8 * i)); } frame.FrameData = txData; frame.Callback = callback; return SendApiFrame(frame); }
public byte SendData(ulong destinationSerialNumber, ushort destinationAddress, byte[] data, XBeeCallback callback) { ApiFrame frame = new ApiFrame(); byte frameId = GetNextFrameId(); byte[] txDataContent = new byte[2]; txDataContent[0] = 0x0; txDataContent[1] = 0x0; txDataContent = Utility.CombineArrays(txDataContent, data); byte[] txData = Utility.CombineArrays(_txDataBase, txDataContent); txData[0] = (byte)ApiFrameName.ZigBeeTransmitRequest; txData[1] = frameId; for (int i = 0; i < 8; i++) { txData[9 - i] = (byte)(destinationSerialNumber >> (8 * i)); } frame.FrameData = txData; frame.Callback = callback; return SendApiFrame(frame); }
public void Reset() { position = 0; length = 0; checksum = 0; IsComplete = false; frame = new ApiFrame(); }