Beispiel #1
0
        public override void OnEvent(DeviceEvents deviceEvents)
        {
            base.OnEvent(deviceEvents);

            foreach (DeviceEvent deviceEvent in deviceEvents.services)
            {
                if (deviceEvent.eventType == "start_scan")
                {
                    ScanSubdeviceNotify scanSubdeviceNotify = JsonUtil.ConvertDicToObject <ScanSubdeviceNotify>(
                        deviceEvent.paras);

                    if (subDevDiscoveryListener != null)
                    {
                        subDevDiscoveryListener.OnScan(scanSubdeviceNotify);
                    }
                }
                else if (deviceEvent.eventType == "add_sub_device_notify")
                {
                    SubDevicesInfo subDevicesInfo = JsonUtil.ConvertDicToObject <SubDevicesInfo>(
                        deviceEvent.paras);

                    OnAddSubDevices(subDevicesInfo);
                }
                else if (deviceEvent.eventType == "delete_sub_device_notify")
                {
                    SubDevicesInfo subDevicesInfo = JsonUtil.ConvertDicToObject <SubDevicesInfo>(
                        deviceEvent.paras);

                    OnDeleteSubDevices(subDevicesInfo);
                }
            }
        }
        /// <summary>
        /// 接收OTA事件处理
        /// </summary>
        /// <param name="deviceEvent">服务事件</param>
        public override void OnEvent(DeviceEvent deviceEvent)
        {
            if (otaListener == null)
            {
                Log.Info("otaListener is null");
                return;
            }

            if (deviceEvent.eventType == "version_query")
            {
                otaListener.OnQueryVersion();
            }
            else if (deviceEvent.eventType == "firmware_upgrade" || deviceEvent.eventType == "software_upgrade")
            {
                OTAPackage pkg = JsonUtil.ConvertDicToObject <OTAPackage>(deviceEvent.paras);

                // OTA单独起一个线程处理
                new Thread(new ThreadStart(new Action(() =>
                {
                    // to do 启动新线程要执行的代码
                    otaListener.OnNewPackage(pkg);
                }))).Start();
            }
        }