Exemplo n.º 1
0
        /// <summary>
        /// 获取设备的总揽数据
        /// </summary>
        /// <param name="sites">场站编号集合</param>
        /// <returns></returns>
        public async Task <BaseResponse> GetDeviceOverViewAsync(List <int> sites, string GroupId)
        {
            var device = await _dr.FindWithOnline(a => sites.Contains(a.ProjectId.Value)).ToListAsync();

            //获取类型的分类以及分类下的子类型标示
            var Types = await _tr.Find(a => a.GroupId == GroupId && a.Parent == null).ToListAsync();

            if (Types == null || Types.Count == 0)
            {
                return(new BaseResponse {
                    Success = false, Message = "该组织没有添加类型"
                });
            }
            DeviceOverViewDto     dto  = new DeviceOverViewDto();
            List <DeviceTypeInfo> list = new List <DeviceTypeInfo>();

            foreach (var item in Types)
            {
                DeviceTypeInfo dti = new DeviceTypeInfo {
                    TypeId = item.Id, TypeName = item.TypeName, Icon = item.ICON
                };
                List <int> listType = await _tr.FindTypeChildAsync(item.Id);

                var online = device.Where(a => listType.Contains(a.TypeId) && (a.DeviceOnline != null && a.DeviceOnline.State == true)).Count();
                var num    = device.Where(a => listType.Contains(a.TypeId)).Count();
                dti.OnlineNum  = online;
                dti.Num        = num;
                dto.Num       += dti.Num;
                dto.OnlineNum += dti.OnlineNum;
                dto.TypeData.Add(dti);
            }
            return(new BResponse <DeviceOverViewDto> {
                Success = true, Message = "获取数据成功", Data = dto
            });
        }
        public byte[] HandDeviceControl(MasProtocol masProtocol, DeviceControlRequest deviceControl, ref string deviceCode, ref int commPort)
        {
            DeviceInfo                  deviceinfoobject = null;
            DeviceTypeInfo              devicetypeobject = null;
            NetworkDeviceInfo           netmacobject     = null;
            DeviceControlRequestCommand commandobject    = new DeviceControlRequestCommand();

            byte[] sendbuff = null;
            if (masProtocol == null || deviceControl == null)
            {
                return(sendbuff);
            }
            if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.DeviceControlRequest, deviceControl.DeviceCode))
            {
                return(sendbuff);
            }
            if (netmacobject.NetID > 0)
            {
                commPort      = deviceinfoobject.K3;
                deviceCode    = netmacobject.IP;
                commandobject = Basic.Framework.Common.ObjectConverter.Copy <DeviceControlRequest, DeviceControlRequestCommand>(deviceControl); //得到基础数据
                commandobject.OrderVersion = (byte)devicetypeobject.LC2;                                                                        //设备设备类型
                commandobject.def          = deviceinfoobject;
                sendbuff = commandobject.ToBytes();                                                                                             //得到通讯命令的返回Buffer数组
            }
            return(sendbuff);
        }
        public byte[] HandUpdateCancle(MasProtocol masProtocol, UpdateCancleRequest updateCancleRequest, ref string deviceCode)
        {
            DeviceInfo                 deviceinfoobject = null;
            DeviceTypeInfo             devicetypeobject = null;
            NetworkDeviceInfo          netmacobject     = null;
            UpdateCancleRequestCommand commandobject    = new UpdateCancleRequestCommand();

            byte[] sendbuff = null;
            if (masProtocol == null || updateCancleRequest == null)
            {
                return(sendbuff);
            }
            if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.DeviceControlRequest, updateCancleRequest.DeviceCode))
            {
                return(sendbuff);
            }
            if (netmacobject.NetID > 0)
            {
                deviceCode    = netmacobject.MAC;                                                                                                   //向下的发送的MAC地址
                commandobject = Basic.Framework.Common.ObjectConverter.Copy <UpdateCancleRequest, UpdateCancleRequestCommand>(updateCancleRequest); //得到基础数据

                commandobject.DeviceId    = updateCancleRequest.DeviceId;
                commandobject.HardVersion = updateCancleRequest.HardVersion;
                commandobject.FileVersion = updateCancleRequest.FileVersion;

                commandobject.def = deviceinfoobject;        // Framework.Common.ObjectConverter.DeepCopy<DeviceInfo>(deviceinfoobject);//得到分站的对象必须是深度拷贝;
                sendbuff          = commandobject.ToBytes(); //得到通讯命令的返回Buffer数组
                //if (sendbuff != null)
                //{
                //    sendbuff = Cache.GetPackages(sendbuff, netmacobject, deviceinfoobject, 2, CommandCodes.ExtendCommand, (byte)devicetypeobject.LC2);//通过当前网络模块进行打包
                //}
            }
            return(sendbuff);
        }
        public byte[] HandModificationDeviceAdress(MasProtocol masProtocol, ModificationDeviceAdressRequest modificationDeviceAdress, ref string deviceCode, ref int commPort)
        {
            DeviceInfo        deviceinfoobject = null;
            DeviceTypeInfo    devicetypeobject = null;
            NetworkDeviceInfo netmacobject     = null;
            ModificationDeviceAdressRequestCommand commandobject = new ModificationDeviceAdressRequestCommand();

            byte[] sendbuff = null;
            if (masProtocol == null || modificationDeviceAdress == null)
            {
                return(sendbuff);
            }
            if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.ModificationDeviceAdressRequest, modificationDeviceAdress.DeviceCode))
            {
                return(sendbuff);
            }
            if (netmacobject.NetID > 0)
            {
                commPort          = deviceinfoobject.K3;
                deviceCode        = netmacobject.IP;                                                                                                                                 //向下的发送的MAC地址
                commandobject     = Basic.Framework.Common.ObjectConverter.Copy <ModificationDeviceAdressRequest, ModificationDeviceAdressRequestCommand>(modificationDeviceAdress); //得到基础数据
                commandobject.def = deviceinfoobject;                                                                                                                                //得到分站的对象必须是深度拷贝
                sendbuff          = commandobject.ToBytes();                                                                                                                         //得到通讯命令的返回Buffer数组
            }
            return(sendbuff);
        }
        public byte[] HandQueryHistoryRealData(MasProtocol masProtocol, QueryHistoryRealDataRequest queryHistoryRealData, ref string deviceCode, ref int commPort)
        {
            DeviceInfo        deviceinfoobject = null;
            DeviceTypeInfo    devicetypeobject = null;
            NetworkDeviceInfo netmacobject     = null;
            QueryHistoryRealDataRequestCommand commandobject = new QueryHistoryRealDataRequestCommand();

            byte[] sendbuff = null;
            if (queryHistoryRealData == null)
            {
                return(sendbuff);
            }
            if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.QueryHistoryRealDataRequest, queryHistoryRealData.DeviceCode))
            {
                return(sendbuff);
            }
            if (netmacobject.NetID > 0)
            {
                commPort                   = deviceinfoobject.K3;
                deviceCode                 = netmacobject.IP;                                                                                                                     //向下的发送的MAC地址
                commandobject              = Basic.Framework.Common.ObjectConverter.Copy <QueryHistoryRealDataRequest, QueryHistoryRealDataRequestCommand>(queryHistoryRealData); //得到基础数据
                commandobject.def          = deviceinfoobject;                                                                                                                    //得到分站的对象必须是深度拷贝
                commandobject.SerialNumber = queryHistoryRealData.SerialNumber;
                sendbuff                   = commandobject.ToBytes();                                                                                                             //得到通讯命令的返回Buffer数组
                //if (sendbuff != null)
                //{
                //    sendbuff = Cache.GetPackages(sendbuff, netmacobject, deviceinfoobject, 2, CommandCodes.ExtendCommand, (byte)devicetypeobject.LC2);//通过当前网络模块进行打包
                //}
            }
            return(sendbuff);
        }
        public byte[] HandResetDeviceCommand(MasProtocol masProtocol, ResetDeviceCommandRequest resetDevice, ref string deviceCode, ref int commPort)
        {
            DeviceInfo                deviceinfoobject = null;
            DeviceTypeInfo            devicetypeobject = null;
            NetworkDeviceInfo         netmacobject     = null;
            ResetDeviceRequestCommand commandobject    = new ResetDeviceRequestCommand();

            byte[] sendbuff = null;
            if (resetDevice == null)
            {
                return(sendbuff);
            }
            if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.ResetDeviceCommandRequest, resetDevice.DeviceCode))
            {
                return(sendbuff);
            }
            if (netmacobject.NetID > 0)
            {
                commPort          = deviceinfoobject.K3;
                deviceCode        = netmacobject.IP;                                                                                                 //向下的发送的MAC地址
                commandobject     = Basic.Framework.Common.ObjectConverter.Copy <ResetDeviceCommandRequest, ResetDeviceRequestCommand>(resetDevice); //得到基础数据
                commandobject.def = deviceinfoobject;                                                                                                //得到分站的对象必须是深度拷贝
                sendbuff          = commandobject.ToBytes();                                                                                         //得到通讯命令的返回Buffer数组
            }
            return(sendbuff);
        }
        public byte[] HandSensorGradingAlarm(MasProtocol masProtocol, SetSensorGradingAlarmRequest sensorGradingAlarm, ref string deviceCode, ref int commPort)
        {
            DeviceInfo        deviceinfoobject = null;
            DeviceTypeInfo    devicetypeobject = null;
            NetworkDeviceInfo netmacobject     = null;
            SetSensorGradingAlarmRequestCommand commandobject = new SetSensorGradingAlarmRequestCommand();

            byte[] sendbuff = null;
            if (sensorGradingAlarm == null)
            {
                return(sendbuff);
            }
            if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.SetSensorGradingAlarmRequest, sensorGradingAlarm.DeviceCode))
            {
                return(sendbuff);
            }
            if (netmacobject.NetID > 0)
            {
                commPort          = deviceinfoobject.K3;
                deviceCode        = netmacobject.IP;                                                                                                                     //向下的发送的MAC地址
                commandobject     = Basic.Framework.Common.ObjectConverter.Copy <SetSensorGradingAlarmRequest, SetSensorGradingAlarmRequestCommand>(sensorGradingAlarm); //得到基础数据
                commandobject.def = deviceinfoobject;                                                                                                                    //得到分站的对象必须是深度拷贝
                sendbuff          = commandobject.ToBytes();                                                                                                             //得到通讯命令的返回Buffer数组
                //if (sendbuff != null)
                //{
                //    sendbuff = Cache.GetPackages(sendbuff, netmacobject, deviceinfoobject, 2, CommandCodes.ExtendCommand, (byte)devicetypeobject.LC2);//通过当前网络模块进行打包
                //}
            }
            return(sendbuff);
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="index"></param>
        /// <param name="tempDef"></param>
        /// <param name="decimalCount"></param>
        /// <param name="sensorlc"></param>
        private void GetSignCapacity(byte[] bytes, int index, DeviceInfo tempDef, ref byte decimalCount, ref ushort sensorlc)
        {
            decimalCount = 0;      //小数位数需要返回
            sensorlc     = 0xFFFF; //量程需要返回
            DeviceTypeInfo dev = null;
            short          LC1;
            float          LC2;
            ushort         tempValue;// = Convert.ToUInt16(Math.Abs(tempalarm[i]) * Math.Pow(10, decimalCount));

            sensorlc = 0;
            dev      = DeviceTypeListItem.Find(delegate(DeviceTypeInfo p) { return(p.Devid == tempDef.Devid); });
            if (dev != null)
            {
                LC1 = dev.LC;//高值
                if (string.IsNullOrEmpty(dev.Bz11))
                {
                    LC2 = 0;//默认为0
                }
                else
                {
                    LC2 = Convert.ToSingle(dev.Bz11);
                }
                decimalCount = Convert.ToByte(dev.Bz1);
            }
            else
            {
                decimalCount = 0;
                LC1          = 0;
                LC2          = 0;
                sensorlc     = 0;
                LogHelper.Error("测点号:" + tempDef.Point + ",未找到设备类型" + tempDef.Devid);
            }
            bytes[index - 1] |= (byte)((decimalCount & 0x03) << 4); //放到大类的高两位
            tempValue         = Convert.ToUInt16(Math.Abs(LC1) * Math.Pow(10, decimalCount));
            bytes[index + 34] = (byte)(tempValue & 0xFF);           //量程高值
            bytes[index + 35] = (byte)((tempValue >> 8) & 0xFF);    //量程高值
            if (LC1 < 0)
            {
                bytes[index + 35] |= 0x80;//量程高值
            }
            else
            {
                bytes[index + 35] &= 0x7F;//量程高值
            }
            tempValue = Convert.ToUInt16(Math.Abs(LC2) * Math.Pow(10, decimalCount));

            bytes[index + 36] |= (byte)(tempValue & 0xFF);        //量程低值
            bytes[index + 37] |= (byte)((tempValue >> 8) & 0xFF); //量程低值
            if (LC2 < 0)
            {
                bytes[index + 37] |= 0x80;//量程高值
            }
            else
            {
                bytes[index + 37] &= 0x7F;//量程高值
            }
        }
        /// <summary>
        /// 处理回发的数据体,以分站为对象
        /// </summary>
        /// <param name="data"></param>
        /// <param name="protocolData"></param>
        public void HandleDeviceData(byte[] data, MasProtocol protocolData)
        {
            DeviceTypeInfo dev = null;

            dev = Cache.CacheManager.QueryFrist <DeviceTypeInfo>(p => p.Devid == def.Devid, true);
            if (dev != null)
            {
                DataControlByMonitor(data, protocolData, (byte)dev.LC2);
            }
        }
