예제 #1
0
        public static int parseClientDataOpCode(List <byte> buffer, ref int counter)
        {
            UnwrapMOPHeader(buffer, ref counter);

            int firmwareversion = HeepLanguage.GetNumberFromBuffer(buffer, ref counter, 1);

            return(firmwareversion);
        }
예제 #2
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);
        }
예제 #3
0
        private void AddNewAnalyticsDataToDeviceMemory(Control changedControl)
        {
            if (changedControl.ShouldKeepAnalytics())
            {
                List <byte> analyticsBuffer = HeepDeviceAnalytics.GetDeviceAnalyticsByteArray(changedControl, myID);
                HeepLanguage.AddBufferToBuffer(deviceMemory, analyticsBuffer);

                HeepCommunications.SendAnalytics(myID, deviceMemory);
            }
        }
예제 #4
0
        private void AddNewAnalyticsDataToDeviceMemory(Control changedControl)
        {
            if (changedControl.ShouldKeepAnalytics())
            {
                Console.WriteLine("Hello");

                List <byte> analyticsBuffer = HeepDeviceAnalytics.GetDeviceAnalyticsByteArray(changedControl, myID);
                HeepLanguage.AddBufferToBuffer(deviceMemory, analyticsBuffer);
                NonVolatileData.WriteMemoryToFile(deviceMemory);

                HeepCommunications.SendAnalytics(myID, deviceMemory);
            }
        }
예제 #5
0
        private static List <byte> GetMillisecondsByteArray()
        {
            DateTime startTime = new DateTime(2017, 12, 20, 0, 0, 0);
            DateTime curTime   = DateTime.Now;

            double milliSeconds           = ((curTime - startTime).TotalSeconds) * 1000;
            ulong  fixedPointMilliSeconds = (ulong)milliSeconds;
            //Debug.Log ("Milliseconds from " + startTime + " to now is " + fixedPointMilliSeconds);

            List <byte> milliSecondByteArray = HeepLanguage.GetByteArrayFromULong(fixedPointMilliSeconds);

            return(milliSecondByteArray);
        }
예제 #6
0
 private void SendOutput(Control toSend)
 {
     // Send the current value of the control
     if (toSend.GetControlDirection() == (int)Control.CtrlInputOutput.output)
     {
         for (int i = 0; i < vertices.Count; i++)
         {
             if (vertices [i].GetTXControlID() == toSend.GetID())
             {
                 List <byte> sendBuffer = HeepLanguage.GetSetValCOPBuffer(vertices [i].GetRXControlID(), toSend.GetCurValue());
                 IPAddress   sendIP     = vertices [i].GetDestIP();
                 HeepCommunications.SendBufferToIP(sendBuffer, sendIP);
             }
         }
     }
 }
예제 #7
0
        private static List <byte> AddErrorMessageToBuffer(String message, HeepDevice theDevice)
        {
            List <byte> outputBuf = new List <byte>();

            outputBuf.Add(HeepLanguage.ErrorOpCode);
            HeepLanguage.AddDeviceIDToMemory(outputBuf, theDevice.GetDeviceID());

            byte stringLength = (byte)message.Length;

            outputBuf.Add(stringLength);

            for (int i = 0; i < message.Length; i++)
            {
                outputBuf.Add((byte)message [i]);
            }

            return(outputBuf);
        }
예제 #8
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);
        }
예제 #9
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));;
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
0
 public void AddVertex(Vertex newVertex)
 {
     vertices.Add(newVertex);
     HeepLanguage.AddVertexToMemory(deviceMemory, newVertex);
     NonVolatileData.WriteMemoryToFile(deviceMemory);
 }
예제 #13
0
 public void SetDeviceName(String name)
 {
     HeepLanguage.AddNameToMemory(deviceMemory, myID, name);
     NonVolatileData.WriteMemoryToFile(deviceMemory);
 }