public static FrameTypeDescriptor GetFrameTypeDescriptor(IXBeeFrame frame) { if (frame == null) throw new ArgumentNullException("frame"); return GetFrameTypeDescriptor(frame.FrameType); }
private void WriteFrameToSerialPort(IXBeeFrame frame) { byte[] bytesToWrite = FrameSerializer.Serialize(frame); serialPort.WriteFrame(bytesToWrite); // statistics counting XBeeStatistics.MessagesSent++; }
private void StartRegisteringUnknownDevice(XBeeDeviceNetwork deviceNetwork, IXBeeFrame frame) { // check if this device is already staging if (!HomeAutomationSystem.DeviceRegistry.IsStagingDevice(deviceNetwork, frame.Address)) { HomeAutomationSystem.DeviceRegistry.RegisterStagingDevice(deviceNetwork, frame.Address); AskForDeviceType(deviceNetwork, frame); } }
private void AskForDeviceType(XBeeDeviceNetwork deviceNetwork, IXBeeFrame remoteFrame) { frameId++; if (frameId == 0) frameId++; Log.Debug($"Received a frame from an unknown device, so we are asking type ID from this device. Address: {remoteFrame.Address.ToHexString()}"); // create the XBee frame to send IXBeeFrame frame = XBeeFrameBuilder.CreateRemoteATCommand(ATCommands.DD, frameId, remoteFrame.Address, remoteFrame.NetworkAddress); deviceNetwork.XBeeService.SendFrame(frame); }
/// <summary> /// Serializes the frame to the provided buffer. /// </summary> /// <param name="frame"></param> /// <param name="apiVersion"></param> public static byte[] Serialize(IXBeeFrame frame) { byte[] buffer = new byte[XBeeConstants.MaxFrameLength]; FrameTypeDescriptor descriptor = FrameTypeDescriptorRegistry.GetFrameTypeDescriptor(frame); // set the frame start byte. buffer[FrameIndex.Start] = XBeeConstants.FrameStart; MethodInfo getterMethod; int index = 0; for (int i = 0; i < descriptor.PropertyDescriptors.Length; i++) { PropertyDescriptor onePropertyDescriptor = descriptor.PropertyDescriptors[i]; int writtenByteCount = onePropertyDescriptor.ByteCount; if (onePropertyDescriptor.PropertyType != PropertyType.Ignored) { // get the setter method information getterMethod = descriptor.FrameClassType.GetMethod("get_" + onePropertyDescriptor.PropertyName); object returnValue = getterMethod.Invoke(frame, new object[] { }); if (returnValue != null) { writtenByteCount = SetPropertyValueToBuffer(buffer, index, returnValue, onePropertyDescriptor); } } index += writtenByteCount; } // calculate the length of the payload, and update the frame with the information int payloadLength = index - 3; buffer[FrameIndex.LengthMSB] = (byte)(payloadLength / 256); buffer[FrameIndex.LengthLSB] = (byte)(payloadLength % 256); // calculate the checksum of the payload buffer[index] = XBeeFrameUtil.CalculateChecksum(buffer); byte[] resultBuffer = null; // make a new array which contains only the resulting bytes, and return that array resultBuffer = new byte[index + 1]; Array.Copy(buffer, resultBuffer, index + 1); return resultBuffer; }
public void ProcessFrame(XBeeDeviceNetwork deviceNetwork, IXBeeFrame frame) { // get the device type from device registry. if it's not found // then we will ask the device to identify itself. IXBeeDevice device = HomeAutomationSystem.DeviceRegistry.GetDeviceById(deviceNetwork, frame.Address) as IXBeeDevice; if (device != null) { device.ProcessFrame(frame); deviceNetwork.AnnounceDeviceState(device.DeviceState); } else { StartRegisteringUnknownDevice(deviceNetwork, frame); } }
public override void ProcessFrame(IXBeeFrame frame) { base.ProcessFrame(frame); IODataSample dataSample = frame as IODataSample; if (dataSample != null) { // The device sent both digital and analog samples if (dataSample.Samples.Length == 4) { // first 2 bytes are going to the RelayDevice (digital samples) // next 2 bytes are the analog samples double analogReading = (dataSample.Samples[2] * 256 + dataSample.Samples[3]) * AnalogPinMaxVoltage / AnalogPinResolution; // now calculate the temperature temperature = HomeAutomation.Sensor.Temperature.LM35.TemperatureFromVoltage(analogReading); } } }
public void ProcessFrame(XBeeDeviceNetwork deviceNetwork, IXBeeFrame frame) { RemoteCommandResponse responseFrame = (RemoteCommandResponse)frame; // check if this is a DD command response - used for identifying devices by their type if (XBeeFrameUtil.IsSameATCommand(responseFrame.ATCommand, ATCommands.DD)) { // build the ID for the device type based on the frame info int deviceIdentification = responseFrame.Parameters[2] * 256 + responseFrame.Parameters[3]; HomeAutomationSystem.DeviceRegistry.RegisterDeviceWithTypeID(deviceNetwork, deviceIdentification, frame.Address, frame.NetworkAddress); } else { // get the device type from device registry, and send the frame for processing it. IXBeeDevice device = HomeAutomationSystem.DeviceRegistry.GetDeviceById(deviceNetwork, frame.Address) as IXBeeDevice; device?.ProcessFrame(frame); } }
public void ProcessFrame(IXBeeFrame frame) { ReceivePacket dataSample = frame as ReceivePacket; if (dataSample != null) { if (dataSample.ReceivedData[0] == MagiConstant_EpamDevice && dataSample.ReceivedData[1] == MagiConstant_TemperatureDevice) { Temperature = BitConverter.ToSingle(dataSample.ReceivedData, 2); } else { Log.Debug("[EpamTemperatureDeviceV1] Wrong start bytes."); } } else { Log.Debug("[EpamTemperatureDeviceV1] Wrong frame type (or null)."); } }
public void ProcessFrame(IXBeeFrame frame) { IODataSample dataSample = frame as IODataSample; if (dataSample != null) { if (dataSample.Samples.Length == 2) { // now read the temperature sensor reading double analogReading = (dataSample.Samples[0] * 256 + dataSample.Samples[1]) * AnalogPinMaxVoltage / AnalogPinResolution; Temperature = HomeAutomation.Sensor.Temperature.LM35.TemperatureFromVoltage(analogReading); } else { Log.Debug("[TemperatureDeviceV2] Wrong number of samples received."); } } else { Log.Debug("[TemperatureDeviceV2] Wrong frame type (or null) for temperature sensor device."); } }
/// <summary> /// Processes any frames sent to this device. /// </summary> /// <param name="frame"></param> public virtual void ProcessFrame(IXBeeFrame frame) { IODataSample dataSample = frame as IODataSample; if (dataSample != null) { // if there are digital pin states in the sample then use them for populating wht switchStates variable. if (dataSample.DigitalMask > 0 && dataSample.Samples.Length >= 2) { int digitalReadingMLB = dataSample.Samples[0] * 256 + dataSample.Samples[1]; // build the switch states for (int i = 0; i < switchStates.Length; i++) { switchStates[i] = dataSample.IsDigitalPinHigh(xbeeConfiguration[i]) ? StateOFF : StateON; } } } }
private void XbeeService_MessageReceived(object sender, IXBeeFrame e) { Type frameType = e.GetType(); IXBeeFrameProcessor processor = XBeeFrameProcessorFactory.GetProcessorByFrameType(frameType); if (processor != null) { processor.ProcessFrame(this, e); } else { Log.Debug("Dropping frame with type " + frameType.Name + " as no suitable processor is found."); } }
public void ProcessFrame(IXBeeFrame frame) { }
public void SendFrame(IXBeeFrame frame) { }
/// <summary> /// Sends the frame to the XBee network. /// </summary> /// <param name="frame"></param> public void SendFrame(IXBeeFrame frame) { messageListToSend.Add(frame); }