Exemplo n.º 1
0
 public void Append(SensorItem e)
 {
     try
     {
         InvokeHelper.Invoke(() =>
         {
             Value = e;
             History.Add(e);
             ValueChanged?.Invoke(e);
             NotifyPropertyChanged("History");
         });
     }
     catch (Exception x) {
         Debug.WriteLine(x);
     }
 }
Exemplo n.º 2
0
        public void Append(SensorItem e)
        {
            try
            {
                InvokeHelper.Invoke(() =>
                {
                    Value = e;
                    History.Add(e);
                    ValueChanged?.Invoke(e);
                    NotifyPropertyChanged("History");
                    NotifyPropertyChanged("LastSummary");
                    NotifyPropertyChanged("LastDribble");
                    NotifyPropertyChanged("DribbleHistory");
                });

                Task.Run(() => PostToApi(this, e));
            }
            catch (Exception x) {
                Debug.WriteLine(x);
            }
        }
Exemplo n.º 3
0
        private SensorItem PacketToSensorData(string json)
        {
            try
            {
                var item = JsonConvert.DeserializeObject <SensorData>(json);
                if (Data != null)
                {
                    if (item?.airdata != null)
                    {
                        if (item.airdata.g != 0) // filter
                        {
                            var reading = new SensorItem
                            {
                                offsetMs = item.airdata.t,
                                itemType = SensorItemTypes.Airtime,
                                duration = item.airdata.dt,
                                altitude = item.airdata.alt,
                                force    = item.airdata.g
                            };
                            Data.Append(reading);
                        }
                    }

                    if (item?.turndata != null)
                    {
                        if (item.turndata.g != 0)
                        {
                            var reading = new SensorItem
                            {
                                offsetMs = item.turndata.t,
                                itemType = SensorItemTypes.Turns,
                                duration = item.turndata.dt,
                                radius   = item.turndata.r,
                                force    = item.turndata.g,
                                forceAvg = item.turndata.ga
                            };
                            Data.Append(reading);
                        }
                    }

                    if (item?.dribbledata != null)
                    {
                        if (item.dribbledata.gavg != 0)
                        {
                            var reading = new SensorItem
                            {
                                offsetMs = item.dribbledata.t,
                                itemType = SensorItemTypes.Dribble,
                                duration = item.dribbledata.dt,
                                dribbles = item.dribbledata.c,
                                force    = item.dribbledata.gmax,
                                forceAvg = item.dribbledata.gavg,
                                pace     = item.dribbledata.p
                            };
                            Data.Append(reading);
                        }
                    }

                    if (item?.hurdledata != null)
                    {
                        if (item.hurdledata.angle != 0)
                        {
                            var reading = new SensorItem
                            {
                                offsetMs = item.hurdledata.t,
                                itemType = SensorItemTypes.Hurdle,
                                duration = item.hurdledata.dt,
                                angle    = item.hurdledata.angle,
                                wy       = item.hurdledata.w,
                                force    = item.hurdledata.g
                            };
                            Data.Append(reading);
                        }
                    }

                    if (item?.divedata != null)
                    {
                        if (item.divedata.angle != 0)
                        {
                            var reading = new SensorItem
                            {
                                offsetMs = item.divedata.t,
                                itemType = SensorItemTypes.Diving,
                                duration = item.divedata.dt,
                                angle    = item.divedata.angle,
                                wy       = item.divedata.w,
                                force    = item.divedata.g,
                                hurdles  = item.divedata.hurdles
                            };
                            Data.Append(reading);
                        }
                    }


                    if (item?.rawdata != null)
                    {
                        var reading = new SensorItem
                        {
                            offsetMs    = item.rawdata.t,
                            itemType    = SensorItemTypes.Raw,
                            wx          = item.rawdata.wx * 0.001f * Math.PI / 180.0f,
                            wy          = item.rawdata.wy * 0.001f * Math.PI / 180.0f,
                            wz          = item.rawdata.wz * 0.001f * Math.PI / 180.0f,
                            ax          = item.rawdata.ax * 0.001f * GRAVITY,
                            ay          = item.rawdata.ay * 0.001f * GRAVITY,
                            az          = item.rawdata.az * 0.001f * GRAVITY,
                            orientation = item.rawdata.o
                        };

                        Data.Append(reading);
                    }


                    if (item?.summary != null)
                    {
                        var reading = new SensorItem
                        {
                            offsetMs  = item.summary.t,
                            itemType  = SensorItemTypes.Summary,
                            steps     = item.summary.steps,
                            aircount  = item.summary.air,
                            airgmax   = item.summary.airgmax,
                            airaltmax = item.summary.airaltmax,
                            //turns = item.summary.turns,
                            //tgmax = item.summary.tgmax,
                            //tgavg = item.summary.tgavg,
                            airgavg = item.summary.airgavg,
                            airt    = item.summary.airt,
                            //turnt = item.summary.turnt,
                            sessions = item.summary.dsessions,
                            dribbles = item.summary.dribble,
                            dgmax    = item.summary.dgmax,
                            dgavg    = item.summary.dgavg,
                            pace     = item.summary.dpace
                        };
                        Data.Append(reading);
                    }
                }
            }
            catch (Exception x)
            {
                Debug.WriteLine(x);
            }
            return(null);
        }
Exemplo n.º 4
0
        public static async Task <bool> PostToApi(SensorModel sensor, SensorItem item)
        {
            try
            {
                if (String.IsNullOrEmpty(SensorKit.Instance.API))
                {
                    return(false);
                }

                string rootUrl = SensorKit.Instance.API;
                string url     = rootUrl;
                var    client  = new HttpClient();

                HttpResponseMessage response;

                string json = "";

                if (item.itemType == SensorItemTypes.Dribble)
                {
                    url = rootUrl + "dribblesession";
                    var dribblesession = new dribblesession
                    {
                        deviceId   = sensor.Id.ToString().ToLower(),
                        deviceName = sensor.Name,
                        count      = item.dribbles,
                        duration   = item.duration,
                        gavg       = item.dgavg,
                        gmax       = item.dgmax,
                        pace       = item.pace,
                        tag        = sensor.Tag
                    };
                    json = dribblesession.ToJsonString();
                }
                //else if (item.itemType == SensorItemTypes.Summary)
                //{
                //    url = rootUrl + "dribblesummary";
                //    var dribblesummary = new summary
                //    {
                //        deviceId = Id.ToString().ToLower(),
                //        deviceName = Name,
                //        tag = Tag,
                //        air = item.aircount,
                //        airaltmax = item.airaltmax,
                //        airgavg = item.airgavg,
                //        airgmax = item.airgmax,
                //        airt = item.airt,
                //        steps = (int)item.steps,
                //        dribbleCount = item.dribbles,
                //        dgavg = item.dgavg,
                //        dgmax = item.dgmax,
                //        dpace = item.pace,
                //        dsessions = item.sessions
                //    };
                //    json = dribblesummary.ToJsonString();
                //}

                if (!String.IsNullOrEmpty(json))
                {
                    byte[] byteData = Encoding.UTF8.GetBytes(json);

                    using (var content = new ByteArrayContent(byteData))
                    {
                        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                        response = await client.PostAsync(url, content);
                    }

                    if (response.IsSuccessStatusCode)
                    {
                        return(true);
                    }
                }
            }catch (Exception x)
            {
                Debug.WriteLine(x);
            }

            return(false);
        }