Пример #1
0
        public static async void SendDeviceContext(HeepDevice theDevice)
        {
            string      deviceIDString = GetDeviceIDString(theDevice.GetDeviceID());
            string      project        = "heep-3cddb";
            FirestoreDb db             = FirestoreDb.Create(project);

            Console.WriteLine("Created Cloud Firestore client with project ID: {0}", project);

            string name = theDevice.GetDeviceName();
            Dictionary <string, object> user = new Dictionary <string, object>
            {
                { "Name", name },
            };
            WriteResult writeResult = await db.Collection("DeviceList").Document(deviceIDString).SetAsync(user);

            for (int i = 0; i < theDevice.GetControlList().Count; i++)
            {
                Control currentControl = theDevice.GetControlList()[i];
                Dictionary <string, object> controlDoc = new Dictionary <string, object>
                {
                    { "Name", currentControl.GetName() },
                    { "ID", currentControl.GetID() },
                    { "Type", (int)currentControl.GetControlType() },
                    { "Direction", (int)currentControl.GetControlDirection() },
                    { "HighValue", currentControl.GetHighValue() },
                    { "LowValue", currentControl.GetLowValue() }
                };

                string      controlDocName = "Control" + i;
                WriteResult controlResult  = await db.Collection("DeviceList").Document(deviceIDString).Collection("Controls").Document(controlDocName).SetAsync(controlDoc);
            }
        }
Пример #2
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);
        }