Example #1
0
        public static async Task SendTrespassEvent(int uavId)
        {
            var uav = await db.UAVs.FindAsync(uavId);
            EventLog evt = new EventLog();
            evt.uav_id = uav.Id;
            evt.uav_callsign = uav.Callsign;
            evt.criticality = "critical";
            evt.message = uav.Callsign + " Trespassing";
            evt.create_date = DateTime.Now;
            evt.modified_date = DateTime.Now;
            //wtf seriously? -- why is this in here twice...
            evt.UAVId = uav.Id;
            evt.operator_screen_name = "NEST";
            eventHub.Clients.All.newEvent(evt);

            
            db.EventLogs.Add(evt);
            await db.SaveChangesAsync();
            eventHub.Clients.All.newEvent(evt);
        }
Example #2
0
        public async Task PushFlightStateUpdate(FlightStateDTO dto){
            Clients.All.flightStateUpdate(dto);
            //await TrespassChecker.ReportTrespassIfNecesarry(dto.UAVId, dto.Latitude, dto.Longitude);
            var eventHub = GlobalHost.ConnectionManager.GetHubContext<EventLogHub>();
            UAV uav = db.UAVs.FirstOrDefault(x => x.Id == dto.Id);
            double lat = Math.Round(dto.Latitude * 10000) / 10000;
            double lon = Math.Round(dto.Longitude * 10000) / 10000;

            var mis = from ms in db.Missions
                      where ms.ScheduleId == uav.Id
                      select ms;

            //look up the uav
            bool areaList = (areaWarning.Where(u => u.Id == uav.Id).Count()) > 0;
            bool batteryList = (batteryWarning.Where(u => u.Id == uav.Id).Count()) > 0 ;
            if (!areaList)
            {
                bool check = db.MapRestrictedSet.Where(
                    u => u.SouthWestLatitude < mis.FirstOrDefault().Latitude &&
                        u.NorthEastLatitude > mis.FirstOrDefault().Latitude &&
                        u.SouthWestLongitude < mis.FirstOrDefault().Longitude &&
                        u.NorthEastLongitude > mis.FirstOrDefault().Longitude
                    ).Count() > 0;
                if (check)
                {
                    areaWarning.Add(uav);

                    EventLog evt = new EventLog();
                    evt.event_id = events;
                    evt.uav_id = uav.Id;
                    evt.uav_callsign = uav.Callsign;
                    evt.criticality = "critical";
                    evt.message = "Delivery is in restricted area";
                    evt.create_date = DateTime.Now;
                    evt.modified_date = DateTime.Now;
                    //wtf seriously? -- why is this in here twice...
                    evt.UAVId = uav.Id;
                    evt.operator_screen_name = "jimbob";
                    eventHub.Clients.All.newEvent(evt);

                    db.EventLogs.Add(evt);
                    events++;

                }
            }

            //it's not in the battery list
            if( !batteryList ) {
                if (dto.BatteryLevel < .2)
                {
                    //add list -- stops from sending warning everytime
                    batteryWarning.Add(uav);

                    EventLog evt = new EventLog();
                        evt.event_id = events;
                        evt.uav_id = uav.Id;
                        evt.uav_callsign = uav.Callsign;
                        evt.criticality = "critical";
                        evt.message = "Low Battery";
                        evt.create_date = DateTime.Now;
                        evt.modified_date = DateTime.Now;
                        //wtf seriously? -- why is this in here twice...
                        evt.UAVId = uav.Id;
                        evt.operator_screen_name = "jimbob";
                        eventHub.Clients.All.newEvent(evt);

                    db.EventLogs.Add(evt);
                    events++;

                }
            }

            try
            {
                db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            
            // flightstatedto entity is not the same as models in our db context. can not guarantee atomic. need to wipe out flightstatedto
        }
Example #3
0
        public async Task<HttpResponseMessage> PostUavEvent(EventLog evnt)
        {
            evnt.create_date = DateTime.Now;
            evnt.modified_date = DateTime.Now;
            _db.EventLogs.Add(evnt);

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            return Request.CreateResponse(HttpStatusCode.OK);
        }