示例#1
0
        public void StatusPacketReceived(StatusPacket statusPacket)
        {
            Console.WriteLine("ROUTER: #" + statusPacket.deviceId + " (" + statusPacket.shortAddress + " = #" + Device.RouterAltId(statusPacket.shortAddress) + "), parent " + statusPacket.parentAddress + " (" + statusPacket.parentAltAddress + " = #" + Device.RouterAltId(statusPacket.parentAltAddress) + ").");
            Console.Write("NEIGHBOURS of #" + Device.RouterAltId(statusPacket.shortAddress) + ": ");
            for (int i = 0; i < statusPacket.neighbours.Length; i++)
            {
                Console.Write("#" + statusPacket.neighbours[i] + "; ");
            }
            Console.WriteLine("");

            Device device = null;
            if (devices.ContainsKey(statusPacket.deviceId))
            {
                device = devices[statusPacket.deviceId];
            }
            else
            {
                Console.WriteLine("NOTICE: New router: " + statusPacket.deviceId + "");
                device = new Device(statusPacket.deviceId, false);
                devices.Add(statusPacket.deviceId, device);
            }
            device.AddStatus(statusPacket);

            //throw new NotImplementedException();
        }
示例#2
0
        public void StatusPacketReceived(StatusPacket statusPacket)
        {
            Console.WriteLine("ROUTER: #" + statusPacket.deviceId + " (" + statusPacket.shortAddress + " = #" + Device.RouterAltId(statusPacket.shortAddress) + "), parent " + statusPacket.parentAddress + " (" + statusPacket.parentAltAddress + " = #" + Device.RouterAltId(statusPacket.parentAltAddress) + ").");
            Console.Write("NEIGHBOURS of #" + Device.RouterAltId(statusPacket.shortAddress) + ": ");
            for (int i = 0; i < statusPacket.neighbours.Length; i++)
            {
                Console.Write("#" + statusPacket.neighbours[i] + "; ");
            }
            Console.WriteLine("");

            Device device = null;

            if (devices.ContainsKey(statusPacket.deviceId))
            {
                device = devices[statusPacket.deviceId];
            }
            else
            {
                Console.WriteLine("NOTICE: New router: " + statusPacket.deviceId + "");
                device = new Device(statusPacket.deviceId, false);
                devices.Add(statusPacket.deviceId, device);
            }
            device.AddStatus(statusPacket);

//throw new NotImplementedException();
        }
示例#3
0
        public void AddStatus(StatusPacket statusPacket)
        {
            UpdateTime = DateTime.UtcNow;

            this.parentAddress = statusPacket.parentAddress;
            this.shortAddress  = statusPacket.shortAddress;
            this.parentLQI     = statusPacket.lastLQI;
            this.parentRSSI    = statusPacket.lastRSSI;
            neighbours         = (ushort[])statusPacket.neighbours.Clone();
        }
示例#4
0
        void stompListener_ReceivedMessage(object sender, StompMessageEventArgs e)
        {
            Hashtable data = (Hashtable)Json.JsonDecode(e.Message.Body);

            if (data != null)
            {
                string type = null;

                if (data.ContainsKey("Type"))
                {
                    type = data["Type"].ToString();
                }

                if (type == "TEDDI" || (type == null && data.ContainsKey("Humidity")))  // Appears to be TEDDI type
                {
                    Packet packet = Packet.PacketFromStomp(data);
                    if (packet != null)
                    {
                        TeddiPacketReceived(packet);
                    }
                }
                else if (type == "TEDDI_Status")            // Appears to be TEDDI_Status type
                {
                    StatusPacket statusPacket = StatusPacket.StatusPacketFromStomp(data);
                    if (statusPacket != null)
                    {
                        TeddiStatusPacketReceived(statusPacket);
                    }
                }
                else if (type == null)
                {
                    string debug = e.Message.Body;
                    if (debug.Length > 128)
                    {
                        debug = debug.Substring(0, 128) + "...";
                    }
                    Console.WriteLine("WARNING: Un-typed JSON STOMP message: " + debug + "");
                }
                else
                {
                    Console.WriteLine("WARNING: Unknown STOMP type: " + type + "");
                }
            }
            else
            {
                string debug = e.Message.Body;
                if (debug.Length > 128)
                {
                    debug = debug.Substring(0, 128) + "...";
                }
                Console.WriteLine("WARNING: Couldn't parse JSON: " + debug + "");
            }
        }
示例#5
0
        private void BinaryPacketReceived(byte[] data, DateTime timestamp)
        {
            if (data == null)
            {
                return;
            }

            Packet packet = Packet.PacketFromBinary(data, timestamp);

            if (packet != null)
            {
                TeddiPacketReceived(packet);
            }

            StatusPacket statusPacket = StatusPacket.StatusPacketFromBinary(data, timestamp);

            if (statusPacket != null)
            {
                TeddiStatusPacketReceived(statusPacket);
            }
        }
示例#6
0
        private void TeddiStatusPacketReceived(StatusPacket statusPacket)
        {
            if (logStream != null)
            {
//                logStream.WriteLine(statusPacket.ToString());
            }

            lock (manager)
            {
                manager.StatusPacketReceived(statusPacket);
            }

            //SendOscPacket(statusPacket);

            if (graphPanel.Visible)
            {
                graphPanel.Invalidate();
            }
            if (mapPanel.Visible)
            {
                mapPanel.Invalidate();
            }
        }
        // Method to return a StatusPacket, or null if invalid byte array
        public static StatusPacket StatusPacketFromBinary(byte[] buffer, DateTime timestampReceived)
        {
            StatusPacket statusPacket = null;

            if (buffer != null && buffer.Length > 0)
            {
                if (buffer.Length >= 5 && buffer[0] == 0x12 && buffer[1] == 0x53)           // USER_REPORT_TYPE && TEDDI (ASCII 'S')
                {
                    ushort deviceId = (ushort)(buffer[2] | (((ushort)buffer[3]) << 8));
                    byte version = buffer[4];

                    if (buffer.Length >= 24)
                    {
                        /*
                        #define NUM_COORDINATOR 64
                        typedef struct
                        {
                            unsigned char  reportType;          // @ 0  [1] USER_REPORT_TYPE (0x12)
                            unsigned char  reportId;            // @ 1  [1] Report identifier (0x53, ASCII 'S')
                            unsigned short deviceId;            // @ 2  [2] Device identifier (16-bit)
                            unsigned char  version;             // @ 4  [1] Low nibble = packet version (0x3), high nibble = config (0x0)
                            unsigned char  power;               // @ 5  [1] Power (top-bit indicates USB, if low-15 are 0x7ffff, unknown)
                            unsigned short sequence;			// @ 6  [2] Packet sequence number
                            unsigned short shortAddress;		// @ 8  [2] Short address
                            unsigned char  lastLQI;				// @ 10 [1] LQI of last received keep-alive broadcast
                            unsigned char  lastRSSI;			// @ 11 [1] RSSI of last received keep-alive broadcast
                            unsigned short parentAddress;		// @ 12 [2] Parent address
                            unsigned short parentAltAddress;	// @ 14 [2] Parent alt. address
                            unsigned char  neighbours[NUM_COORDINATOR/8];	// @ 16 [8] Neighbouring routers bitmap
                            unsigned long long timestampReceived;
                        } TeddiStatusPacket;
                        */
                        byte power = (byte)(buffer[5]);
                        ushort sequence = (ushort)(buffer[6] | (((ushort)buffer[7]) << 8));
                        ushort shortAddress = (ushort)(buffer[8] | (((ushort)buffer[9]) << 8));
                        byte lastLQI = (byte)(buffer[10]);
                        byte lastRSSI = (byte)(buffer[11]);
                        ushort parentAddress = (ushort)(buffer[12] | (((ushort)buffer[13]) << 8));
                        ushort parentAltAddress = (ushort)(buffer[14] | (((ushort)buffer[15]) << 8));

                        // Neighbour table
                        byte[] neighbourBitmap = new byte[NUM_COORDINATOR / 8];
                        for (int i = 0; i < NUM_COORDINATOR / 8; i++)
                        {
                            neighbourBitmap[i] = buffer[16 + i];
                        }
                        List<ushort> neighbourList = new List<ushort>();
                        for (int i = 0; i < NUM_COORDINATOR; i++)
                        {
                            if ((neighbourBitmap[i / 8] & (1 << (i & 7))) != 0)
                            {
                                neighbourList.Add((ushort)i);
                            }
                        }
                        ushort[] neighbours = neighbourList.ToArray();

                        statusPacket = new StatusPacket(deviceId, version, power, sequence, shortAddress, lastLQI, lastRSSI, parentAddress, parentAltAddress, neighbours, timestampReceived);

                    }
                    else
                    {
                        Console.Error.Write("[S?]");	// Unknown TEDDI status packet type
                    }
                }
                else
                {
                    //Console.Error.Write("[?]");		// Unknown packet type
                }
            }
            return statusPacket;
        }
