23 / 30
iSense Ethernet Gateway User Guide
coalesenses
research to innovate
// Handler called when the button of the NET10 is pressed
void
button_down(
uint8
button_no
);
// inherited from Task, called when registered task is due
void
execute(
void
* userdata );
private
:
//Pointer to the NET10 instance
Net10Module
*
net10_
;
//Status of the LEDs
u
int8
led
_value_
;
//Pointer the SDCard instance
SDCard
*
sd_card_
;
//Counts the number of times the button was pressed
uint64
*
cm_
;
};
NET10DemoApplication
overwrites
isense::Application::boot()
, which is called
upon the start up of the iSense sensor node.
void
UG_NET10DemoApplication::
boot (){
os_
->allow_sleep(
false
);
os_
->allow_doze(
false
);
os
().debug(
"NET10DemoApplication::boot"
);
//create NET10 Module instance
net10_ =
new
Net10Module( os_ );
if
(
net10_
!=
NULL
)
// new was successful
{
//Register application as button handler of the NET10 module
net10_
->set_button_handler(
this
);
//Get SDCard instance from Net10Module
sd_card_ = net10_
->sd_card( );
if
(
sd_card_
!=
NULL
)
// new was successful
{
os_.add_task_in( Time( 1, 0 ),
void
,
(
void
*)USERDATA_SD_CARD_METRICS )
}
}
}
Within the
boot()
method, a
Net10Module
object is created. If the allocation was successful, the
application registers itself as
ButtonHandler
for button events of the
Net10Module
. Next the
pointer to the
SDCard
instance is retrieved. An instance of the
SDCard
is created together with the
Net10Module
. If an instance of
SDCard
exists, a
Task
will be registered, that will periodically
queriy the SD Card slot until a card is inserted and then output the number of its sectors.
An application can register itself at the OS as a
Task
to receive a callback immediately, at a certain
time, or after a certain interval. Task callbacks are called in the regular application context. They
cannot interrupt other activities, and hence may be delayed. Task execution can take an arbitrary time,
and is hence suited for longer activities such as complex computations.
class Task : public iSenseObject
{
public:
/**
* This method is called by the os in normal context.
*/
virtual
void
execute(
void
* userdata ) = 0;
};