Esempio n. 1
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();
        }
Esempio n. 2
0
 public static void AddDeviceIDToMemory(List <byte> dynMem, DeviceID deviceID)
 {
     for (int i = 0; i < deviceID.GetDeviceIDSize(); i++)
     {
         dynMem.Add(deviceID.GetIDArray() [i]);
     }
 }
Esempio n. 3
0
 public Vertex(DeviceID rxID, DeviceID txId, int rxControlID, int txControlID, IPAddress destIP)
 {
     _rxID        = rxID;
     _txID        = txId;
     _rxControlID = rxControlID;
     _txControlID = txControlID;
     _destIP      = destIP;
 }
Esempio n. 4
0
        public static MOPHeader UnwrapMOPHeader(List <byte> buffer, ref int counter)
        {
            DeviceID newDeviceID = HeepLanguage.GetDeviceIDFromBuffer(buffer, ref counter);

            int       numBytes = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);
            MOPHeader header   = new MOPHeader(numBytes, newDeviceID);

            return(header);
        }
Esempio n. 5
0
 public static void PrintDeviceID(DeviceID deviceID)
 {
     Console.Write("FOUND ID: ");
     for (int i = 0; i < deviceID.GetDeviceIDSize(); i++)
     {
         Console.Write(deviceID.GetIDArray() [i] + " ");
     }
     Console.WriteLine();
 }
Esempio n. 6
0
        public static void AddNameToMemory(List <byte> dynMem, DeviceID deviceID, String deviceName)
        {
            dynMem.Add(DeviceNameOpCode);
            AddDeviceIDToMemory(dynMem, deviceID);

            dynMem.Add((byte)deviceName.Length);
            for (int i = 0; i < deviceName.Length; i++)
            {
                dynMem.Add((byte)deviceName [i]);
            }
        }
Esempio n. 7
0
        public static void SendAnalytics(DeviceID deviceID, List <byte> memoryDump)
        {
            List <byte> deviceIDList   = deviceID.GetIDArray();
            string      base64deviceID = Convert.ToBase64String(deviceIDList.ToArray());

            Debug.Log("Saving Analytics for " + base64deviceID);
            string url = "https://heep-3cddb.firebaseio.com/analytics/" + base64deviceID + ".json";

            string base64 = Convert.ToBase64String(memoryDump.ToArray());
            string data   = "\"" + base64 + "\"";

            POST(url, data);
        }
Esempio n. 8
0
 public static List <byte> GetDeviceAnalyticsByteArray(Control controlToSend, DeviceID theID)
 {
     if (controlToSend.GetType().Equals(typeof(BufferControl)))
     {
         Debug.Log("Analytic Data Created at " + DateTime.Now + " for CtrlID " + controlToSend.GetID() + " with buffer length " + ((BufferControl)controlToSend).GetBuffer().Count);
         return(GetAnalyticsByteArrayForBufferControl((BufferControl)controlToSend, theID));
     }
     else
     {
         Debug.Log("Analytic Data Created at " + DateTime.Now + " for CtrlID " + controlToSend.GetID() + " with Value " + controlToSend.GetCurValue());
         return(GetAnalyticsByteArrayForControl(controlToSend, theID));
     }
 }
Esempio n. 9
0
        public static void GetMemoryDump(List <byte> buffer, DeviceID deviceID, int firmwareVersion, List <Control> controlList, List <byte> dynMem, int dynMemSize)
        {
            List <byte> coreMemoryBuffer = new List <Byte> ();

            AddCoreMemoryToBuffer(coreMemoryBuffer, deviceID, firmwareVersion, controlList, dynMemSize);

            int totalMemory = coreMemoryBuffer.Count + dynMem.Count;

            buffer.Add(MemoryDumpOpCode);
            AddDeviceIDToMemory(buffer, deviceID);
            buffer.Add((byte)totalMemory);

            AddBufferToBuffer(buffer, coreMemoryBuffer);
            AddBufferToBuffer(buffer, dynMem);
        }
