Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved AMBusy

  • Loading branch information...
commit 377057a8fec0576b87c24bc97f903400ce8722b9 1 parent bff83f3
@mckk authored
Showing with 60 additions and 52 deletions.
  1. +51 −45 Receiver/ReceiverC.nc
  2. +9 −7 Sender/SenderC.nc
View
96 Receiver/ReceiverC.nc
@@ -51,12 +51,14 @@ implementation
//-----------------TIMER EVENTS------------------------------------//
event void SyncTimer.fired()
{
- // On fired broadcast sync message
- TimerRestartMsg *pkt = NULL;
- pkt = (TimerRestartMsg *)(call TimerPacket.getPayload(&datapkt, sizeof(TimerRestartMsg)));
- pkt -> srcid = TOS_NODE_ID;
- if (!AMBusy && call TimerSend.send(AM_BROADCAST_ADDR, &datapkt, sizeof(TimerRestartMsg)) == SUCCESS){
- AMBusy = TRUE;
+ if (!AMBusy) {
+ // On fired broadcast sync message
+ TimerRestartMsg *pkt = NULL;
+ pkt = (TimerRestartMsg *)(call TimerPacket.getPayload(&datapkt, sizeof(TimerRestartMsg)));
+ pkt -> srcid = TOS_NODE_ID;
+ if (call TimerSend.send(AM_BROADCAST_ADDR, &datapkt, sizeof(TimerRestartMsg)) == SUCCESS){
+ AMBusy = TRUE;
+ }
}
}
@@ -82,55 +84,59 @@ implementation
event message_t * FireMsgReceive.receive(message_t * msg, void * payload, uint8_t len)
{
- FireMsg * fire_pkt = NULL;
- SerialMsg * s_pkt = NULL;
+ if(!SerialAMBusy) {
+ FireMsg * fire_pkt = NULL;
+ SerialMsg * s_pkt = NULL;
- if (len != sizeof(FireMsg)) {
- return msg;
- }
-
- fire_pkt = (FireMsg *) payload;
+ if (len != sizeof(FireMsg)) {
+ return msg;
+ }
+
+ fire_pkt = (FireMsg *) payload;
- s_pkt = (SerialMsg *)(call SerialPacket.getPayload(&serialpkt, sizeof(SerialMsg)));
-
- s_pkt->header = SERIALMSG_HEADER;
- s_pkt->srcid = fire_pkt->srcid;
- s_pkt->fire = TRUE;
- s_pkt->temperature = 0;
- s_pkt->lux = 0;
+ s_pkt = (SerialMsg *)(call SerialPacket.getPayload(&serialpkt, sizeof(SerialMsg)));
+
+ s_pkt->header = SERIALMSG_HEADER;
+ s_pkt->srcid = fire_pkt->srcid;
+ s_pkt->fire = TRUE;
+ s_pkt->temperature = 0;
+ s_pkt->lux = 0;
- if (!SerialAMBusy && (call SerialSend.send(AM_BROADCAST_ADDR, &serialpkt, sizeof(SerialMsg)) == SUCCESS)) {
- SerialAMBusy = TRUE;
- }
+ if (call SerialSend.send(AM_BROADCAST_ADDR, &serialpkt, sizeof(SerialMsg)) == SUCCESS) {
+ SerialAMBusy = TRUE;
+ }
- call Leds.led1Toggle();
+ call Leds.led1Toggle();
+ }
return msg;
}
event message_t * DataReceive.receive(message_t * msg, void * payload, uint8_t len)
{
- SerialMsg * s_pkt = NULL;
- DataMsg * d_pkt = NULL;
-
- if(len != sizeof(DataMsg)) {
- return msg;
- }
-
- d_pkt = (DataMsg *) payload;
-
- s_pkt = (SerialMsg *)(call SerialPacket.getPayload(&serialpkt, sizeof(SerialMsg)));
-
- s_pkt->header = SERIALMSG_HEADER;
- s_pkt->srcid = d_pkt->srcid;
- s_pkt->temperature = d_pkt->temp;
- s_pkt->lux = d_pkt->lux;
- s_pkt->fire = FALSE;
-
- if (!SerialAMBusy && (call SerialSend.send(AM_BROADCAST_ADDR, &serialpkt, sizeof(SerialMsg)) == SUCCESS)) {
- SerialAMBusy = TRUE;
- }
+ if(!SerialAMBusy) {
+ SerialMsg * s_pkt = NULL;
+ DataMsg * d_pkt = NULL;
+
+ if(len != sizeof(DataMsg)) {
+ return msg;
+ }
+
+ d_pkt = (DataMsg *) payload;
+
+ s_pkt = (SerialMsg *)(call SerialPacket.getPayload(&serialpkt, sizeof(SerialMsg)));
+
+ s_pkt->header = SERIALMSG_HEADER;
+ s_pkt->srcid = d_pkt->srcid;
+ s_pkt->temperature = d_pkt->temp;
+ s_pkt->lux = d_pkt->lux;
+ s_pkt->fire = FALSE;
+
+ if (call SerialSend.send(AM_BROADCAST_ADDR, &serialpkt, sizeof(SerialMsg)) == SUCCESS) {
+ SerialAMBusy = TRUE;
+ }
- call Leds.led0Toggle();
+ call Leds.led0Toggle();
+ }
return msg;
}
View
16 Sender/SenderC.nc
@@ -159,7 +159,7 @@ implementation
// If both temperature and light readings occured, send the data
task void sendData()
{
- if(temperatureRead && luxRead) {
+ if(temperatureRead && luxRead && !AMBusy) {
DataMsg *pkt = NULL;
call Leds.led2On();
@@ -168,7 +168,7 @@ implementation
pkt->temp = temperature;
pkt->lux = lux;
- if(!AMBusy && call DataSend.send(AM_BROADCAST_ADDR, &datapkt, sizeof(DataMsg)) == SUCCESS) {
+ if(call DataSend.send(AM_BROADCAST_ADDR, &datapkt, sizeof(DataMsg)) == SUCCESS) {
AMBusy = TRUE;
}
}
@@ -225,12 +225,14 @@ implementation
// turn on red led
call Leds.led0On();
- // send the fire message
- pkt = (FireMsg *)(call DataPacket.getPayload(&datapkt, sizeof(FireMsg)));
- pkt->srcid = TOS_NODE_ID;
+ if(!AMBusy) {
+ // send the fire message
+ pkt = (FireMsg *)(call DataPacket.getPayload(&datapkt, sizeof(FireMsg)));
+ pkt->srcid = TOS_NODE_ID;
- if(!AMBusy && call FireMsgSend.send(BASE_ADDR, &datapkt, sizeof(FireMsg)) == SUCCESS){
- AMBusy = TRUE;
+ if(call FireMsgSend.send(BASE_ADDR, &datapkt, sizeof(FireMsg)) == SUCCESS){
+ AMBusy = TRUE;
+ }
}
}
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.