示例#8
0
        // Method to return a StatusPacket, or null if invalid byte array
        public static StatusPacket StatusPacketFromBinary(byte[] buffer, DateTime timestampReceived)
        {
            StatusPacket statusPacket = null;

            if (buffer != null && buffer.Length > 0)
            {
                if (buffer.Length >= 5 && buffer[0] == 0x12 && buffer[1] == 0x53)           // USER_REPORT_TYPE && TEDDI (ASCII 'S')
                {
                    ushort deviceId = (ushort)(buffer[2] | (((ushort)buffer[3]) << 8));
                    byte   version  = buffer[4];

                    if (buffer.Length >= 24)
                    {
                        /*
                         #define NUM_COORDINATOR 64
                         * typedef struct
                         * {
                         *  unsigned char  reportType;          // @ 0  [1] USER_REPORT_TYPE (0x12)
                         *  unsigned char  reportId;            // @ 1  [1] Report identifier (0x53, ASCII 'S')
                         *  unsigned short deviceId;            // @ 2  [2] Device identifier (16-bit)
                         *  unsigned char  version;             // @ 4  [1] Low nibble = packet version (0x3), high nibble = config (0x0)
                         *  unsigned char  power;               // @ 5  [1] Power (top-bit indicates USB, if low-15 are 0x7ffff, unknown)
                         *  unsigned short sequence;			// @ 6  [2] Packet sequence number
                         *  unsigned short shortAddress;		// @ 8  [2] Short address
                         *  unsigned char  lastLQI;				// @ 10 [1] LQI of last received keep-alive broadcast
                         *  unsigned char  lastRSSI;			// @ 11 [1] RSSI of last received keep-alive broadcast
                         *  unsigned short parentAddress;		// @ 12 [2] Parent address
                         *  unsigned short parentAltAddress;	// @ 14 [2] Parent alt. address
                         *  unsigned char  neighbours[NUM_COORDINATOR/8];	// @ 16 [8] Neighbouring routers bitmap
                         *  unsigned long long timestampReceived;
                         * } TeddiStatusPacket;
                         */
                        byte   power            = (byte)(buffer[5]);
                        ushort sequence         = (ushort)(buffer[6] | (((ushort)buffer[7]) << 8));
                        ushort shortAddress     = (ushort)(buffer[8] | (((ushort)buffer[9]) << 8));
                        byte   lastLQI          = (byte)(buffer[10]);
                        byte   lastRSSI         = (byte)(buffer[11]);
                        ushort parentAddress    = (ushort)(buffer[12] | (((ushort)buffer[13]) << 8));
                        ushort parentAltAddress = (ushort)(buffer[14] | (((ushort)buffer[15]) << 8));

                        // Neighbour table
                        byte[] neighbourBitmap = new byte[NUM_COORDINATOR / 8];
                        for (int i = 0; i < NUM_COORDINATOR / 8; i++)
                        {
                            neighbourBitmap[i] = buffer[16 + i];
                        }
                        List <ushort> neighbourList = new List <ushort>();
                        for (int i = 0; i < NUM_COORDINATOR; i++)
                        {
                            if ((neighbourBitmap[i / 8] & (1 << (i & 7))) != 0)
                            {
                                neighbourList.Add((ushort)i);
                            }
                        }
                        ushort[] neighbours = neighbourList.ToArray();

                        statusPacket = new StatusPacket(deviceId, version, power, sequence, shortAddress, lastLQI, lastRSSI, parentAddress, parentAltAddress, neighbours, timestampReceived);
                    }
                    else
                    {
                        Console.Error.Write("[S?]");    // Unknown TEDDI status packet type
                    }
                }
                else
                {
                    //Console.Error.Write("[?]");		// Unknown packet type
                }
            }
            return(statusPacket);
        }
示例#9
0
        public void AddStatus(StatusPacket statusPacket)
        {
            UpdateTime = DateTime.UtcNow;

            this.parentAddress = statusPacket.parentAddress;
            this.shortAddress = statusPacket.shortAddress;
            this.parentLQI = statusPacket.lastLQI;
            this.parentRSSI = statusPacket.lastRSSI;
            neighbours = (ushort[])statusPacket.neighbours.Clone();
        }
示例#10
0
        private void TeddiStatusPacketReceived(StatusPacket statusPacket)
        {
            if (logStream != null)
            {
            //                logStream.WriteLine(statusPacket.ToString());
            }

            lock (manager)
            {
                manager.StatusPacketReceived(statusPacket);
            }

            //SendOscPacket(statusPacket);

            if (graphPanel.Visible) { graphPanel.Invalidate(); }
            if (mapPanel.Visible) { mapPanel.Invalidate(); }
        }