Example #1
0
// Target function to timer, sends ping packet after a delay
// note that arguments are via static vars due to the indirect nature of the call
static void
macDoPingRequest(void)
{
    ftPing frame;

    frame.fcf = FCF_DATA;
    frame.seq = macConfig.dsn++;
    frame.panid = macConfig.panId;
    frame.srcAddr = macConfig.shortAddress;
    frame.originAddr = macConfig.shortAddress;
    frame.finalDestAddr = pingAddr;
    frame.rssi = radioGetSavedRssiValue();
    frame.lqi = radioGetSavedLqiValue();
    frame.type = pingType;

    // Set high bit of type if we're sleeping
    if (macConfig.sleeping && NODE_TYPE == ENDDEVICE && NODE_SLEEP)
       	frame.type |= 0x80;

#if (NODE_TYPE == COORD)
    {
#if DEBUG==2
 debugMsgStr("\r\nin macDoPingRequest");
#endif
    	// Find the top parentpin
        u8 addr = macGetTopParent(pingAddr);
        frame.destAddr = addr;
        // See if the child is sleeping (only the coord sends directly to a child node)
        if (NODE_SLEEP &&
            macIsChild(addr)&&
            macIsChildSleeping(addr))
        {
            // Send it later, after child is awake
#if DEBUG==2
debugMsgStr("\r\ncalling macHoldFrame for ping response");
#endif
            macHoldFrame(addr, (u8*)&frame, sizeof(ftPing));
            // Don't send frame right now
            return;
        }
        else
        {
#if DEBUG==2
debugMsgStr("\r\n child: ");
debugMsgInt(addr);
debugMsgStr(" not sleeping");
#endif
        }

    }
#else
        // End/router nodes
        frame.destAddr = macConfig.parentShortAddress;
#endif
#if DEBUG==2
debugMsgStr(" sending Ping Response now\n\r");
#endif

    radioSendData(sizeof(ftPing), (u8*)&frame);
}
Example #2
0
// Target function to timer, sends ping packet after a delay
void mp(void)
{
   uint8_t* pFrame = bmm_buffer_alloc();

   if(pFrame != NULL)
   {
      ftPing *frame = (ftPing*)(((rx_frame_t*)pFrame)->data);

      frame->fcf = FCF_DATA;
      frame->seq = macConfig.dsn++;
      frame->panid = macConfig.panId;
      frame->srcAddr = macConfig.shortAddress;
      frame->originAddr = macConfig.shortAddress;
      frame->finalDestAddr = pingAddr;
      frame->type = pingType;
      frame->rssi = radioGetSavedRssiValue();
      frame->lqi = radioGetSavedLqiValue();

      ((rx_frame_t*)pFrame)->length = sizeof(ftPing);

      if (NODETYPE == COORD)
      {
         // Find the top parent
         u8 addr = macGetTopParent(pingAddr);
         frame->destAddr = addr;
         // See if the child is sleeping (only the coord sends directly to a child node)
         if (RUMSLEEP && macIsChild(addr) && macIsChildSleeping(addr))
         {
            // Send it later, after child is awake
            macHoldFrame(addr, pFrame);
            // buffer is freed inside macHoldFrame()
            // Don't send frame right now
            return;
         }
      }
      else // End/router nodes
      {
         frame->destAddr = macConfig.parentShortAddress;
      }

      event_object_t event;
      event.event = MAC_EVENT_SEND;
      event.data = pFrame;
      event.callback = 0;

      // save Event
      mac_put_event(&event);
   }
}