Exemplo n.º 10
0
        public void DeviceTypeInfoObjectTest()
        {
            DeviceTypeInfo sample = new DeviceTypeInfo();

            sample.id                     = "my id";
            sample.classId                = "device";
            sample.description            = "my device";
            sample.metadata               = "test";
            sample.deviceInfo             = new DeviceInfo();
            sample.deviceInfo.description = "my device";

            Assert.AreEqual("my id", sample.id);
            Assert.AreEqual("device", sample.classId);
            Assert.AreEqual("my device", sample.description);
            Assert.AreEqual("my device", sample.deviceInfo.description);
            Assert.AreEqual("test", sample.metadata);
        }
Exemplo n.º 11
0
        protected HidManager()
        {
            _ble = new DeviceTypeInfo()
            {
                GetDeviceKeysCallback   = GetBleDeviceKeys,
                TryCreateDeviceCallback = TryCreateBleDevice
            };

            _hid = new DeviceTypeInfo()
            {
                GetDeviceKeysCallback   = GetHidDeviceKeys,
                TryCreateDeviceCallback = TryCreateHidDevice
            };

            _serial = new DeviceTypeInfo()
            {
                GetDeviceKeysCallback   = GetSerialDeviceKeys,
                TryCreateDeviceCallback = TryCreateSerialDevice
            };
        }
        public byte[] HandTimeSynchronization(MasProtocol masProtocol, TimeSynchronizationRequest timeSynchronization, ref string deviceCode, ref int commPort)
        {
            DeviceTypeInfo devicetypeobject = null;

            DeviceInfo        deviceinfoobject = null;
            NetworkDeviceInfo netmacobject     = null;
            TimeSynchronizationRequestCommand commandobject = new TimeSynchronizationRequestCommand();

            byte[] sendbuff = null;
            if (timeSynchronization == null)
            {
                return(sendbuff);
            }
            if (timeSynchronization.DeviceCode.Length < 4)
            {//服务端只发下了分站号,自动生成分站的测点号
                timeSynchronization.DeviceCode = timeSynchronization.DeviceCode.PadLeft(3, '0') + "0000";
            }
            if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.TimeSynchronizationRequest, timeSynchronization.DeviceCode))
            {
                return(sendbuff);
            }
            lock (Cache.LockWorkNet)//用缓存的连接号和接收时间进行更新
            {
                CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == netmacobject.IP); });
                if (curnet != null)
                {
                    netmacobject.NetID = curnet.NetID;
                }
            }
            if (netmacobject.NetID > 0)
            {
                commPort          = timeSynchronization.CommPort;
                deviceCode        = netmacobject.IP;                                                                                                                  //向下的发送的MAC地址
                commandobject     = Basic.Framework.Common.ObjectConverter.Copy <TimeSynchronizationRequest, TimeSynchronizationRequestCommand>(timeSynchronization); //得到基础数据
                commandobject.def = deviceinfoobject;                                                                                                                 //得到分站的对象必须是深度拷贝
                sendbuff          = commandobject.ToBytes();                                                                                                          //得到通讯命令的返回Buffer数组
            }
            return(sendbuff);
        }
        private bool GetDeviceObject(ref DeviceInfo deviceInfoObject, ref DeviceTypeInfo deviceTypeObject, ref NetworkDeviceInfo netMacObject, ProtocolType pType, string deviceCode)
        {
            string ipstr = "";
            List <NetworkDeviceInfo> lstNet = new List <NetworkDeviceInfo>();

            deviceInfoObject = Cache.CacheManager.GetItemByKey <DeviceInfo>(deviceCode, true);//得到对应的分站对象
            if (deviceInfoObject == null)
            {
                LogHelper.Info("未找到分站【" + deviceCode + "】:" + pType.ToString());
                return(false);
            }
            Point  = deviceInfoObject.Point; //用于外部显示分站号
            ipstr  = deviceInfoObject.Jckz2; //获取IP
            lstNet = Cache.CacheManager.Query <NetworkDeviceInfo>(p => (p.IP == ipstr) && (p.Upflag == "0"), true);
            if (lstNet.Count > 0)
            {
                netMacObject = lstNet[0];
            }
            else
            {
                LogHelper.Info("未找到分站【" + deviceCode + "】对应的网络地址【" + deviceInfoObject.Jckz2 + "】:" + pType.ToString());
                return(false);
            }
            lock (Cache.LockWorkNet)//用缓存的连接号进行更新
            {
                CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == ipstr); });
                if (curnet != null)
                {
                    netMacObject.NetID = curnet.NetID;
                }
            }
            deviceTypeObject = Cache.CacheManager.GetItemByKey <DeviceTypeInfo>(deviceInfoObject.Devid, true);//按照devid搜索对象
            if (deviceTypeObject == null)
            {
                LogHelper.Info("未找到分站【" + deviceCode + "】对应的设备类型【" + deviceInfoObject.Devid + "】:" + pType.ToString());
                return(false);
            }
            return(true);
        }
        public byte[] HandInitialize(MasProtocol masProtocol, InitializeRequest Initialize, ref string deviceCode, ref int commPort)
        {
            DeviceInfo               deviceinfoobject = null;
            DeviceTypeInfo           devicetypeobject = null;
            NetworkDeviceInfo        netmacobject     = null;
            InitializeRequestCommand commandobject    = new InitializeRequestCommand();

            byte[] sendbuff = null;
            if (Initialize == null)
            {
                return(sendbuff);
            }
            if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.InitializeRequest, Initialize.DeviceCode))
            {
                return(sendbuff);
            }
            if (netmacobject.NetID > 0)
            {
                commPort      = deviceinfoobject.K3;
                deviceCode    = netmacobject.IP;                                                                                       //向下的发送的MAC地址
                commandobject = Basic.Framework.Common.ObjectConverter.Copy <InitializeRequest, InitializeRequestCommand>(Initialize); //得到基础数据
                commandobject.OrderVersion       = (byte)devicetypeobject.LC2;                                                         //设备设备类型
                commandobject.def                = deviceinfoobject;
                commandobject.DeviceListItem     = Cache.CacheManager.Query <DeviceInfo>(p => p.Fzh == deviceinfoobject.Fzh, true);
                commandobject.DeviceTypeListItem = Cache.CacheManager.GetAll <DeviceTypeInfo>(true);
                if (commandobject.DeviceListItem == null)
                {
                    commandobject.DeviceListItem = new List <DeviceInfo>();
                }
                if (commandobject.DeviceTypeListItem == null)
                {
                    commandobject.DeviceTypeListItem = new List <DeviceTypeInfo>();
                }
                sendbuff = commandobject.ToBytes();//得到通讯命令的返回Buffer数组
            }

            return(sendbuff);
        }
