protected void NotifyStatusChanged(ModemStatus status) { if (StatusChanged != null) { StatusChanged(this, status); } }
public void RequestManufacturerTest() { var status = new ModemStatus { IsSuccess = false, State = "Not initialized", Manufacturer = "None", ModelName = string.Empty, SerialNumber = "SN xyz", SignalQuality = new SignalQuality { dBmW = 0, Percent = "0.0", IsValid = false }, Imsi = string.Empty, Imei = string.Empty, OperatorName = string.Empty }; var request = new ModemRequestContext { Response = status, Connection = _configuration }; var handler = new RequestManufaturerHandler(); var result = handler.Handle(request, "AT+GMI"); result.Should().NotBeNull(); result.Response.Manufacturer.Should().NotBeEmpty(); result.Response.IsSuccess.Should().BeTrue(); }
private static void OnStatusChanged(XBeeApi sender, ModemStatus status) { switch (status) { case ModemStatus.HardwareReset: Debug.Print(sender.Config.SerialNumber + " Hardware reset"); break; case ModemStatus.WatchdogTimerReset: Debug.Print(sender.Config.SerialNumber + " Software reset"); break; case ModemStatus.Associated: Debug.Print(sender.Config.SerialNumber + " Associated"); break; case ModemStatus.Disassociated: Debug.Print(sender.Config.SerialNumber + " Not associated"); break; default: Debug.Print(sender.Config.SerialNumber + " Status " + status); break; } }
protected override void OnStatusChange(ModemStatus mask, ModemStatus state) { if (mask.cts) { // CTS is PTT on from OTRSP _data.Ptt = state.cts; } }
public override void Parse(IPacketParser parser) { var value = parser.Read("Modem Status"); Status = value < (byte)ModemStatus.StackError ? (ModemStatus)value : ModemStatus.StackError; }
/// <summary> /// /// </summary> /// <returns></returns> protected override bool AfterOpen() { //frm.OnOpen(); ModemStatus m = GetModemStatus(); //frm.SetIndics(m.cts, m.dsr, m.rlsd, m.ring); return(true); }
public void XbeeEventReceived(IXBeeEvent xbeeEvent) { if (xbeeEvent is XBeeReceivePacketExplicitEvent rxMessage) { ZigBeeApsFrame apsFrame = new ZigBeeApsFrame { Cluster = (ushort)rxMessage.GetClusterId(), DestinationEndpoint = (byte)rxMessage.GetDestinationEndpoint(), Profile = (ushort)rxMessage.GetProfileId(), SourceEndpoint = (byte)rxMessage.GetSourceEndpoint(), SourceAddress = (ushort)rxMessage.GetNetworkAddress(), Payload = rxMessage.GetData().Select(item => (byte)item).ToArray() }; _zigBeeTransportReceive.ReceiveCommand(apsFrame); return; } // Handle dongle status messages if (xbeeEvent is XBeeModemStatusEvent modemStatus) { ModemStatus modemCurrentStatus = modemStatus.GetStatus(); switch (modemCurrentStatus) { case ModemStatus.COORDINATOR_STARTED: { _coordinatorStarted = true; SetNetworkState(ZigBeeTransportState.ONLINE); } break; case ModemStatus.DISASSOCIATED: { SetNetworkState(ZigBeeTransportState.OFFLINE); } break; case ModemStatus.HARDWARE_RESET: case ModemStatus.JOINED_NETWORK: case ModemStatus.NETWORK_SECURITY_KEY_UPDATED: case ModemStatus.WATCHDOG_TIMER_RESET: break; default: break; } return; } Log.Debug($"Unhandled XBee Frame: {xbeeEvent.ToString()}"); }
public void GetModemStatusTest() { var configuration = new ConnectConfiguration { ConnectionType = ConnectionType.Usb, BaudRate = int.Parse(ConfigurationManager.AppSettings["baudrate"]), PortName = ConfigurationManager.AppSettings["port"] }; var status = new ModemStatus { IsSuccess = false, State = "Not initialized", Manufacturer = "None", ModelName = string.Empty, SerialNumber = "SN xyz", SignalQuality = new SignalQuality { dBmW = 0, Percent = "0.0", IsValid = false }, Imsi = string.Empty, Imei = string.Empty, OperatorName = string.Empty }; var request = new ModemRequestContext { Response = status, Connection = configuration }; var commands = new Dictionary <string, AbstractModemCommandHandler> { { "AT", new RequestEchoHandler() }, { "AT+GMI", new RequestManufaturerHandler() }, { "AT+GMM", new RequestModelHandler() }, { "AT+CGMR", new RequestRevisionIdentificationHandler() } }; var results = new Dictionary <string, ModemRequestContext>(); foreach (var command in commands) { var commandString = command.Key; var commandClass = command.Value; var commandResult = commandClass.Handle(request, commandString); results.Add(commandString, commandResult); } }
/// <summary> /// Called when the value of IsConnected is changing. If the values are different, /// log the change and set the icon and tooltip for the system tray. If the new /// status is Offline, reboot the modem. /// </summary> private void OnStatusChanging(ModemStatus oldStatus, ModemStatus newStatus) { if (oldStatus != newStatus) { if (newStatus == ModemStatus.Online) { Program.LogMessage("Modem is now online."); _notifyIcon.Icon = Resources.Modem; } else { Program.LogMessage("Modem is now offline."); Program.LogMessage("Rebooting modem..."); RebootModem(); _notifyIcon.Icon = Resources.BadModem; } } }
private static void OnStatusChanged(XBeeApi sender, ModemStatus status) { switch (status) { case ModemStatus.HardwareReset: Debug.Print(sender.Config.SerialNumber + " Hardware reset"); break; case ModemStatus.WatchdogTimerReset: Debug.Print(sender.Config.SerialNumber + " Software reset"); break; case ModemStatus.Associated: Debug.Print(sender.Config.SerialNumber + " Associated"); break; case ModemStatus.Disassociated: Debug.Print(sender.Config.SerialNumber + " Not associated"); break; default: Debug.Print(sender.Config.SerialNumber + " Status " + status); break; } }
public virtual ModemRequestContext Handle(ModemRequestContext request, string param) { if (param == ModemCommand) { lock (_locker) { modemStatus = request.Response?.Clone(); manager.OnSerialPortOpened += OnSerialPortOpened; manager.OnStatusChanged += OnStatusChanged; manager.OnDataReceived += OnDataReceived; if (!manager.IsOpen) { manager.Open(request.Connection.PortName); } else { manager.Close(); manager.Open(request.Connection.PortName); } { while (received) { Monitor.Wait(_locker, TimeSpan.FromMilliseconds(Sleep)); } } manager.OnSerialPortOpened -= OnSerialPortOpened; manager.OnStatusChanged -= OnStatusChanged; manager.OnDataReceived -= OnDataReceived; var result = new ModemRequestContext { Connection = request.Connection, Response = modemStatus }; return(result); } } return(_nextHandler?.Handle(request, param)); }
/// <summary> /// /// </summary> /// <param name="c"></param> /// <param name="v"></param> protected override void OnStatusChange(ModemStatus c, ModemStatus v) { //frm.SetIndics(v.cts, v.dsr, v.rlsd, v.ring); }
protected virtual void OnStatusChange(ModemStatus mask, ModemStatus state) { }
//JH 1.3: Deleted OnRing() which was never called: use OnStatusChange instead (Thanks Jim Foster) /// <summary> /// Override this to take action when one or more modem status inputs change state /// </summary> /// <param name="mask">The status inputs that have changed state</param> /// <param name="state">The state of the status inputs</param> protected virtual void OnStatusChange(ModemStatus mask, ModemStatus state) { }
protected void NotifyStatusChanged(ModemStatus status) { if (StatusChanged != null) StatusChanged(this, status); }
public override string ToString() { var bld = new StringBuilder(); if ((byte)FrameType < 0x7F) { bld.AppendFormat("\r\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n"); } else { bld.AppendFormat("\r\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\r\n"); } bld.AppendFormat("Frame Type \t: {0}\r\n", FrameType.ToString()); if (FrameType == FrameTypes.RxModemStatus) { bld.AppendFormat("Modem Status \t: {0}\r\n", ModemStatus.ToString()); } if (FrameType == FrameTypes.RxTransmitStatus) { bld.AppendFormat("Retry Count \t: {0}\r\n", TransmitRetryCount); bld.AppendFormat("Transmit Status \t: {0}\r\n", DeliveryStatus); bld.AppendFormat("Discovery Status \t: {0}\r\n", DiscoveryStatus); } if (FrameType == FrameTypes.TxATCommand) { bld.AppendFormat("AT Command \t: {0}\r\n", ATCommandString); WritePayload(bld); } if (FrameType == FrameTypes.RxAtCommandResponse) { bld.AppendFormat("AT Command \t: {0}\r\n", ATCommandString); bld.AppendFormat("Sending Frame Id \t: {0}\r\n", FrameId); bld.AppendFormat("AT Status \t: {0}\r\n", ATCommandStatus); WritePayload(bld); } if (FrameType == FrameTypes.RxReceivePacket) { bld.AppendFormat("Length \t: {0}\r\n", FormatHex(Length)); bld.AppendFormat("Payload Length \t: {0}\r\n", FormatHex(Convert.ToUInt16(Length - 17))); bld.AppendFormat("Dest 64 Bit Addr \t: {0}\r\n", FormatHex(DestinationAddress64Bit)); bld.AppendFormat("Dest 16 Bit Addr \t: {0}\r\n", FormatHex(DestinationAddress16Bit)); bld.AppendFormat("Source End Point \t: {0:X2}\r\n", SourceEndPoint); bld.AppendFormat("Dest End Point \t: {0:X2}\r\n", DestinationEndPoint); bld.AppendFormat("Cluster ID \t: {0}\r\n", FormatHex(ClusterId)); bld.AppendFormat("Profile ID \t: {0}\r\n", FormatHex(ProfileId)); bld.AppendFormat("Receive Options \t: {0:X2}\r\n", ReceiveOptions); WritePayload(bld); } if (FrameType == FrameTypes.TxExplicitAddressCommand) { bld.AppendFormat("Frame ID \t: {0:X2}\r\n", FrameId); bld.AppendFormat("Dest 64 Bit Addr \t: {0}\r\n", FormatHex(DestinationAddress64Bit)); bld.AppendFormat("Dest 16 Bit Addr \t: {0}\r\n", FormatHex(DestinationAddress16Bit)); bld.AppendFormat("Source End Point \t: {0:X2}\r\n", SourceEndPoint); bld.AppendFormat("Dest End Point \t: {0:X2}\r\n", DestinationEndPoint); bld.AppendFormat("Cluster ID \t: {0}\r\n", FormatHex(ClusterId)); bld.AppendFormat("Profile ID \t: {0}\r\n", FormatHex(ProfileId)); bld.AppendFormat("Broadcast Radius \t: {0:X2}\r\n", BroadcastRadius); bld.AppendFormat("Transmit Options \t: {0:X2}\r\n", Options); bld.AppendFormat("Check Sum \t: {0:X2}\r\n", CheckSum); WritePayload(bld); } if ((byte)FrameType < 0x7F) { bld.AppendFormat(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n"); } else { bld.AppendFormat("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\r\n"); } bld.Append("\r\n"); return(bld.ToString()); }
/// <summary> /// Get the latest status from the modem. /// </summary> private void UpdateStatus() { ModemStatus = Modem.GetStatus(); }
internal ModemStatusChangedEventArgs(ModemStatus status) { Status = status; }
/// <summary> /// Method for deserializing the fields for the response </summary> public void Deserialize(int[] incomingData) { InitializeDeserializer(incomingData); _status = DeserializeModemStatus(); }
protected override void OnStatusChange(ModemStatus c, ModemStatus v) { frm.SetIndics(v.cts, v.dsr, v.rlsd, v.ring); }