示例#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();
        }
示例#2
0
 public static void AddDeviceIDToMemory(List <byte> dynMem, DeviceID deviceID)
 {
     for (int i = 0; i < deviceID.GetDeviceIDSize(); i++)
     {
         dynMem.Add(deviceID.GetIDArray() [i]);
     }
 }
示例#3
0
 public Vertex(DeviceID rxID, DeviceID txId, int rxControlID, int txControlID, IPAddress destIP)
 {
     _rxID        = rxID;
     _txID        = txId;
     _rxControlID = rxControlID;
     _txControlID = txControlID;
     _destIP      = destIP;
 }
示例#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);
        }
示例#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();
 }
示例#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]);
            }
        }
示例#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);
        }
示例#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));
     }
 }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
            }
        }
示例#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));;
        }
示例#16
0
 public MOPHeader(int _numBytes, DeviceID _deviceID)
 {
     numBytes = _numBytes;
     deviceID = _deviceID;
 }
示例#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);
        }
示例#18
0
 public HeepDevice(DeviceID theID)
 {
     SetDeviceID(theID);
 }
示例#19
0
 public HeepDevice(DeviceID theID)
 {
     SetDeviceID(theID);
     interruptServer = HeepCommunications.GetHeepInterruptServer();
 }
示例#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]);
                }
            }
        }
示例#21
0
 public void SetDeviceID(DeviceID newID)
 {
     myID = newID;
 }
示例#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);
        }