Exemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (!(obj is DRP))
            {
                return(false);
            }
            DRP compto = obj as DRP;

            if (this.devType != compto.devType)
            {
                return(false);
            }
            if (this.servID != compto.servID)
            {
                return(false);
            }
            if (this.servName != compto.ServName)
            {
                return(false);
            }
            if (!JsonConvert.SerializeObject(data).Equals(JsonConvert.SerializeObject(compto.data)))
            {
                return(false);
            }
            if (this.messageType != compto.messageType)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        /**
         * Deserializing DRP message
         * @param mepMessage the string to deserialize
         * EXAMPLE:
         * {"$DRP":{"DevType":"RBPI","MACAddr":"123456789ABC","IPAddr":"C0A80101","Callback":"RES","Addressee":"123456789ABC","Date": "28/07/2017 19:02"}}
         **/

        public static DRP deserializeDRP(string drpMessage)
        {
            drpMessage = drpMessage.Replace('?', '\"');
            DRP drp = JsonConvert.DeserializeObject <DRP>(drpMessage);

            return(drp);
        }
Exemplo n.º 3
0
        private async Task TalkToRaspberry()
        {
            string ip = ipaddress;

            if (!await tcps.Connect(ip))
            {
                System.Diagnostics.Debug.WriteLine("Connection failed.");
                handleGUI_OnFailure("Connection failed.");
                return;
            }

            DRP result = await sendSCANNED();

            if (result == null)
            {
                //in case there's no answer from the server
                handleGUI_OnFailure("Connection Timeout");
                return;
            }
            FindViewById <TextView>(Resource.Id.tv_servname).Visibility = ViewStates.Visible;
            FindViewById <TextView>(Resource.Id.tv_servname).Text       = result.ServName;
            if (result.MessageType == DRPMessageType.DATA)
            {
                currentWeigh = result.Data;
                handleGUI_OnSuccess(result.Data.ToString());

                if (isStreamAnalytics)
                {
                    var newweightablerecord = new weighTable
                    {
                        username = ourUserId,
                        weigh    = currentWeigh
                    };
                    try
                    {
                        MobileServiceClient client = ToDoActivity.CurrentActivity.CurrentClient;
                        weighTableRef = client.GetTable <weighTable>();
                        await weighTableRef.InsertAsync(newweightablerecord);
                    }
                    catch (Exception e)
                    {
                        CreateAndShowDialog(e, "Error");
                    }
                }

                return;
            }
            else if (result.MessageType == DRPMessageType.IN_USE)
            {
                handleGUI_OnFailure("the scale is in use");
                return;
            }
            else if (result.MessageType == DRPMessageType.ILLEGAL || result.MessageType == DRPMessageType.HARDWARE_ERROR)
            {
                handleGUI_OnFailure("The scaling could not been done due to error.");
                return;
            }
        }
Exemplo n.º 4
0
        //sending a message of type SCANNED to the RBPi and waiting to the result
        private async Task <DRP> sendSCANNED()
        {
            DRP msg = new DRP(DRPDevType.APP, ourUserId, "111", "don't care", 0, 0, DRPMessageType.SCANNED);

            try
            {
                //sending the message
                await tcps.Send(msg.ToString());

                string ans = await tcps.Receive();

                DRP rec = DRP.deserializeDRP(ans);
                return(rec);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception caught in SendScanned : " + e.Message);
                return(null);
            }
        }