GetBytes() публичный Метод

public GetBytes ( ) : byte[]
Результат byte[]
Пример #1
0
 public void SendGw(MsDevice dev, MsMessage msg)
 {
     msg.GetBytes();
     lock (_sendQueue) {
         _sendQueue.Enqueue(msg);
     }
 }
Пример #2
0
 public void SendGw(byte[] addr, MsMessage msg)
 {
     msg.GetBytes();
     lock (_sendQueue) {
         _sendQueue.Enqueue(msg);
     }
 }
Пример #3
0
        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;
                if (_bcIps == null)
                {
                    Log.Error("bcIps == null");
                    return;
                }
                foreach (var bc in _bcIps)
                {
                    try {
                        _udp.Send(buf, buf.Length, new IPEndPoint(bc, 1883));
                    }
                    catch (Exception ex) {
                        if (_pl.verbose)
                        {
                            Log.Warning("MsGUdp.SendGw({0}, {1}) - {2}", bc, msg, ex.Message);
                        }
                    }
                }
            }
            else if (dev.addr != null && dev.addr.Length == 4)
            {
                addr = new IPAddress(dev.addr);
                try {
                    _udp.Send(buf, buf.Length, new IPEndPoint(addr, 1883));
                }
                catch (Exception ex) {
                    if (_pl.verbose)
                    {
                        Log.Warning("MsGUdp.SendGw({0}, {1}) - {2}", addr, msg, ex.Message);
                    }
                }
            }
            else
            {
                return;
            }
            if (_pl.verbose)
            {
                Log.Debug("s {0}: {1}  {2}", addr, BitConverter.ToString(buf), msg.ToString());
            }
        }
Пример #4
0
        private void SendRaw(MsMessage msg, byte[] tmp)
        {
            if (_port == null || !_port.IsOpen || msg == null)
            {
                return;
            }
            byte[] buf = msg.GetBytes();
            int    i, j = 0;
            byte   b;

            b = (byte)buf.Length;
            if (_useSlip)
            {
                tmp[j++] = 0xC0;
                if (b == 0xC0 || b == 0xDB)
                {
                    tmp[j++] = 0xDB;
                    tmp[j++] = (byte)(b ^ 0x20);
                }
                else
                {
                    tmp[j++] = b;
                }
                for (i = 0; i < buf.Length; i++)
                {
                    if (buf[i] == 0xC0 || buf[i] == 0xDB)
                    {
                        tmp[j++] = 0xDB;
                        tmp[j++] = (byte)(buf[i] ^ 0x20);
                    }
                    else
                    {
                        tmp[j++] = buf[i];
                    }
                }
                tmp[j++] = 0xC0;
            }
            else
            {
                tmp[j++] = b;
                for (i = 0; i < buf.Length; i++)
                {
                    tmp[j++] = buf[i];
                }
            }
            _port.Write(tmp, 0, j);

            if (_pl.verbose)
            {
                Log.Debug("s {0}: {1}  {2}", _port.PortName, BitConverter.ToString(buf), msg.ToString());
            }
        }
Пример #5
0
        public void SendGw(byte[] arr, MsMessage msg)
        {
            if (_udp == null || arr == null || arr.Length != 4 || msg == null)
            {
                return;
            }
            byte[]    buf  = msg.GetBytes();
            IPAddress addr = new IPAddress(arr);

            _udp.Send(buf, buf.Length, new IPEndPoint(addr, 1883));
            if (_pl.verbose)
            {
                Log.Debug("s {0}: {1}  {2}", addr, BitConverter.ToString(buf), msg.ToString());
            }
        }
Пример #6
0
        public override byte[] GetBytes()
        {
            base._length = (ushort)(3 + addr.Length);
            byte[] fMsg = msg.GetBytes();
            byte[] rez  = new byte[_length + fMsg.Length];
            int    ptr  = 0;

            if (_length > 255)
            {
                rez[ptr++] = 1;
                rez[ptr++] = (byte)(_length >> 8);
                rez[ptr++] = (byte)(_length);
            }
            else
            {
                rez[ptr++] = (byte)(_length);
            }
            rez[ptr++] = (byte)MsgTyp;
            rez[ptr++] = 0;
            Buffer.BlockCopy(addr, 0, rez, ptr, addr.Length);
            ptr += addr.Length;
            Buffer.BlockCopy(fMsg, 0, rez, ptr, fMsg.Length);
            return(rez);
        }
