/* Stores the signals with the provided coordinates. */ private void Fingerprint(string beaconMac, string gatewayMac, int Rssi) { /* If the received signal is not from the beacon to be used fingerprinting, ignore it */ if (!FingerprintingSettings.Fingerprinting_BeaconMacAddress.Equals(beaconMac)) { return; } /* Get gateway */ GatewayDao gwDao = new GatewayDao(); Gateway gateway = gwDao.GetGateway(gatewayMac); FingerprintingDao dao = new FingerprintingDao(); Fingerprinting fingerprinting = new Fingerprinting() { GatewayId = gateway.GatewayId, Rssi = Rssi, Timestamp = DateTime.Now, Xaxis = FingerprintingSettings.Fingerprinting_X, Yaxis = FingerprintingSettings.Fingerprinting_Y, EnvironmentId = FingerprintingSettings.Fingerprinting_EnvironmentId }; dao.NewFingerprint(fingerprinting); }
/* Check whether the gateway was registred or now * If not, it will create a new one otherwise updated last RSSI */ private void CheckGateway(string gatewayMac, string gatewayType) { /* Check the GW */ GatewayDao dao = new GatewayDao(); Gateway gateway = dao.GetGateway(gatewayMac); if (gateway == null) { /* There is no definition for this GW. * Create a new gateway record */ gateway = new Gateway() { GatewayType = gatewayType, MACAddress = gatewayMac, Name = "Unknown", Xaxis = "0", Yaxis = "0", }; /* save new gateway */ dao.NewGateway(gateway); } else { /* Update beacon */ gateway.LastSignalTimestamp = DateTime.Now; dao.UpdateGateway(gateway); } }
private void GetGateways() { GatewayDao gatewayDao = new GatewayDao(); List <Gateway> gateways = gatewayDao.GetGateways(); string json = Newtonsoft.Json.JsonConvert.SerializeObject(gateways); ServiceClient.Send(json); }
/* Updates the gateway that is provided as json */ private void UpdateGateway(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 gateway "; string json = data.Substring(command.Length); Gateway gateway = JsonConvert.DeserializeObject <Gateway>(json); GatewayDao gatewayDao = new GatewayDao(); gatewayDao.UpdateGateway(gateway); ServiceClient.Send(OK); }
private void Position(string beaconMac, string gatewayMac, int rssi) { /* If the received signal is not from the beacon to be used positioning, ignore it */ if (!PositioningParams.Positioning_BeaconMacAddress.Equals(beaconMac)) { return; } /* Get gateway */ GatewayDao gwDao = new GatewayDao(); Gateway gateway = gwDao.GetGateway(gatewayMac); PositioningParams.SetRssi(gateway.GatewayId, rssi); }
private void GetGatewayById(int id) { GatewayDao gatewayDao = new GatewayDao(); Gateway gateway = gatewayDao.GetGatewayById(id); if (gateway == null) { ServiceClient.Send(NOT_FOUND_ERROR); return; } string json = Newtonsoft.Json.JsonConvert.SerializeObject(gateway); ServiceClient.Send(json); }