//private System.Collections.Concurrent.ConcurrentQueue<Tuple<byte[], byte[]>> _inBuf; public MsGUdp(MQTT_SNPl pl) { _pl = pl; _scanBusy = 0; //_inBuf = new System.Collections.Concurrent.ConcurrentQueue<Tuple<byte[], byte[]>>(); _udpT = Topic.root.Get("/$YS/MQTT-SN/udp"); if (!_udpT.CheckAttribute(Topic.Attribute.Required) || _udpT.GetState().ValueType != JSC.JSValueType.Boolean) { _udpT.SetAttribute(Topic.Attribute.Required | Topic.Attribute.Config); var act = new JSL.Array(1); var r_a = JSC.JSObject.CreateObject(); r_a["name"] = "MQTT_SN.RefreshNIC"; r_a["text"] = "Refresh"; act[0] = r_a; _udpT.SetField("Action", act); _udpT.SetState(true); } else if (!(bool)_udpT.GetState()) { return; // udp disabled } _scanBusy = 1; ScanNIC(false); try { _udp = new UdpClient(1883); _udp.EnableBroadcast = true; _udp.BeginReceive(new AsyncCallback(ReceiveCallback), null); _advTick = new Timer(SendAdv, null, 4500, 900000); Topic t; if (Topic.root.Exist("/$YS/MQTT-SN/radius", out t) && t.GetState().IsNumber) { _gwRadius = (byte)(int)t.GetState(); if (_gwRadius < 1 || _gwRadius > 3) { _gwRadius = 0; } } else { _gwRadius = 1; } } catch (Exception ex) { Log.Error("MsGUdp.ctor() {0}", ex.Message); } }
public static void Init(MQTT_SNPl pl) { _pl = pl; ThreadPool.RegisterWaitForSingleObject(_startScan, ScanSerialPorts, null, 289012, false); _portsTopic = Topic.root.Get("/$YS/MQTT-SN/ports"); if (!_portsTopic.CheckAttribute(Topic.Attribute.Required) || _portsTopic.GetState().ValueType != JSC.JSValueType.Boolean) { var act = new JSL.Array(1); var r_a = JSC.JSObject.CreateObject(); r_a["name"] = "MQTT_SN.RefreshPorts"; r_a["text"] = "Refresh"; act[0] = r_a; _portsTopic.SetField("Action", act); _portsTopic.SetState(true); _portsTopic.SetAttribute(Topic.Attribute.Required | Topic.Attribute.Config); _scanBusy = 1; } _portValuesSR = _portsTopic.Subscribe(SubRec.SubMask.Chldren | SubRec.SubMask.Value, PortValuesChanged); _startScan.Set(); }