Example #1
0
 public void SetDeviceNameStartup(String name)
 {
     if (!HeepParser.DeviceNameOpCodeAlreadySet(deviceMemory))
     {
         SetDeviceName(name);
     }
 }
Example #2
0
        public static void TestNonVolatileMemory()
        {
            HeepTest nonVolatileTest = new HeepTest("Non Volatile Memory Test");

            String TestDeviceName = "Test Device";

            List <byte> ID = new List <byte>();

            for (byte i = 0; i < 4; i++)
            {
                ID.Add(i);
            }

            DeviceID   myID     = new DeviceID(ID);
            HeepDevice myDevice = new HeepDevice(myID);

            myDevice.SetDeviceName(TestDeviceName);

            List <byte> readMem = NonVolatileData.ReadMemoryFromFile();

            int    counter   = 1;
            String foundName = HeepParser.parseDeviceNameMOP(readMem, ref counter);

            nonVolatileTest.AddTest(new TestData("Device Name", TestDeviceName, foundName));

            nonVolatileTest.CheckTests();
        }
Example #3
0
        private static void DeviceSearchWorker(object currentIP)
        {
            Console.WriteLine((IPAddress)currentIP);

            List <byte> Buffer = new List <byte>();

            Buffer.Add((byte)0x09);

            try{
                List <byte> returnedCode = HeepCommunications.SendBufferToIP(Buffer, (IPAddress)currentIP);
                HeepParser.ParseROP(returnedCode);
            }
            catch (Exception e) {
                Console.Write("FAILED: ");
                Console.Write(e.Data);
            }
        }
Example #4
0
        public static void StartListening(HeepDevice device, UdpClient client)
        {
            byte[] recData;
            while (true)
            {
                try
                {
                    IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
                    Debug.Log("About to receive");
                    recData = client.Receive(ref anyIP);
                    Debug.Log("Received");
                    List <byte> commandData = new List <byte>(recData);

                    if (HeepParser.isROP(commandData))
                    {
                        Debug.Log("Was ROP");
                        continue;
                    }

                    List <byte> fromparser = HeepParser.ParseCommand(commandData, device);

                    Debug.Log("IP Address: " + anyIP.Address + " Port: " + anyIP.Port);
                    Debug.Log("UDP Data Received: " + Encoding.ASCII.GetString(commandData.ToArray(), 0, commandData.Count));

                    String printableReturn = "";
                    for (int i = 0; i < fromparser.Count; i++)
                    {
                        printableReturn += fromparser[i] + " ";
                    }
                    Debug.Log("Sending: " + printableReturn);

                    UdpClient udpClientB = new UdpClient();
                    anyIP.Port = PORT;
                    udpClientB.Send(fromparser.ToArray(), fromparser.Count, anyIP);
                }
                catch (ObjectDisposedException) {
                    Debug.Log("Server disposed");
                    return;
                }
                catch (Exception err)
                {
                    Debug.Log("UDP Exception: " + err.ToString());
                }
            }
        }
Example #5
0
        public static async void SendAnalytics(DeviceID deviceID, List <byte> memoryDump)
        {
            string deviceIDString = GetDeviceIDString(deviceID);

            string analyticsString = HeepParser.GetAnalyticsStringFromMemory(memoryDump);


            if (analyticsString.Length > 0)
            {
                string      project = "heep-3cddb";
                FirestoreDb db      = FirestoreDb.Create(project);

                Dictionary <string, object> DataDictionary = new Dictionary <string, object>
                {
                    { "Data", analyticsString }
                };
                await db.Collection("DeviceList").Document(deviceIDString).Collection("Analytics").AddAsync(DataDictionary);
            }
        }
Example #6
0
        public static void StartListening(HeepDevice device, UdpClient client)
        {
            byte[] recData;
            while (true)
            {
                try
                {
                    IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
                    recData = client.Receive(ref anyIP);
                    List <byte> commandData = new List <byte>(recData);

                    if (HeepParser.isROP(commandData))
                    {
                        continue;
                    }

                    List <byte> fromparser = HeepParser.ParseCommand(commandData, device);

                    String printableReturn = "";
                    for (int i = 0; i < fromparser.Count; i++)
                    {
                        printableReturn += fromparser[i] + " ";
                    }

                    UdpClient udpClientB = new UdpClient();
                    anyIP.Port = PORT;
                    udpClientB.Send(fromparser.ToArray(), fromparser.Count, anyIP);
                }
                catch (ObjectDisposedException) {
                    return;
                }
                catch (Exception err)
                {
                }
            }
        }
Example #7
0
        public void LoadDeviceMemoryFromFile()
        {
            deviceMemory = NonVolatileData.ReadMemoryFromFile();

            vertices = HeepParser.GetVerticesFromBuffer(deviceMemory);
        }
Example #8
0
 public string GetDeviceName()
 {
     return(HeepParser.GetNameFromBuffer(deviceMemory));
 }
Example #9
0
        public static void StartListening(HeepDevice device)
        {
            // Data buffer for incoming data.
            byte[] bytes = new Byte[1024];

            byte []    IPAddrArray   = { 0, 0, 0, 0 };
            IPAddress  theAddr       = new IPAddress(IPAddrArray);
            IPEndPoint localEndPoint = new IPEndPoint(theAddr, 5000);

            // Create a TCP/IP socket.
            Socket listener = new Socket(AddressFamily.InterNetwork,
                                         SocketType.Stream, ProtocolType.Tcp);

            // Bind the socket to the local endpoint and
            // listen for incoming connections.
            try {
                listener.Bind(localEndPoint);
                listener.Listen(10);

                // Start listening for connections.
                while (true)
                {
                    Console.WriteLine("Waiting for a connection...");
                    // Program is suspended while waiting for an incoming connection.
                    Socket handler = listener.Accept();

                    Console.WriteLine("Data accepted");

                    data = null;

                    bytes = new byte[1024];
                    int bytesRec = handler.Receive(bytes);
                    Console.WriteLine(bytesRec);
                    data += Encoding.ASCII.GetString(bytes, 0, bytesRec);

                    // Show the data on the console.
                    Console.WriteLine("Text received : {0}", data);

                    List <byte> commandData = new List <byte> ();
                    for (int i = 0; i < bytesRec; i++)
                    {
                        commandData.Add(bytes[i]);
                    }

                    // Echo the data back to the client.
//					byte[] msg = Encoding.ASCII.GetBytes(data);
                    List <byte> fromparser = HeepParser.ParseCommand(commandData, device);
                    byte[]      msg        = new byte[fromparser.Count];

                    for (int i = 0; i < fromparser.Count; i++)
                    {
                        msg[i] = fromparser[i];
                    }


                    handler.Send(msg);
                    handler.Shutdown(SocketShutdown.Both);
                    handler.Close();
                }
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }

            Console.WriteLine("\nPress ENTER to continue...");
            Console.Read();
        }