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