Esempio n. 10
0
        public static string GetDeviceIDString(DeviceID deviceID)
        {
            List <byte> deviceIDList = deviceID.GetIDArray();

            StringBuilder hex = new StringBuilder(deviceIDList.Count * 2);

            foreach (byte b in deviceIDList)
            {
                hex.AppendFormat("{0:x2}", b);
            }

            string deviceIDString = hex.ToString();

            return(deviceIDString);
        }
Esempio n. 11
0
        public static void AddCoreMemoryToBuffer(List <byte> buffer, DeviceID deviceID, int firmwareVersion, List <Control> controlList, int dynamicMemorySize)
        {
            // Client Data
            buffer.Add(ClientDataOpCode);
            AddDeviceIDToMemory(buffer, deviceID);
            buffer.Add(0x01);              // Num Bytes
            buffer.Add((byte)firmwareVersion);

            // Control Data
            AddControlDataToBuffer(buffer, controlList, deviceID);

            // Dynamic memory size
            buffer.Add(DynamicMemorySizeOpCode);
            AddDeviceIDToMemory(buffer, deviceID);
            buffer.Add(0x01);
            buffer.Add((byte)dynamicMemorySize);
        }
Esempio n. 12
0
        public static DeviceID GetDeviceIDFromBuffer(List <byte> buffer, ref int position)
        {
            List <byte> deviceBytes = new List <byte> ();

            int numBytesInID = 4;             // This will be read dynamically once we have dynamic iDs

            for (int i = position; i < position + numBytesInID; i++)
            {
                deviceBytes.Add(buffer [i]);
            }

            position += numBytesInID;

            DeviceID retID = new DeviceID(deviceBytes);

            return(retID);
        }
Esempio n. 13
0
        public static Vertex parseVertexMOP(List <byte> buffer, ref int counter)
        {
            MOPHeader header = UnwrapMOPHeader(buffer, ref counter);

            DeviceID  txID        = header.deviceID;
            DeviceID  rxID        = HeepLanguage.GetDeviceIDFromBuffer(buffer, ref counter);
            int       txControlID = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);
            int       rxControlID = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);
            IPAddress rxIPAddress = HeepLanguage.GetIPAddrFromBuffer(buffer, counter);

            counter += 4;

            Vertex newVertex = new Vertex(rxID, txID, rxControlID, txControlID, rxIPAddress);

            Console.WriteLine("Adding a vertex named: " + newVertex.GetDestIP());

            return(newVertex);
        }
Esempio n. 14
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);
            }
        }
Esempio n. 15
0
        public static List <byte> ParseSetVertexCommand(List <byte> commandBuffer, HeepDevice theDevice)
        {
            int counter = 1;

            HeepLanguage.GetNumberFromBuffer(commandBuffer, ref counter, 1);
            DeviceID txID      = HeepLanguage.GetDeviceIDFromBuffer(commandBuffer, ref counter);
            DeviceID rxID      = HeepLanguage.GetDeviceIDFromBuffer(commandBuffer, ref counter);
            int      txControl = HeepLanguage.GetNumberFromBuffer(commandBuffer, ref counter, 1);

            int rxControl = HeepLanguage.GetNumberFromBuffer(commandBuffer, ref counter, 1);

            IPAddress destIP = HeepLanguage.GetIPAddrFromBuffer(commandBuffer, counter);

            Vertex newVertex = new Vertex(rxID, txID, rxControl, txControl, destIP);

            theDevice.AddVertex(newVertex);

            return(AddSuccessMessageToBuffer("Vertex Set", theDevice));;
        }
Esempio n. 16
0
 public MOPHeader(int _numBytes, DeviceID _deviceID)
 {
     numBytes = _numBytes;
     deviceID = _deviceID;
 }
