-
Notifications
You must be signed in to change notification settings - Fork 4
Applications
Northshoot edited this page Dec 16, 2014
·
8 revisions
Following subsections contain description of applications and some ideas for syntactic sugar.
Embedded device is attached on a plastic pipe which is connected between the shower arm and the head. Water flows via device pipe rotating a propeller which generates current. Water flow is determined by the current generation rate e.g. propeller rotation speed.
On boot device initiates BLE, Flash, Temperature, Flow (flow sensor is basically an interrupt counter) and software interrupt which serves as a periodic timer. On software interrupt:
- app reads temperature and flow values, the new values are compared to old ones and if there is change a record is created and stored on flash.
- checks if BLE is connected, if yes available records on flash are transmitted via indicate.
Application:
class WaterSaver extends TockApp implements BLEUser, SensorUser{
private static ResourceManager rm;
private byte mTemperature;
private int mFlow;
private SensorResource mTemperatureResource;
private SensorResource mFlowResource;
private usigned int mStorageCapacity = 1000;
private StorageResource mStorageResource;
private static final int mPeriod = 1000;
private boolean mReading;
private boolean mConnected;
private BLEDevice mDataOut;
private DataRecord dr;
private final static String APP_KEY = "xxxxxxx"
//called when the application is started
public void onBoot(ResourceManager resourcemanager){
this.rm = resourcemanager;
mDataOut = null;
dr = new DataRecord(); //assuming some serializible implemented class
//get a resource from kernel
mTemperature = rm.getResource(Platforms.Storm.Sensors.Temperature);
//the application never accesses resources, instead, resrouce write data to
//applications variable
//this way the application or driver cannot pass the resource anywere else
mTemperature.updateWithReading(mTemperature, 1000);
mFlow = rm.getResource(Platforms.Storm.Sensors.Flow);
mStorageResource = rm.getRsource(Platform.Storm.Flash);
//some syntactic sugar for flash
mStorageResource.setEncryptionKey(APP_KEY);
mStorageResource.create(Tock.Storage.CircularBuffer, Tock.Storage.Types.FIFO, sizeof(DataRecordImpl)*mStorageCapacity);
//configure BLE, jsut a place holder
rm.getResource(Platforms.Storm.BLE).setBLEService('ble_service_descrition.xml');
}
//called after period sleep
public void onWakeUp(){
}
//somebody connected to the provided service
public void BLEUser.serviceSubscribed(BLEDevice ble){
mConnected = true;
mDataOut = ble;
}
public void BLEUser.dataSent(boolean status){
if(!mStorageResource.isEmpty() && mConnected && mDataOut){
DataRecord dr = mStorageResource.getFirst();
boolean status = mDataOut.send(dr);
if (status){
mStorageResource.delete(dr);
}
}
}
public void BLEUser.serviceUnSubscribed(BLEDevice ble){
mConnected = false;
mDataOut = null;
}
public void mTemperatureResource.onReadingUpdated(boolean status){
if (status){
}
}
public void onEnteringLP(){
}
private void storeRecord(DataRecord dr){
if(mConnected && mDataOut){
boolean status = mDataOut.send(dr);
if (!status) {
mStorageResource.write(dr);
}
} else {
mStorageResource.write(dr);
}
}
}