public void SendGw(MsDevice dev, MsMessage msg) { msg.GetBytes(); lock(_sendQueue) { _sendQueue.Enqueue(msg); } }
public void SetOwner(Topic owner) { if(_owner!=null) { _owner.Unsubscribe("+", STVarChanged); } _owner=owner; if(_owner!=null) { addr=int.Parse(owner.name.Substring(2)); if(_owner.parent!=null && _owner.parent.valueType==typeof(MsDevice)) { _dev=(_owner.parent as DVar<MsDevice>).value; } _decl=_owner.Get<string>("_declarer", _owner); _owner.Subscribe("+", STVarChanged); if(_state!=0xB0) { Reset(); } } else { _decl=null; _state=0xB0; _to.Change(-1, -1); } }
internal void Recv(byte[] data) { if(_owner==null || data==null) { return; } if(_dev==null) { if(_owner.parent!=null && _owner.parent.valueType==typeof(MsDevice)) { _dev=(_owner.parent as DVar<MsDevice>).value; } } if(_verbose) { Log.Debug("{0}.Recv {1}", _owner.name, BitConverter.ToString(data)); } if(data.Length>0 && data[0]==0xB0) { _state=0xB0; } if(_state==0xF0 && data.Length>1) { byte addr=data[0]; var st=_vars.FirstOrDefault(z => z.addr==addr); if(st.flType!=0) { SetValue(st, data); } } else if(_state==0xB0) { if(data.Length>1 && data[0]==0xB0) { string decl=Encoding.UTF8.GetString(data, 1, data.Length-1); if(_decl!=null) { _decl.value=decl; } _state=0xC0; _dev.PublishWithPayload(_owner, new byte[] { 0xF0, (byte)'r', (byte)_state }); } else { _to.Change(100, -1); return; } } else if(_state>=0xC0 && _state<0xF0) { if(data.Length>0 && data[0]==(byte)_state) { if(data.Length==1) { _dev.PublishWithPayload(_owner, new byte[] { 0xF0, (byte)'I' }); _state=0xF0; _to.Change(-1, -1); } else { var st=_vars.FirstOrDefault(z => z.addr==data[0]); if(st.flType==0) { st.addr=data[2]; st.flType=data[1]; Topic ptr; string name=Encoding.UTF8.GetString(data, 3, data.Length-3); switch(st.dateType) { case 'z': ptr=_owner.Get<bool>(name); break; case 'b': case 'B': case 'w': case 'W': case 'd': case 'D': case 'q': ptr=_owner.Get<long>(name); break; case 's': ptr=_owner.Get<string>(name); break; case 'a': ptr=_owner.Get<PLC.ByteArray>(name); break; default: ptr=null; break; } if(ptr!=null) { st.ptr=ptr; _vars.Add(st); } } _state++; _dev.PublishWithPayload(_owner, new byte[] { 0xF0, (byte)'r', (byte)_state }); } } else { _to.Change(100, -1); return; } } _cntTry=0; }
public void RemoveNode(MsDevice dev) { if(_nodes!=null) { _nodes.Remove(dev); } }
private static void PrintPacket(MsDevice dev, MsMessage msg, byte[] buf) { if(_verbose.value) { Log.Debug("r {4:X2}:{0}:{1} \t{2}:{3}", BitConverter.ToString(msg.Addr??new byte[0]), BitConverter.ToString(buf??new byte[0]), (dev!=null && dev.Owner!=null)?dev.Owner.name:string.Empty, msg.ToString(), (dev!=null && dev._gate!=null)?dev._gate.gwIdx:0xFF); } }
public void AddNode(MsDevice dev) { _nodes.Add(dev); }
public void SendGw(MsDevice dev, MsMessage msg) { if(_udp==null || msg==null) { return; } byte[] buf=msg.GetBytes(); IPAddress addr; if(dev==null) { addr=IPAddress.Broadcast; foreach(var bc in _bcIps) { _udp.Send(buf, buf.Length, new IPEndPoint(bc, 1883)); } } else if(dev.Addr!=null && dev.Addr.Length==4) { addr=new IPAddress(dev.Addr); _udp.Send(buf, buf.Length, new IPEndPoint(addr, 1883)); } else { return; } if(_verbose.value) { Log.Debug("s {0}: {1} {2}", addr, BitConverter.ToString(buf), msg.ToString()); } }
public void SetOwner(Topic owner) { if(_owner!=null) { if(Topic.brokerMode) { _owner.Unsubscribe("+", STVarChanged); } } if(_dev!=null) { _dev.Pool+=_dev_Pool; } _owner=owner; if(_owner!=null) { name=owner.name; if(Topic.brokerMode) { if(_owner.parent!=null && _owner.parent.valueType==typeof(MsDevice)) { _dev=(_owner.parent as DVar<MsDevice>).value; } _owner.Get<string>("_declarer", _owner).value="TWI"; _owner.Subscribe("+", STVarChanged); if(_dev!=null) { _dev.Pool+=_dev_Pool; Reset(); } } } }
public void AddNode(MsDevice dev) { if(_nodes==null) { _nodes=new List<MsDevice>(); } _nodes.Add(dev); }
public void SendGw(MsDevice dev, MsMessage msg) { if(_gate!=null) { _gate.SendGw(this, new MsForward(dev.Addr, msg)); } }