Node Core Behaviour Design
From Glacsweb Wiki
Below is the pseudo code for the planned development of contiki code for Sensinode.
Main
int main(void){ while(1){ Config(); //On startup wait for config message to sync clock and be told to run. Run(); //After config has be recived then the node runs independatly forever (or untill batteries run out). } return 0; }
int Config(void){ TurnOnLeds(3); while( "Not recived config packet" ){ //check for config radio packet. } "TIME" currentTime = GetConfigTime(); SetClock(currentTime); return 1; }
int Run(void){ while(1){ "TIME" currentTime = ReadClock(); if( "Time to Take readings" ){ TakeAllReadings(); SetWakeUpTimer(); } else{ TakeAllReadings(); SendReciveData(); SetWakeUpTimer(); } Sleep(); } }
Leds
int TurnOnLeds(int LEDId){ if(LEDId == 1){ // Turn on LED 1 } else if(LEDId == 2){ // Turn on LED 2 } else{ //Turn on LED 1 & 2 } return 1; }
int TurnOffLeds(int LEDId){ if(LEDId == 1){ // Turn off LED 1 } else if(LEDId == 2){ // Turn off LED 2 } else{ //Turn off LED 1 & 2 } return 1; }
int ToggleLeds(int LEDId){ if(LEDId == 1){ if( " is LED 1 ON" ){ TurnOffLeds(1); } else{ TurnOnLeds(1); } } else if(LEDId == 2){ if( "is LED 2 ON" ){ TurnOffLeds(2); } else{ TurnOnLeds(2); } } else{ if( "is LED 1 ON" ){ TurnOffLeds(1); } else{ TurnOnLeds(1); } if( "is LED 2 ON" ){ TurnOffLeds(2); } else{ TurnOnLeds(2); } } return 1; }
Buttons
int WaitForButtonPress(int ButtonId){ if(ButtonId == 1){ while( "Button one is not pressed " ){ //wait } } else{ while( "button 2 is not pressed "){ //wait } } return 1; }
Sensing
int TakeAllReadings(){ int currentTemp = ReadTemp(); int currentPicth = ReadPitcch(); int currentRoll = ReadRoll(); int currentConduct = ReadConduct(); if(StoreAllReadings(currentTemp, currentPitch, currentRoll, currentConduct)){ return 1; } return 0; }
int ReadTemp(){ int reading = //Get Temp reading and return return reading; }
int ReadPitch(){ int reading = //Get Pitch reading and return return reading; }
int ReadRoll(){ int reading = //Get Roll reading and return return reading; }
int ReadConduct(){ int reading = //Get Conduct reading and return return reading; }
Time
could use a time struct like:
typedef struct uint8_t year, uint8_t month, uint8_t date, uint8_t day_week, uint8_t hour, uint8_t minute, uint8_t second } date_type; int SetClock( date_type currentTime){ //set RTC time/date return 1; } date_type ReadClock(date_type *d){ return //get RTC date }
Storage
int StoreAllReadings(currentTemp, currentPitch, currentRoll, currentConduct){ //Save all reading with timestamp and system status return 1; // if successful }
int SendAllData(){ //send all data the node has SendData("Data to send"); }
Radio
Back to Sensinode Development...