} // SendUnencryptedOTA /// <summary>Sends a Request to given cluster and returns any data that /// comes back. This method is usually used for a table read.</summary> /// <param name="TargetAddress">Short address of device to send the message to</param> /// <param name="Msg"></param> /// <returns></returns> // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 01/31/08 mcm 1.0.x Initial Release // 09/15/08 AF Replaced ItronC177 with ItronEZSP because // the interface names changed in the new version // of the EZSP dlls. // 10/26/12 PGH Replaced EZSP with C177App // 09/17/15 jrf 4.21.04 616082 Added in a monitor in order to synchronize communication // with the beacon timer. public override ZigbeeResult SendDataRequest(ushort TargetAddress, byte[] Msg) { ZigbeeResult Result = ZigbeeResult.SUCCESS; PauseIntermittentBeacons(); Monitor.Enter(C177App); try { if (null != Msg) { m_Logger.WriteLine(Logger.LoggingLevel.Protocol, "Sending data request to address " + TargetAddress.ToString("X4", CultureInfo.InvariantCulture)); try { C177App.SendDataRequest(Msg); } catch (Exception e) { m_Logger.WriteException(this, e); Result = ZigbeeResult.ERROR; } } } finally { Monitor.Exit(C177App); } ResumeIntermittentBeacons(); return(Result); } // SendDataRequest
/// <summary> /// Opens the port passed in as a parameter. /// </summary> /// <param name="portName"> /// The communication port to open. /// </param> /// <exception cref="CommPortException"> /// Thrown when a port failure occurs. /// </exception> /// <example> /// <code> /// Communication comm = new Communication(); /// comm.OpenPort("COM4:"); /// </code> /// </example> /// Revision History /// MM/DD/YY who Version Issue# Description /// -------- --- ------- ------ --------------------------------------- /// 01/31/08 mcm 1.0.x N/A Created /// 05/15/08 AF 1.50 Added call to EnableDecryptedDebugOuput /// for debug tool CommOps.exe. This does not /// affect performance unless EthDebugInfo.txt /// is present in the Debug folder /// 09/15/08 AF Replaced C177 with EZSP because the interface /// names changed in the new version of the EZSP dlls. /// 04/09/09 AF 2.20.00 Added code to distinguish between an Itron ZBCR /// and a Telegesis dongle /// 01/07/11 AF 2.45.22 Added text for Telegesis dongle /// /// 10/17/12 PGH 2.70.36 Replaced EZSP with C177App /// public override void OpenPort(string portName) { // If we're already connected, we don't need to do anything. if (!m_bConnected) { try { if (!C177App.IsConnected) { C177App.Connect(portName); m_bConnected = true; m_PortName = portName; } else { m_Logger.WriteDetail(Logger.LoggingLevel.ZigBeeProtocol, "Failed to connect to the BeltClip radio/Telegesis dongle."); m_PortName = ""; } } catch (Exception e) { m_Logger.WriteDetail(Logger.LoggingLevel.ZigBeeProtocol, "Failed to connect to the BeltClip radio/Telegesis dongle"); m_Logger.WriteException(this, e); m_bConnected = false; m_PortName = ""; } } }
} // Start /// <summary>Stops the Radio. </summary> /// // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 01/31/08 mcm 1.0.x Initial Release // 09/26/08 AF Added implementation // 10/06/08 AF 2.00 Commented out the WaitEvent() and increased // the amount of Sleep time to increase the // success rate. // // 10/17/12 PGH 2.70.36 Replaced EZSP with C177App // public override void Stop() { if (C177App.IsJoined) { C177App.LeaveNetwork(); } } // Stop
} // Stop /// <summary> /// Find the Networks around the radio /// </summary> /// <param name="ScanChannels">Packed bits representing the channels /// to search. Only channels 15-26 are valid, so only bits 15 (0x800) /// through bit 26 (0x4000000). Note that bits are 0 indexed, so /// channel 0 = 0x01.</param> /// <param name="Networks">Returned array of found networks</param> /// <param name="Fast">Indicates whether or not the duration period /// used during scan should be set to a small number.</param> /// <returns>ZigbeeResult indicating success of search</returns> /// // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 01/31/08 mcm 1.0.x Initial Release // 09/08/08 AF Increased the Sleep() to give the scan // enough time to complete. In HH-Pro we // weren't getting many channel 25 networks // 08/24/09 AF 2.21.03 138987 Replaced the Sleep() with a WaitEvent() // so that we will wait only as long as necessary // // 10/17/12 PGH 2.70.36 Replaced EZSP with C177App // 09/17/15 jrf 4.21.04 616082 Added a fast parameter to cause scan duration to // be set to a lower number of periods (speeds scan up) // and also added in a monitor in order to synchronize // communication with the beacon timer. // 11/03/15 jrf 4.22.00 629782 Adding null referenced checks for m_NetworkList public override ZigbeeResult FindNetworks(uint ScanChannels, out ZigbeeNetwork[] Networks, bool Fast = false) { ZigbeeResult Result = ZigbeeResult.SUCCESS; EZSPScanDuration ScanDuration = EZSPScanDuration.ScanPeriodX33; PauseIntermittentBeacons(); Monitor.Enter(C177App); try { if (Fast) { ScanDuration = EZSPScanDuration.ScanPeriodX2; } Networks = new ZigbeeNetwork[0]; m_Logger.WriteDetail(this, "Searching for Zigbee Networks"); if (null != m_NetworkList) { m_NetworkList.Clear(); } try { m_NetworkList = C177App.ScanForDevices((ZigBeeChannels)ScanChannels, ScanDuration); if (null != m_NetworkList) { m_NetworkList.Sort(); Networks = m_NetworkList.ToArray(); } } catch (Exception e) { m_Logger.WriteException(this, e); Result = ZigbeeResult.ERROR; } } finally { Monitor.Exit(C177App); } ResumeIntermittentBeacons(); return(Result); } // FindNeworks
/// <summary>Starts the Radio. Returns a bool indicating success. /// </summary> /// <param name="MAC">MAC address for the radio</param> /// <param name="LogicalType">The type of device to configure. When /// joined to a cell relay, this should be a router, otherwise this /// should be a coordinator</param> /// <param name="ScanChannels">Packed bits representing the channels /// to search. Only channels 15-26 are valid, so only bits 15 (0x800) /// through bit 26 (0x4000000). Note that bits are 0 indexed, so /// bit 0 = 0x01.</param> /// <param name="ExPanID">The 8 byte extended Pan ID you want to start /// with. This value can be 0, which will cause the radio to either /// assign one at random or join the first suitable network it finds /// depending on the LogicalType.</param> /// <returns>True if the radio exists and was successfully started</returns> /// // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 01/31/08 mcm 1.0.x Initial Release // 06/17/08 AF 1.50.37 Changed to read the link key from the registry // 09/15/08 AF Replaced C177 with EZSP because // the interface names changed in the new version // of the EZSP dlls. // 10/07/08 AF 121097 Modified the filter on channel. We should allow // any valid channel // 01/26/11 AF 2.45.26 158436 Integration of new ezsp library to support secure rejoin. // // 10/17/12 PGH 2.70.36 Replaced EZSP with C177App // 09/17/15 jrf 4.21.04 616082 Sending a burst of beacons before joining and // starting intermittent beacons if method is successful. public override ZigbeeResult Start(ulong MAC, ulong ExPanID, ZigbeeLogicalType LogicalType, uint ScanChannels) { ZigbeeResult Result = ZigbeeResult.SUCCESS; if (!m_bConnected) { Result = ZigbeeResult.NOT_CONNECTED; } else { try { if (C177App.IsJoined) { C177App.LeaveNetwork(); } byte[] NetworkKey = GetSecurityKey(false); //Need to wake up troublesome devices before we attempt to join. SendBeaconBurst((uint)(0x1 << (int)ScanChannels)); C177App.Rejoin(ConvertLogicalTypeToEmberType(LogicalType), ExPanID, (byte)ScanChannels, NetworkKey); if (!C177App.IsJoined) { Result = ZigbeeResult.ERROR; } } catch (Exception e) { m_Logger.WriteDetail(this, "BeltClipRadio.Start exception"); m_Logger.WriteException(this, e); Result = ZigbeeResult.ERROR; throw e; } } if (ZigbeeResult.SUCCESS == Result) { //This will keep troublesome devices communicative. StartIntermittentBeacons(); } return(Result); } // Start
/// <summary> /// Closes the communication port. /// </summary> /// <exception cref="CommPortException"> /// Thrown when a port failure occurs. /// </exception> /// <example> /// <code> /// Communication comm = new Communication(); /// comm.OpenPort("COM4:"); /// comm.ClosePort(); /// comm.Dispose(); /// </code> /// </example> // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 01/31/08 mcm 1.0.x N/A Created // 09/04/08 AF Added compiler directive to disable Bluetooth // stuff if not CE. // 09/15/08 AF Replaced C177 with EZSP because the interface // names changed in the new version of the EZSP dlls. // 10/17/12 PGH 2.70.36 Replaced EZSP with C177App // 09/17/15 jrf 4.21.04 616082 Stops the beaconing when port is closed. public override void ClosePort() { //Port is closing, so we should stop beacons. StopIntermittentBeacons(); C177App.LeaveNetwork(); if (C177App != null && C177App.IsConnected) { C177App.Disconnect(); C177App.StopLogging(); } #if (WindowsCE) if (false != m_blnUsingBluetooth) { BToothCe.BT_Deinit(); } #endif m_bConnected = false; }
/// <summary> /// Starts EZSP level logging /// </summary> /// <param name="filePath">The path to the log file</param> /// <param name="logLevel">The logging level</param> // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 03/13/13 RCG 2.70.72 327410 Created public void StartLogging(string filePath, EZSPLogLevels logLevel) { C177App.StartLogging(filePath, logLevel); }