예제 #1
0
        public void Init()
        {
            var token = HttpUtil.LoginAsync($"http://{cfg.AppSettings["serverUrl"]}/inIoT/userServer/tologin",
                                            new LoginUser()
            {
                username = "******",
                pwd      = "12345"
            });

            token.Wait();

            if (string.IsNullOrEmpty(token.Result))
            {
                LogHelper.Error($"LoginAsync {cfg.AppSettings["serverUrl"]} error");
                return;
            }
            ServerToken = JsonSrialize.Desrialize <LoginResponse>(token.Result).data.token;

            var req1 = HttpUtil.GetAsync <GroupResResponse>($"http://{cfg.AppSettings["serverUrl"]}/inIoT/devServer/tagGroup/G433635714868056",
                                                            ServerToken);

            req1.Wait();
            var req = HttpUtil.PostAsync($"http://{cfg.AppSettings["serverUrl"]}/inIoT/devServer/deviceRes",
                                         JsonSrialize.Srialize(new DevModel()
            {
                dvIsid      = "dfsdf",
                dvName      = "ssssssf",
                dvTypeCode  = "15",
                managerIsid = cfg.AppSettings["managerIsid"],
                nodeIsid    = "100114",
                addrRes     = new MqttCommon.Setup.AddResource()
                {
                    communicationType = 1,
                    dvAddr1           = "1.1.1.1",
                    dvAddr2           = "2222"
                }
            }), SuperBCenter.ServerToken);


            SdkMgr.Inst.Init().Wait();
            //   SuperBRepertory.Inst.SynchronizeDb().Wait();

            //    MqttMgr.Inst.Init().Wait();

            //   SetupMgr.Inst.Init().Wait();
            return;


            string ss = JsonSrialize.Srialize(new DevModel[]
            {
                new DevModel()
                {
                    addrRes = new AddResource()
                    {
                        communicationType = 0,
                        connectParam1     = "9600",
                        connectParam2     = "8",
                        connectParam3     = "1",
                        connectParam4     = "1",
                        dvAddr1           = "3",
                        dvAddr2           = "1",
                    },
                    dvName      = "sdf",
                    dvTypeCode  = "10",
                    managerIsid = "mgrTest2",
                    nodeIsid    = "zhc-yq",
                    dvIsid      = Uuid.Create16Token(),
                }
            });

            HttpUtil.PostAsync("http://10.10.12.164:8080/inIoT/devServer/deviceRes/list", ss, token.Result);
        }
예제 #2
0
        private async Task HandleAttribute(List <BStruBase> atts)
        {
            PlateformDevs pl = new PlateformDevs();
            ConcurrentDictionary <string, List <TagRes> > groupBuffer = new ConcurrentDictionary <string, List <TagRes> >();

            foreach (var att in atts)
            {
                switch (att.Type)
                {
                case EnumType.STATION:
                {
                    if (!(att is TStation st))
                    {
                        continue;
                    }
                    await SuperBRepertory.Inst.UpdateOrAddStation(st);
                }
                break;

                case EnumType.DEVICE:
                {
                    if (!(att is TDevice dev))
                    {
                        continue;
                    }
                    await SuperBRepertory.Inst.UpdateOrAddDevice(dev);
                }
                break;

                case EnumType.AI:
                case EnumType.AO:
                case EnumType.DI:
                case EnumType.DO:
                case EnumType.STRIN:
                {
                    await SuperBRepertory.Inst.BeginUpdateOrAddTag(att, async (tag, groupIsid, change) =>
                        {
                            if (change == MqttCommon.ChangeType.Add)
                            {
                                groupBuffer.AddOrUpdate(groupIsid, new List <TagRes>(),
                                                        (oKey, oVal) => { oVal.Add(tag.Tag); return(oVal); });
                            }
                            else if (change == MqttCommon.ChangeType.Update)
                            {
                                return(true);
                            }

                            return(false);
                        });
                }
                break;

                default:
                    break;
                }

                foreach (var pair in groupBuffer)
                {
                    var req = await HttpUtil.GetAsync <GroupResResponse>(
                        $"http://{cfg.AppSettings["serverUrl"]}/inIoT/devServer/tagGroup/{pair.Key}",
                        SuperBCenter.ServerToken);

                    if (req == null)
                    {
                        continue;
                    }
                    if (req.codeid != 0)
                    {
                        var devMap = SuperBRepertory.Inst.devicemap.Find(d => d.groupIsid == pair.Key);
                        if (devMap == null)
                        {
                            LogHelper.Error($"GroupRes {pair.Key} cannot find map to device");
                            continue;
                        }
                        var device = SuperBRepertory.Inst.DevList.Find(d => d.Device.dvIsid == devMap.devIsid);
                        if (device == null)
                        {
                            LogHelper.Error($"GroupRes {pair.Key} cannot find device");
                            continue;
                        }
                        var res = await HttpUtil.PostAsync($"http://{cfg.AppSettings["serverUrl"]}/inIoT/devServer/tagGroup",
                                                           JsonSrialize.Srialize(new GroupRes()
                        {
                            groupIsid       = pair.Key,
                            collectPeriod   = 2,
                            dvIsid          = device.Device.dvIsid,
                            nodeIsid        = device.NodeIsid,
                            overTime        = 2,
                            relinkCount     = 2,
                            relinkPeriod    = 2,
                            transProtocolId = "1",
                        }),
                                                           SuperBCenter.ServerToken);

                        if (res == null || res.codeid != 0)
                        {
                            LogHelper.Error($"GroupRes {pair.Key} cannot add");
                            continue;
                        }
                    }
                }
            }
        }