Esempio n. 1
0
        public static String parseDeviceNameMOP(List <byte> buffer, ref int counter)
        {
            MOPHeader header = UnwrapMOPHeader(buffer, ref counter);

            Console.WriteLine(header.numBytes);
            return(HeepLanguage.GetStringFromBuffer(buffer, ref counter, header.numBytes));
        }
Esempio n. 2
0
        public static string GetNameFromBuffer(List <byte> buffer)
        {
            string name    = "";
            int    counter = 0;

            while (counter < buffer.Count)
            {
                byte nextMOP = buffer[counter];
                counter += 1;

                MOPHeader header = UnwrapMOPHeader(buffer, ref counter);

                if (nextMOP == HeepLanguage.DeviceNameOpCode)
                {
                    for (int i = 0; i < header.numBytes; i++)
                    {
                        name += (char)buffer[i + counter];
                    }
                }

                counter += header.numBytes;
            }

            return(name);
        }
Esempio n. 3
0
        public static List <Vertex> GetVerticesFromBuffer(List <byte> buffer)
        {
            int counter = 0;

            List <Vertex> vertexList = new List <Vertex>();

            while (counter < buffer.Count)
            {
                byte nextMOP = buffer [counter];
                counter += 1;

                Console.WriteLine("Next MOP: " + nextMOP);

                if (nextMOP == HeepLanguage.VertexOpCode)
                {
                    Vertex newVertex = parseVertexMOP(buffer, ref counter);
                    vertexList.Add(newVertex);
                }
                else
                {
                    MOPHeader header = UnwrapMOPHeader(buffer, ref counter);
                    counter += header.numBytes;
                }
            }

            return(vertexList);
        }
Esempio n. 4
0
        public static string GetAnalyticsStringFromMemory(List <byte> AnalyticsContainingBuffer)
        {
            List <byte> AnalyticsBuffer = new List <byte>();
            int         counter         = 0;

            while (counter < AnalyticsContainingBuffer.Count)
            {
                int  startCounter = counter;
                byte nextMOP      = AnalyticsContainingBuffer[counter];
                counter += 1;

                MOPHeader header = UnwrapMOPHeader(AnalyticsContainingBuffer, ref counter);

                if (nextMOP == HeepLanguage.AnalyticsData)
                {
                    for (int i = 0; i < header.numBytes + 6; i++)
                    {
                        AnalyticsBuffer.Add(AnalyticsContainingBuffer[i + startCounter]);
                    }

                    AnalyticsContainingBuffer[startCounter] = HeepLanguage.FragmentOpCode;
                }

                counter += header.numBytes;
            }

            return(Convert.ToBase64String(AnalyticsBuffer.ToArray()));

            //char[] chars = new char[AnalyticsBuffer.Count / sizeof(char)];
            //System.Buffer.BlockCopy(AnalyticsBuffer.ToArray(), 0, chars, 0, AnalyticsBuffer.Count);
            //return new string(chars);

            //return Encoding.UTF8.GetString(AnalyticsBuffer.ToArray(), 0, AnalyticsBuffer.Count);
            //return System.Text.Encoding.ASCII.GetString(AnalyticsBuffer.ToArray());
        }
Esempio n. 5
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. 6
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. 7
0
        public static void ParseMemoryDump(List <byte> buffer)
        {
            int counter = 1;

            MOPHeader memoryDumpHeader = UnwrapMOPHeader(buffer, ref counter);
            int       firmwareVersion  = 0;

            String         Devicename  = "";
            List <Control> controlList = new List <Control>();
            List <Vertex>  vertexList  = new List <Vertex>();

            while (counter < buffer.Count)
            {
                byte nextMOP = buffer [counter];
                counter += 1;

                Console.WriteLine("Next MOP: " + nextMOP);

                if (nextMOP == HeepLanguage.ClientDataOpCode)
                {
                    firmwareVersion = parseClientDataOpCode(buffer, ref counter);
                    Console.WriteLine("Firmware Version: " + firmwareVersion);
                }
                else if (nextMOP == HeepLanguage.ControlOpCode)
                {
                    Control newControl = parseControlMOP(buffer, ref counter);
                    controlList.Add(newControl);
                }
                else if (nextMOP == HeepLanguage.VertexOpCode)
                {
                    Vertex newVertex = parseVertexMOP(buffer, ref counter);
                    vertexList.Add(newVertex);
                }
                else if (nextMOP == HeepLanguage.DeviceNameOpCode)
                {
                    Devicename = parseDeviceNameMOP(buffer, ref counter);
                }
                else
                {
                    MOPHeader header = UnwrapMOPHeader(buffer, ref counter);
                    counter += header.numBytes;
                }
            }
        }
Esempio n. 8
0
        public static Control parseControlMOP(List <byte> buffer, ref int counter)
        {
            MOPHeader header = UnwrapMOPHeader(buffer, ref counter);

            int controlID        = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);
            int controlType      = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);
            int controlDirection = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);
            int lowValue         = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);
            int highValue        = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);
            int curValue         = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);

            string controlName = HeepLanguage.GetStringFromBuffer(buffer, ref counter, header.numBytes - 6);

            Control newControl = new Control(controlID, (Heep.Control.CtrlInputOutput)controlDirection, (Heep.Control.CtrlType)controlType, highValue, lowValue, curValue, controlName);

            Console.WriteLine("Adding a control named: " + controlName);

            return(newControl);
        }
Esempio n. 9
0
        public static bool DeviceNameOpCodeAlreadySet(List <byte> buffer)
        {
            int counter = 0;

            while (counter < buffer.Count)
            {
                byte nextMOP = buffer [counter];
                counter += 1;

                if (nextMOP == HeepLanguage.DeviceNameOpCode)
                {
                    return(true);
                }

                MOPHeader header = UnwrapMOPHeader(buffer, ref counter);
                counter += header.numBytes;
            }

            return(false);
        }