Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- includes IntMsg;
- module HomeWorkM
- {
- provides
- {
- interface StdControl;
- }
- uses
- {
- interface Timer as Timer1;
- interface Timer as Timer2;
- interface SendMsg;
- interface ReceiveMsg;
- }
- }
- implementation
- {
- bool sending_enabled;
- char serialNumber=0;
- struct TOS_Msg data;
- char max[4];
- uint8_t num[4];
- command result_t StdControl.init()
- {
- return SUCCESS;
- }
- command result_t StdControl.start()
- {
- sending_enabled=FALSE;
- return call Timer1.start(TIMER_ONE_SHOT, 10000);
- }
- command result_t StdControl.stop()
- {
- return rcombine(call Timer1.stop(), call Timer2.stop());
- }
- event result_t Timer1.fired()
- {
- IntMsg *message = (IntMsg *)data.data;
- if (sending_enabled)
- {
- if (call Timer1.start(TIMER_REPEAT, 1000))
- {
- sending_enabled=TRUE;
- }
- }
- else
- {
- if (serialNumber < 100)
- {
- serialNumber++;
- message->val = serialNumber;
- atomic
- {
- message->src = TOS_LOCAL_ADDRESS;
- }
- call SendMsg.send(TOS_BCAST_ADDR, sizeof(IntMsg), &data);
- }
- }
- return SUCCESS;
- }
- event result_t Timer2.fired()
- {
- uint8_t k;
- for (k=0; k<4; k++)
- {
- store(k,num[k],max[k]); // stores num and max for each k
- }
- return SUCCESS;
- }
- event result_t SendMsg.sendDone(TOS_MsgPtr msg, bool success)
- {
- return SUCCESS;
- }
- event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr recv_packet)
- {
- IntMsg *message = (IntMsg *)recv_packet->data;
- if (message->val > max[message->src])
- {
- max[message->src]=message->val;
- }
- num[message->src]++;
- call Timer2.stop();
- call Timer2.start(TIMER_ONE_SHOT, 60000);
- return recv_packet;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement