Quantcast
Channel: Wireless Connectivity
Viewing all articles
Browse latest Browse all 116964

Forum Post: RE: SMPL_Init() & End Device.

$
0
0

A lot of thanks for your response Leo.

And yes, I am using the one of the AP_as_Data_Hub example provided by TI.

About the join question, I have understood how it works, but I still have problems with it in the ED scenario.

After a lot of reading  mrfi files and macros, I start to understand what functions are used during the SMPL_Init(0). In "nwk_api.c", SMPL_Init function, after initializing and waking up, the nwk_join() function is called.

This function is defined in "nwk_join.c". The brief of this function is: "Join functionality for non-AP devices. Send the Join token and wait for the reply."  If I have understood correctly, this function, firstly, creates the payload, that is to say, set the length, address, port ( since it is a join request is 3) and message (the join token if i am not wrong) and then  "SMPL_Ioctl(IOCTL_OBJ_RAW_IO, IOCTL_ACT_WRITE, &ioctl_info.send);" sends the enclosed payload to the specified port/address. And then, it waits for a reply.

After reply waiting, there is an if:  "if (SMPL_SUCCESS == SMPL_Ioctl(IOCTL_OBJ_RAW_IO, IOCTL_ACT_READ, &ioctl_info.recv))". Inside of it, if the reply (in the last frame received) is correct, sets the link token for the linking process and returns the SMPL_SUCCESS for the SMPL_Init. And here it is my problem. My "SMPL_Init(0)" on the ED never returns SMPL_SUCCESS, since the "SMPL_SUCCESS == SMPL_Ioctl(IOCTL_OBJ_RAW_IO, IOCTL_ACT_READ, &ioctl_info.recv" condition never is true.

If I set a breakpoint in this line, in the debug  window, the "mrfiIncomingPacket" variable has the correct format, the AP address, the ED address, port 3, REQ reply 0x81 and the link token, but the values in ioctl_info.recv.addr and ioctl_info.send.addr does not match with the correct ones ( these values have to be the device address, haven't they? or I am wrong)

Could the value of reply delay create problems for a correct reading of frames? The Anaren module uses another crystal (27 MHz instead of 26 MHz).

Please I hope your answer, and thanks in advance. This is the code I am using.

Could the value of reply delay create problems for a correct reading of frames? The Anaren module uses another crystal (27 MHz instead of 26 MHz).

Please I hope your answer, and thanks in advance.

smplStatus_t nwk_join(void)
{
  uint8_t      msg[JOIN_FRAME_SIZE];
  uint32_t     linkToken;
  addr_t       apAddr;
  uint8_t      radioState = MRFI_GetRadioState();
  smplStatus_t rc = SMPL_NO_JOIN;
  union
  {
    ioctlRawSend_t    send;
    ioctlRawReceive_t recv;
  } ioctl_info;

#if defined( FREQUENCY_AGILITY )
  uint8_t  i, numChan;
  freqEntry_t channels[NWK_FREQ_TBL_SIZE];

  if (!(numChan=nwk_scanForChannels(channels)))
  {
    return SMPL_NO_CHANNEL;
  }

  for (i=0; i<numChan; ++i)
  {
    nwk_setChannel(&channels[i]);
#else
  {
#endif

    ioctl_info.send.addr = (addr_t *)nwk_getBCastAddress();
    ioctl_info.send.msg  = msg;
    ioctl_info.send.len  = sizeof(msg);
    ioctl_info.send.port = SMPL_PORT_JOIN;

    /* Put join token in */
    nwk_putNumObjectIntoMsg((void *)&sJoinToken, msg+J_JOIN_TOKEN_OS, sizeof(sJoinToken));
    /* set app info byte */
    msg[JB_REQ_OS] = JOIN_REQ_JOIN;
    msg[JB_TID_OS] = sTid;
    /* Set number of connections supported. Used only by AP if it is
     * a data hub.
     */
    msg[J_NUMCONN_OS] = NUM_CONNECTIONS;
    /* protocol version number */
    msg[J_PROTOCOL_VERSION_OS] = nwk_getProtocolVersion();

    SMPL_Ioctl(IOCTL_OBJ_RAW_IO, IOCTL_ACT_WRITE, &ioctl_info.send);

    ioctl_info.recv.port = SMPL_PORT_JOIN;
    ioctl_info.recv.msg  = msg;
    ioctl_info.recv.addr = &apAddr;    /* save AP address from reply */

    NWK_CHECK_FOR_SETRX(radioState);
    NWK_REPLY_DELAY();
    NWK_CHECK_FOR_RESTORE_STATE(radioState);



    if (SMPL_SUCCESS == SMPL_Ioctl(IOCTL_OBJ_RAW_IO, IOCTL_ACT_READ, &ioctl_info.recv))
    {
      uint8_t firstByte = msg[JB_REQ_OS] & (~NWK_APP_REPLY_BIT);

      /* Sanity check for correct reply frame. Older version
       * has the length instead of the request as the first byte.
       */
      if ((firstByte == JOIN_REQ_JOIN) || (firstByte == JOIN_REPLY_LEGACY_MSG_LENGTH))
      {
        /* join reply returns link token */
        memcpy(&linkToken, msg+JR_LINK_TOKEN_OS, sizeof(linkToken));

        nwk_setLinkToken(linkToken);
        /* save AP address */
        nwk_setAPAddress(&apAddr);
        sTid++;   /* guard against duplicates */
        rc = SMPL_SUCCESS;
#if defined( FREQUENCY_AGILITY )
        break;
#endif
      }
    }

    /* TODO: process encryption stuff */
  }

  return rc;

}

#endif /* ACCESS_POINT */


Viewing all articles
Browse latest Browse all 116964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>