Ejemplo n.º 1
0
        /* Check whether the beacon was registred or now
         * If not, it will create a new one otherwise updated last RSSI
         * and timestamp */
        private void CheckBeacon(string beaconMac, int rssi)
        {
            /* Check the beacon */
            BeaconDao dao    = new BeaconDao();
            Beacon    beacon = dao.GetBeacon(beaconMac);

            if (beacon == null)
            {
                /* There is no definition for this beacon.
                 * Create a new beacon record */
                beacon = new Beacon()
                {
                    MACAddress = beaconMac,
                    LastRssi   = rssi,
                    Name       = "Unknown",
                };

                /* save new beacon */
                dao.NewBeacon(beacon);
            }
            else
            {
                /* Update beacon */
                beacon.LastSignalTimestamp = DateTime.Now;
                beacon.LastRssi            = rssi;
                dao.UpdateBeacon(beacon);
            }
        }
Ejemplo n.º 2
0
        private void GetBeacons()
        {
            BeaconDao     beaconDao = new BeaconDao();
            List <Beacon> beacons   = beaconDao.GetBeacons();

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(beacons);

            ServiceClient.Send(json);
        }
Ejemplo n.º 3
0
        /* Updates the beacon that is provided as json */
        private void UpdateBeacon(string data)
        {
            /* we are triming data below, splitting it by blank chars is not a valid way.
             * because blank char can become in the json object as well */
            string command = "update beacon ";
            string json    = data.Substring(command.Length);

            Beacon    beacon    = JsonConvert.DeserializeObject <Beacon>(json);
            BeaconDao beaconDao = new BeaconDao();

            beaconDao.UpdateBeacon(beacon);
            ServiceClient.Send(OK);
        }
Ejemplo n.º 4
0
        private void GetBeaconById(int id)
        {
            BeaconDao beaconDao = new BeaconDao();
            Beacon    beacon    = beaconDao.GetBeaconById(id);

            if (beacon == null)
            {
                ServiceClient.Send(NOT_FOUND_ERROR);
                return;
            }

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(beacon);

            ServiceClient.Send(json);
        }
Ejemplo n.º 5
0
        /* Updates the beacon that is provided as json */
        private void SetMode(string[] dataItems)
        {
            /* Check data */
            if (dataItems.Length < 3)
            {
                ServiceClient.Send(CreateError_SetMode());
                return;
            }

            string mode = dataItems[2];

            /* If mode string is invalid */
            if (!ServerSettings.Modes.ContainsKey(mode))
            {
                ServiceClient.Send(CreateError_SetMode());
                return;
            }

            /* If fingerprinting mode is being tried to set */
            if (ServerSettings.Modes[mode] == Enums.ServerModes.Fingerprinting)
            {
                /* Check the command whether it is valid for the fingerprinting */
                if (dataItems.Length < 11)
                {
                    ServiceClient.Send(CreateError_SetMode());
                    return;
                }

                /* Check the parameters */
                int envIndex = GetIndex(dataItems, "-env");
                if (envIndex == -1)
                {
                    ServiceClient.Send(CreateError_SetMode());
                    return;
                }
                int beaconIndex = GetIndex(dataItems, "-beacon");
                if (beaconIndex == -1)
                {
                    ServiceClient.Send(CreateError_SetMode());
                    return;
                }
                int xIndex = GetIndex(dataItems, "-x");
                if (xIndex == -1)
                {
                    ServiceClient.Send(CreateError_SetMode());
                    return;
                }
                int yIndex = GetIndex(dataItems, "-y");
                if (yIndex == -1)
                {
                    ServiceClient.Send(CreateError_SetMode());
                    return;
                }
                /* Exceptions will be handled by ServiceClient */
                int env      = int.Parse(dataItems[envIndex + 1]);
                int beaconId = int.Parse(dataItems[beaconIndex + 1]);
                int x        = int.Parse(dataItems[xIndex + 1]);
                int y        = int.Parse(dataItems[yIndex + 1]);

                /* Get the mac address of the beacon provided! */
                BeaconDao dao    = new BeaconDao();
                Beacon    beacon = dao.GetBeaconById(beaconId);

                /*Set coordinates*/
                FingerprintingSettings.Fingerprinting_EnvironmentId    = env;
                FingerprintingSettings.Fingerprinting_BeaconId         = beaconId;
                FingerprintingSettings.Fingerprinting_BeaconMacAddress = beacon.MACAddress;
                FingerprintingSettings.Fingerprinting_X = x;
                FingerprintingSettings.Fingerprinting_Y = y;
            }
            else if (ServerSettings.Modes[mode] == Enums.ServerModes.Positioning)
            {
                /* Check the command whether it is valid for positioning */
                if (dataItems.Length < 5)
                {
                    ServiceClient.Send(CreateError_SetMode());
                    return;
                }
                /* Check the parameters */
                int beaconIndex = GetIndex(dataItems, "-beacon");
                if (beaconIndex == -1)
                {
                    ServiceClient.Send(CreateError_SetMode());
                    return;
                }

                int beaconId = int.Parse(dataItems[beaconIndex + 1]);
                /* Get the mac address of the beacon provided! */
                BeaconDao dao    = new BeaconDao();
                Beacon    beacon = dao.GetBeaconById(beaconId);

                /* Set the beacon to be positioned */
                PositioningParams.Positioning_BeaconId         = beaconId;
                PositioningParams.Positioning_BeaconMacAddress = beacon.MACAddress;
            }

            /* Set mode */
            ServerSettings.ServerMode = ServerSettings.Modes[mode];
            ServiceClient.Send(OK);
        }