Exemplo n.º 15
0
        IEnumerable <Device> GetDevices(DeviceTypeInfo type)
        {
            var _deviceList             = type.DeviceList;
            var devicesLock             = type.DevicesLock;
            var getDeviceKeysCallback   = type.GetDeviceKeysCallback;
            var tryCreateDeviceCallback = type.TryCreateDeviceCallback;

            Device[] deviceListArray;

            lock (devicesLock)
            {
                object[] devices   = getDeviceKeysCallback();
                object[] additions = devices.Except(_deviceList.Keys).ToArray();
                object[] removals  = _deviceList.Keys.Except(devices).ToArray();

                if (additions.Length > 0)
                {
                    int completedAdditions = 0;

                    foreach (object addition in additions)
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(key =>
                        {
                            Device device;
                            bool created = tryCreateDeviceCallback(key, out device);

                            if (created)
                            {
                                // By not adding on failure, we'll end up retrying every time.
                                lock (_deviceList)
                                {
                                    _deviceList.Add(key, device);
                                    HidSharpDiagnostics.Trace("Detected a new device: {0}", key);
                                }
                            }

                            lock (_deviceList)
                            {
                                completedAdditions++; Monitor.Pulse(_deviceList);
                            }
                        }), addition);
                    }

                    lock (_deviceList)
                    {
                        while (completedAdditions != additions.Length)
                        {
                            Monitor.Wait(_deviceList);
                        }
                    }
                }

                foreach (object key in removals)
                {
                    _deviceList.Remove(key);
                    HidSharpDiagnostics.Trace("Detected a device removal: {0}", key);
                }
                deviceListArray = _deviceList.Values.ToArray();
            }

            return(deviceListArray);
        }
        public byte[] HandQueryBatteryRealData(MasProtocol masProtocol, QueryBatteryRealDataRequest batteryRealData, ref string deviceCode, ref int commPort)
        {
            List <NetworkDeviceInfo> lstNet = new List <NetworkDeviceInfo>();
            DeviceInfo                    deviceinfoobject = null;
            DeviceTypeInfo                devicetypeobject = null;
            NetworkDeviceInfo             netmacobject     = null;
            BatteryRealDataRequestCommand commandobject    = new BatteryRealDataRequestCommand();

            byte[] sendbuff = null;
            if (batteryRealData == null)
            {
                return(sendbuff);
            }
            if (batteryRealData.DevProperty == ItemDevProperty.Switches)
            {//如果是交换机的操作,仅获取对应的网络地址即可。
                lstNet = Cache.CacheManager.Query <NetworkDeviceInfo>(p => (p.MAC == batteryRealData.DeviceCode) && (p.Upflag == "1"), true);
                if (lstNet.Count > 0)
                {
                    netmacobject = lstNet[0];
                }
                //netmacobject = Cache.CacheManager.GetItemByKey<NetworkDeviceInfo>(batteryRealData.DeviceCode, true);//按照MAC搜索对象
                if (netmacobject == null)
                {
                    LogHelper.Error("查询交换机的电源,未找到对应的IP地址【" + batteryRealData.DeviceCode + "】");
                    return(sendbuff);
                }
                lock (Cache.LockWorkNet)//用缓存的连接号和接收时间进行更新
                {
                    CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == netmacobject.Bz6); });
                    if (curnet != null)
                    {
                        netmacobject.NetID = curnet.NetID;
                    }
                }
            }
            else
            {
                if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.QueryBatteryRealDataRequest, batteryRealData.DeviceCode))
                {
                    return(sendbuff);
                }
            }
            if (netmacobject.NetID > 0)
            {
                if (batteryRealData.DevProperty == ItemDevProperty.Switches)
                {
                    deviceCode = netmacobject.Bz6;//向下的发送的MAC地址
                    commPort   = 1;
                }
                else
                {
                    commPort = deviceinfoobject.K3;

                    deviceCode = netmacobject.IP;                                                                                                          //向下的发送的MAC地址
                }
                commandobject = Basic.Framework.Common.ObjectConverter.Copy <QueryBatteryRealDataRequest, BatteryRealDataRequestCommand>(batteryRealData); //得到基础数据
                if (devicetypeobject != null)
                {
                    commandobject.OrderVersion = (byte)devicetypeobject.LC2;
                }
                commandobject.def          = deviceinfoobject; // Framework.Common.ObjectConverter.DeepCopy<DeviceInfo>(deviceinfoobject);//得到分站的对象必须是深度拷贝
                commandobject.NetMacObject = netmacobject;
                sendbuff = commandobject.ToBytes();            //得到通讯命令的返回Buffer数组
            }
            return(sendbuff);
        }