Пример #7
0
 public void SendGw(MsDevice dev, MsMessage msg) {
   msg.GetBytes();
   lock(_sendQueue) {
     _sendQueue.Enqueue(msg);
   }
 }
Пример #8
0
      private static void SendRaw(MsGSerial g, MsMessage msg, byte[] tmp) {
        if(g==null || g._port==null || !g._port.IsOpen || msg==null) {
          return;
        }
        byte[] buf=msg.GetBytes();
        int i, j=0;
        byte b;
        b=(byte)buf.Length;
#if UART_RAW_MQTTSN
        tmp[j++]=b;
        for(i=0; i<buf.Length; i++) {
          tmp[j++]=buf[i];
        }
#else
        tmp[j++]=0xC0;
        if(b==0xC0 || b==0xDB) {
          tmp[j++]=0xDB;
          tmp[j++]=(byte)(b ^ 0x20);
        } else {
          tmp[j++]=b;
        }
        for(i=0; i<buf.Length; i++) {
          if(buf[i]==0xC0 || buf[i]==0xDB) {
            tmp[j++]=0xDB;
            tmp[j++]=(byte)(buf[i] ^ 0x20);
          } else {
            tmp[j++]=buf[i];
          }
        }
        tmp[j++]=0xC0;
#endif
        g._port.Write(tmp, 0, j);

        if(_verbose.value) {
          Log.Debug("s {0}: {1}  {2}", g._port.PortName, BitConverter.ToString(buf), msg.ToString());
        }
      }
Пример #9
0
      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());
        }
      }
Пример #10
0
      public void SendGw(byte[] arr, MsMessage msg) {
        if(_udp==null || arr==null || arr.Length!=4 || msg==null) {
          return;
        }
        byte[] buf=msg.GetBytes();
        IPAddress addr=new IPAddress(arr);
        _udp.Send(buf, buf.Length, new IPEndPoint(addr, 1883));
        if(_verbose.value) {
          Log.Debug("s  {0}: {1}  {2}", addr, BitConverter.ToString(buf), msg.ToString());
        }

      }
Пример #11
0
 public void SendGw(byte[] addr, MsMessage msg) {
   msg.GetBytes();
   lock(_sendQueue) {
     _sendQueue.Enqueue(msg);
   }
 }
Пример #12
0
 private static void SendRaw(MsGSerial g, MsMessage msg) {
   if(g==null || g._port==null || !g._port.IsOpen || msg==null || msg.Addr==null || msg.Addr.Length!=1) {
     return;
   }
   int i;
   byte[] b=new byte[1];
   b[0]=0xC0;
   g._port.Write(b, 0, 1);
   if(msg.Addr[0]==0xC0 || msg.Addr[0]==0xDB) {
     b[0]=0xDB;
     g._port.Write(b, 0, 1);
     b[0]=(byte)(msg.Addr[0] ^ 0x20);
   } else {
     b[0]=msg.Addr[0];
   }
   g._port.Write(b, 0, 1);
   byte[] buf=msg.GetBytes();
   for(i=0; i<buf.Length; i++) {
     if(buf[i]==0xC0 || buf[i]==0xDB) {
       b[0]=0xDB;
       g._port.Write(b, 0, 1);
       b[0]=(byte)(buf[i] ^ 0x20);
     } else {
       b[0]=buf[i];
     }
     g._port.Write(b, 0, 1);
   }
   b[0]=0xC0;
   g._port.Write(b, 0, 1);
   if(_verbose.value) {
     Log.Debug("s {0:X2}:{1:X2}:{2} \t{3}", g.gwIdx, msg.Addr[0], BitConverter.ToString(buf), msg.ToString());
   }
 }
Пример #13
0
      public void Send(MsMessage msg) {
        if(_udp==null || msg==null || msg.Addr==null || msg.Addr.Length!=4) {
          return;
        }

        byte[] buf=msg.GetBytes();

        if(IPAddress.Broadcast.GetAddressBytes().SequenceEqual(msg.Addr)) {
          foreach(var bc in _bcIps) {
            _udp.Send(buf, buf.Length, new IPEndPoint(bc, 1883));
          }
        } else {
          _udp.Send(buf, buf.Length, new IPEndPoint(new IPAddress(msg.Addr), 1883));
        }
        if(_verbose.value) {
          Log.Debug("s {0:X2}:{1}:{2} \t{3}", gwIdx, BitConverter.ToString(msg.Addr), BitConverter.ToString(buf), msg.ToString());
        }
      }