private void GpioChanged(Topic t, TopicChanged a) { if(t==null || t.parent!=_gpio || a.Visited(_gpio, true)) { return; } DVar<bool> tb=t as DVar<bool>; if(tb!=null) { Pin pin=GetPin(t.name); if(pin==null) { t.Remove(); return; } if(a.Art==TopicChanged.ChangeArt.Remove) { _pins.Remove(pin.idx); pin.Dispose(); } else if(a.Art==TopicChanged.ChangeArt.Value && pin.dir) { pin.value=tb.value; } } }
private void SubChanged(Topic t, TopicChanged a) { if(t.path.StartsWith("/local") || a.Visited(_ses.owner, true) || !MQTT.MqBroker.CheckAcl(_ses.userName, t, TopicAcl.Subscribe)) { if(_verbose.value) { X13.Log.Warning("ws.snd({0}) - subscribe:access denied", t.path); } return; } if(a.Art==TopicChanged.ChangeArt.Remove) { Send(string.Concat("P\t", t.path, "\tnull")); if(_verbose.value) { X13.Log.Debug("ws.snd({0}) - remove", t.path); } } else if(a.Art==TopicChanged.ChangeArt.Value) { Send(string.Concat("P\t", t.path, "\t", t.ToJson())); if(_verbose.value) { X13.Log.Debug("ws.snd({0}, {1})", t.path, t.ToJson()); } } else { return; } }
private void OwnerChanged(Topic sender, TopicChanged param) { if(!_connected || sender.parent==null || sender.path.StartsWith("/local") || sender.path.StartsWith("/var/now") || sender.path.StartsWith("/var/log") || param.Visited(_mq, false) || param.Visited(_owner, false)) { return; } switch(param.Art) { case TopicChanged.ChangeArt.Add: { MqPublish pm=new MqPublish(sender); if(sender.valueType!=null && sender.valueType!=typeof(string) && !sender.valueType.IsEnum && !sender.valueType.IsPrimitive) { pm.Payload=(new Newtonsoft.Json.Linq.JObject(new Newtonsoft.Json.Linq.JProperty("+", WOUM.ExConverter.Type2Name(sender.valueType)))).ToString(); } this.Send(pm); } break; case TopicChanged.ChangeArt.Value: { MqPublish pm=new MqPublish(sender); this.Send(pm); } break; case TopicChanged.ChangeArt.Remove: { MqPublish pm=new MqPublish(sender); pm.Payload=string.Empty; this.Send(pm); } break; } }
private void _b_changed(Topic sender, TopicChanged param) { if (exec) { if (param.Art == TopicChanged.ChangeArt.Value && _a != null && !param.Visited(_a, true) && (Direction == 0 || Direction == 2)) { Topic a = _a.valueType == typeof(Topic) ? (_a as DVar<Topic>).value : _a; Topic b = _b.valueType == typeof(Topic) ? (_b as DVar<Topic>).value : _b; if (a != null && b != null) { a.SetValue(b.GetValue(), new TopicChanged(param)); } } else if (_b.disposed) { DVar<PiWire> o = System.Threading.Interlocked.Exchange(ref _owner, null); if (o != null) { Change_A(null); Change_B(null); o.Remove(); } } } }
private void MqChanged(Topic sender, TopicChanged param) { if(sender==null || sender.path.StartsWith("/local") || sender.path=="/var/log/A0" || param.Visited(_sign, true)) { return; } _ch.Enqueue(sender); if(param.Art!=TopicChanged.ChangeArt.Add) { _work.Set(); } }
private void PublishTopic(Topic topic, TopicChanged param) { if(topic.valueType==null || topic==Owner) { return; } if(param.Art==TopicChanged.ChangeArt.Add) { if(topic.valueType==typeof(SmartTwi) || (topic.parent!=null && topic.parent.valueType==typeof(SmartTwi))) { return; // processed from SmartTwi } GetTopicInfo(topic); return; } if(topic.name=="_via") { if(_gate==null) { if(string.IsNullOrEmpty(via)) { MsGSerial.Rescan(); } } } if(!(state==State.Connected || state==State.ASleep || state==State.AWake) || param.Visited(Owner, true)) { return; } if(topic.valueType==typeof(SmartTwi) || (topic.parent!=null && topic.parent.valueType==typeof(SmartTwi))) { return; // processed from SmartTwi } TopicInfo rez=null; for(int i=_topics.Count-1; i>=0; i--) { if(_topics[i].path==topic.path) { rez=_topics[i]; break; } } if(rez==null && param.Art==TopicChanged.ChangeArt.Value) { rez=GetTopicInfo(topic, true); } if(rez==null || rez.it==TopicIdType.NotUsed || rez.TopicId>=0xFFC0 || !rez.registred) { return; } if(param.Art==TopicChanged.ChangeArt.Value) { Send(new MsPublish(rez.topic, rez.TopicId, param.Subscription.qos)); } else { // Remove by device Send(new MsRegister(0xFFFF, rez.path.StartsWith(Owner.path)?rez.path.Remove(0, Owner.path.Length+1):rez.path)); _topics.Remove(rez); } }
private void STVarChanged(Topic snd, TopicChanged p) { if(p.Visited(_owner, true)) { return; } for(int i=_drivers.Count-1; i>=0; i--) { if(_drivers[i].VarChanged(snd, p.Art==TopicChanged.ChangeArt.Remove)) { if(p.Art==TopicChanged.ChangeArt.Remove) { lock(_drivers) { _drivers.RemoveAt(i); } } return; } } if(p.Art==TopicChanged.ChangeArt.Remove) { return; } TWICommon drv=null; switch(snd.name) { case "LM75_T0": case "LM75_T1": case "LM75_T2": case "LM75_T3": drv=new LM75(snd); break; case "CC2D_T": case "CC2D_H": drv=new CC2D(snd); break; case "HIH61_T": case "HIH61_H": drv=new HIH61xx(snd); break; case "SI7020_T": case "SI7020_H": drv=new SI7020(snd); break; case "BMP180_T": case "BMP180_P": drv=new BMP180(snd); break; case "BME280_T": case "BME280_P": case "BME280_H": drv=new BME280(snd); break; case "BLINKM_8": case "BLINKM_9": case "BLINKM_10": drv=new Blinky(snd); break; case "BH1750_0": case "BH1750_1": drv=new BH1750(snd); break; case "EXP_0": case "EXP_1": case "EXP_2": case "EXP_3": case "EXP_4": case "EXP_5": case "EXP_6": case "EXP_7": drv=new Expander(snd); break; //case "SI1143": // drv=new SI1143(snd); // break; default: if(snd.name.Length>2 && snd.name.Length<6 && (snd.name.StartsWith("Sa") || snd.name.StartsWith("Ra"))) { drv=new RawDevice(snd); } break; } if(drv!=null) { lock(_drivers) { for(int i=_drivers.Count-1; i>=0; i--) { if(_drivers[i].VarChanged(snd, false)) { drv=null; break; } } if(drv!=null) { _drivers.Add(drv); } } } }