Esempio n. 17
0
        private static List <byte> GetAnalyticsByteArrayForControl(Control theControl, DeviceID theID)
        {
            List <byte> byteArray = new List <byte> ();

            byteArray.Add(HeepLanguage.AnalyticsData);
            HeepLanguage.AddDeviceIDToMemory(byteArray, theID);

            List <byte> timeArray = GetMillisecondsByteArray();

            byte numBytes = (byte)(timeArray.Count + 5);

            byteArray.Add(numBytes);
            byteArray.Add((byte)theControl.GetID());
            byteArray.Add(1);              // Only support 1 byte control values with this right now
            byteArray.Add((byte)theControl.GetCurValue());
            byteArray.Add(1);              // Unity is only running on absolute time for the moment
            byteArray.Add((byte)timeArray.Count);

            for (int i = 0; i < timeArray.Count; i++)
            {
                byteArray.Add(timeArray [timeArray.Count - i - 1]);
            }

            string printableString = "";

            for (int i = 0; i < byteArray.Count; i++)
            {
                printableString += byteArray [i];
                printableString += " ";
            }

            Debug.Log(printableString);

            return(byteArray);
        }
Esempio n. 18
0
 public HeepDevice(DeviceID theID)
 {
     SetDeviceID(theID);
 }
Esempio n. 19
0
 public HeepDevice(DeviceID theID)
 {
     SetDeviceID(theID);
     interruptServer = HeepCommunications.GetHeepInterruptServer();
 }
Esempio n. 20
0
        public static void AddControlDataToBuffer(List <byte> buffer, List <Control> controlList, DeviceID deviceID)
        {
            for (int i = 0; i < controlList.Count; i++)
            {
                buffer.Add(ControlOpCode);
                AddDeviceIDToMemory(buffer, deviceID);
                int  dataSize = controlList [i].GetName().Length + 6;
                byte numBytes = (byte)dataSize;
                buffer.Add(numBytes);
                buffer.Add((byte)controlList [i].GetID());
                buffer.Add((byte)controlList [i].GetControlType());
                buffer.Add((byte)controlList [i].GetControlDirection());
                buffer.Add((byte)controlList [i].GetLowValue());
                buffer.Add((byte)controlList [i].GetHighValue());
                buffer.Add((byte)controlList [i].GetCurValue());

                for (int j = 0; j < controlList [i].GetName().Length; j++)
                {
                    buffer.Add((byte)controlList [i].GetName() [j]);
                }
            }
        }
Esempio n. 21
0
 public void SetDeviceID(DeviceID newID)
 {
     myID = newID;
 }
Esempio n. 22
0
        private static List <byte> GetAnalyticsByteArrayForBufferControl(BufferControl theControl, DeviceID theID)
        {
            List <byte> byteArray = new List <byte> ();

            byteArray.Add(HeepLanguage.AnalyticsData);
            HeepLanguage.AddDeviceIDToMemory(byteArray, theID);

            byte bytesToRecord = theControl.GetBuffer().Count > 10 ? (byte)10 : (byte)theControl.GetBuffer().Count;

            List <byte> timeArray = GetMillisecondsByteArray();

            byte numBytes = (byte)(timeArray.Count + bytesToRecord + 4);

            byteArray.Add(numBytes);
            byteArray.Add((byte)theControl.GetID());

            byteArray.Add(bytesToRecord);

            for (int i = 0; i < bytesToRecord; i++)
            {
                byteArray.Add(theControl.GetBuffer() [i]);
            }

            byteArray.Add(1);              // Unity is only running on absolute time for the moment
            byteArray.Add((byte)timeArray.Count);

            for (int i = 0; i < timeArray.Count; i++)
            {
                byteArray.Add(timeArray [timeArray.Count - i - 1]);
            }

            string printableString = "";

            for (int i = 0; i < byteArray.Count; i++)
            {
                printableString += byteArray [i];
                printableString += " ";
            }

            Debug.Log(printableString);

            return(byteArray);
        }