void IndoorLocalizationService::addTrackedDeviceCharacteristic() {

	buffer_ptr_t buffer = MasterBuffer::getInstance().getBuffer();

	_trackedDeviceCharac = new Characteristic<buffer_ptr_t>();
	addCharacteristic(_trackedDeviceCharac);

	_trackedDeviceCharac->setUUID(UUID(getUUID(), TRACKED_DEVICE_UUID));
	_trackedDeviceCharac->setName("Add tracked device");
	_trackedDeviceCharac->setWritable(true);
	_trackedDeviceCharac->setNotifies(false);
	_trackedDeviceCharac->onWrite([&](const buffer_ptr_t& value) -> void {
		TrackedDevice dev;
		dev.assign(_trackedDeviceCharac->getValue(), _trackedDeviceCharac->getValueLength());

		if (dev.getRSSI() > 0) {
			LOGi("Remove tracked device");
			dev.print();
			_trackedDeviceList->rem(dev.getAddress());
		} else {
			LOGi("Add tracked device");
			dev.print();
			_trackedDeviceList->add(dev.getAddress(), dev.getRSSI());
		}
		_trackedDeviceListCharac->setDataLength(_trackedDeviceList->getDataLength());
		_trackedDeviceListCharac->notify();

		LOGi("currently tracking devices:");
		_trackedDeviceList->print();

		// store in persistent memory
		writeTrackedDevices();
		savePersistentStorage();

		if (_trackedDeviceList->getSize() > 0) {
			startTracking();
		}
		else {
			stopTracking();
		}
	});

	_trackedDeviceCharac->setValue(buffer);
	_trackedDeviceCharac->setMaxLength(TRACKDEVICES_SERIALIZED_SIZE);
	_trackedDeviceCharac->setDataLength(0);

}
Beispiel #2
0
void Tracker::addTrackedDevice(TrackedDevice device) {
	_trackedDeviceList->add(device.getAddress(), device.getRSSI());
	writeTrackedDevices();
	publishTrackedDevices();
}
Beispiel #3
0
void Tracker::removeTrackedDevice(TrackedDevice device) {
	_trackedDeviceList->rem(device.getAddress());
	writeTrackedDevices();
	publishTrackedDevices();
}