Exemplo n.º 17
0
        public static void Main(string[] args)
        {
            string apiKey            = "";
            string authToken         = "";
            string managedDeviceType = "demotest";
            string managedDeviceId   = "1234";

            if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(authToken))
            {
                Console.Write("please Enter API Key : ");
                apiKey = Console.ReadLine();
                Console.WriteLine();
                Console.Write("Please Enter Auth Token : ");
                authToken = Console.ReadLine();
            }
            IBMWIoTP.ApiClient client = new IBMWIoTP.ApiClient(apiKey, authToken);
            client.Timeout = 5000;
            try {
                //Organization

                Console.WriteLine("get org info");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetOrganizationDetail()));

                //Bulk Operations

                Console.WriteLine("get all device list");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetAllDevices()));

                IBMWIoTP.RegisterDevicesInfo [] bulk = new IBMWIoTP.RegisterDevicesInfo[1];
                var info = new IBMWIoTP.RegisterDevicesInfo();
                info.deviceId   = "123qwe";
                info.typeId     = managedDeviceType;
                info.authToken  = "1qaz2wsx3edc4rfv";
                info.deviceInfo = new IBMWIoTP.DeviceInfo();
                info.location   = new IBMWIoTP.LocationInfo();
                info.metadata   = new {};
                bulk[0]         = info;

                Console.WriteLine("get Bulk reg ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.RegisterMultipleDevices(bulk)));

                IBMWIoTP.DeviceListElement [] removeBulk = new IBMWIoTP.DeviceListElement[1];
                var del = new IBMWIoTP.DeviceListElement();
                del.deviceId = "123qwe";
                del.typeId   = managedDeviceType;

                removeBulk[0] = del;
                Console.WriteLine("get Bulk remove ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.DeleteMultipleDevices(removeBulk)));

                //Device Types

                Console.WriteLine("GetAllDeviceTypes ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetAllDeviceTypes()));

                DeviceTypeInfo devty = new DeviceTypeInfo();
                devty.classId    = "Gateway";
                devty.deviceInfo = new DeviceInfo();
                devty.id         = "gatewaypi";
                devty.metadata   = new {};
                Console.WriteLine("RegisterDeviceType");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.RegisterDeviceType(devty)));

                Console.WriteLine("UpdateDeviceType ");
                var u = new IBMWIoTP.DeviceTypeInfoUpdate();
                u.description = "test";
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.UpdateDeviceType("gatewaypi", u)));

                Console.WriteLine("GetDeviceType ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceType("gatewaypi")));

                //Devices

                Console.WriteLine("ListDevices");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.ListDevices(managedDeviceType)));

                string newDeviceId = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                var    newdevice   = new RegisterSingleDevicesInfo();
                newdevice.deviceId   = newDeviceId;
                newdevice.authToken  = "testtest";
                newdevice.deviceInfo = new IBMWIoTP.DeviceInfo();
                newdevice.location   = new IBMWIoTP.LocationInfo();
                newdevice.metadata   = new {};
                Console.WriteLine("RegisterDevice");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.RegisterDevice("gatewaypi", newdevice)));

                var update = new IBMWIoTP.UpdateDevicesInfo();
                update.deviceInfo = new IBMWIoTP.DeviceInfo();
                Console.WriteLine("UpdateDeviceInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.UpdateDeviceInfo("gatewaypi", newDeviceId, update)));

                Console.WriteLine("GetDeviceInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceInfo("gatewaypi", newDeviceId)));

                Console.WriteLine("GetGatewayConnectedDevice");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetGatewayConnectedDevice("gatewaypi", newDeviceId)));

                Console.WriteLine("GetDeviceLocationInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceLocationInfo("gatewaypi", newDeviceId)));

                Console.WriteLine("UpdateDeviceLocationInfo");
                var loc = new IBMWIoTP.LocationInfo();
                loc.accuracy         = 1;
                loc.measuredDateTime = DateTime.Now.ToString("o");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.UpdateDeviceLocationInfo("gatewaypi", newDeviceId, loc)));

                Console.WriteLine("GetDeviceManagementInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementInfo(managedDeviceType, managedDeviceId)));

                Console.WriteLine("UnregisterDevice");
                client.UnregisterDevice("gatewaypi", newDeviceId);


                Console.WriteLine("DeleteDeviceType ");
                client.DeleteDeviceType("gatewaypi");


                Console.WriteLine("AddDeviceDiagLogs");
                var log = new IBMWIoTP.LogInfo();
                log.message  = "test";
                log.severity = 1;

                client.AddDeviceDiagLogs(managedDeviceType, managedDeviceId, log);

                Console.WriteLine("GetAllDiagnosticLogs");
                var logResult = client.GetAllDiagnosticLogs(managedDeviceType, managedDeviceId);
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(logResult));



                Console.WriteLine("GetDiagnosticLog");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDiagnosticLog(managedDeviceType, managedDeviceId, logResult[0]["id"])));

                Console.WriteLine("DeleteDiagnosticLog");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.DeleteDiagnosticLog(managedDeviceType, managedDeviceId, logResult[0]["id"])));

                Console.WriteLine("ClearAllDiagnosticLogs");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.ClearAllDiagnosticLogs(managedDeviceType, managedDeviceId)));



                Console.WriteLine("AddErrorCode");
                var err = new IBMWIoTP.ErrorCodeInfo();
                err.errorCode = 0;
                err.timestamp = "";
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.AddErrorCode(managedDeviceType, managedDeviceId, err)));

                Console.WriteLine("GetDeviceErrorCodes");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceErrorCodes(managedDeviceType, managedDeviceId)));

                Console.WriteLine("ClearDeviceErrorCodes");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.ClearDeviceErrorCodes(managedDeviceType, managedDeviceId)));

                Console.WriteLine("Problem ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceConnectionLogs(managedDeviceType, managedDeviceId)));

                Console.WriteLine("data usage ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDataUsage("2016", "2016", false)));


                Console.WriteLine("Service Status");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetServiceStatus()));

                Console.WriteLine("lastEvents");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetLastEvents(managedDeviceType, managedDeviceId)));

                Console.WriteLine("lastEvents of type");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetLastEventsByEventType(managedDeviceType, managedDeviceId, "test")));


                Console.WriteLine("GetAllDeviceManagementRequests");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetAllDeviceManagementRequests()));

                Console.WriteLine("InitiateDeviceManagementRequest");
                IBMWIoTP.DeviceMgmtparameter [] param = new IBMWIoTP.DeviceMgmtparameter[1];
                IBMWIoTP.DeviceMgmtparameter    p     = new IBMWIoTP.DeviceMgmtparameter();
                p.name   = "rebootAfter";
                p.value  = "100";
                param[0] = p;
                IBMWIoTP.DeviceListElement [] deviceList = new IBMWIoTP.DeviceListElement[1];
                IBMWIoTP.DeviceListElement    ele        = new IBMWIoTP.DeviceListElement();
                ele.typeId    = managedDeviceType;
                ele.deviceId  = managedDeviceId;
                deviceList[0] = ele;
                var response = client.InitiateDeviceManagementRequest("device/reboot", param, deviceList);             //new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<dynamic>(jsonResponse);
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(response));
                string id = response["reqId"];

                Console.WriteLine("GetDeviceManagementRequest");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementRequest(id)));

                Console.WriteLine("GetDeviceManagementRequestStatus");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementRequestStatus(id)));

                Console.WriteLine("GetDeviceManagementRequestStatus");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementRequestStatus(id, ele.typeId, ele.deviceId)));

                Console.WriteLine("DeleteDeviceManagementRequest");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.DeleteDeviceManagementRequest(id)));

                Console.WriteLine("weather");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceLocationWeather(managedDeviceType, managedDeviceId)));
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
            Console.Write("Press any key to exit . . . ");
            Console.ReadKey();
        }
Exemplo n.º 18
0
 public override int GetHashCode()
 {
     return(SerialNumber.GetHashCode() ^ DeviceTypeInfo.GetHashCode());
 }