예제 #1
0
uint8_t RNWK_OnPacketRx(RPHY_PacketDesc *packet) {
  RNWK_ShortAddrType addr;
  RMAC_MsgType type;

  addr = RNWK_BUF_GET_DST_ADDR(packet->phyData);
  if (addr==RNWK_ADDR_BROADCAST || addr==RNWK_GetThisNodeAddr()) { /* it is for me :-) */
    type = RMAC_GetType(packet->phyData, packet->phySize); /* get the type of the message */
    if (RMAC_MSG_TYPE_IS_ACK(type) && RMAC_IsExpectedACK(packet->phyData, packet->phySize)) {
      /* it is an ACK, and the sequence number matches. Mark it with a flag and return, as no need for further processing */
      packet->flags |= RPHY_PACKET_FLAGS_IS_ACK;
      return ERR_OK; /* no need to process the packet further */
    } else if (RMAC_MSG_TYPE_IS_DATA(type)) { /* data packet received */
      if (RNWK_AppOnRxCallback!=NULL) { /* do we have a callback? */
#if RNET_CONFIG_USE_ACK
        if (RMAC_MSG_TYPE_REQ_ACK(type)) {
          (void)RNWK_SendACK(packet, RNWK_GetThisNodeAddr()); /* send ack message back */
        }
#endif
        return RNWK_AppOnRxCallback(packet); /* call upper layer */
      }
    } else {
      return ERR_FAULT; /* wrong message type? */
    }
  }
  return ERR_FAILED;
}
예제 #2
0
static uint8_t PrintStatus(const CLS1_StdIOType *io) {
  uint8_t buf[32];
  
  CLS1_SendStatusStr((unsigned char*)"rnwk", (unsigned char*)"\r\n", io->stdOut);
  
  UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"0x");
#if RNWK_SHORT_ADDR_SIZE==1
  UTIL1_strcatNum8Hex(buf, sizeof(buf), RNWK_GetThisNodeAddr());
#else
  UTIL1_strcatNum16Hex(buf, sizeof(buf), RNWK_GetThisNodeAddr());
#endif
  UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n");
  CLS1_SendStatusStr((unsigned char*)"  addr", buf, io->stdOut);

  return ERR_OK;
}
예제 #3
0
uint8_t RNWK_OnPacketRx(RPHY_PacketDesc *packet) {
  RNWK_ShortAddrType addr;
  RMAC_MsgType type;
  uint8_t res;

  addr = RNWK_BUF_GET_DST_ADDR(packet->data);
  if (addr==RNWK_ADDR_BROADCAST || addr==RNWK_GetThisNodeAddr()) { /* it is for me :-) */
    type = RMAC_GetType(packet->data, packet->dataSize); /* get the type of the message */
    if (type==RMAC_MSG_TYPE_ACK && RMAC_IsExpectedACK(packet->data, packet->dataSize)) {
      /* it is an ACK, and the sequence number matches. Mark it with a flag and return, as no need for further processing */
      packet->flags |= RPHY_PACKET_FLAGS_ACK;
      return ERR_OK; /* no need to process the packet further */
    } else if (type==RMAC_MSG_TYPE_DATA) { /* data packet received */
      if (RNWK_AppOnRxCallback!=NULL) { /* do we have a callback? */
        res = RNWK_AppOnRxCallback(packet); /* call upper layer */
        if (res==ERR_OK) { /* all fine, now send acknowledge back */
          addr = RNWK_BUF_GET_SRC_ADDR(packet->data); /* who should receive the ack? */
          RNWK_BUF_SET_DST_ADDR(packet->data, addr); /* destination address is from where we got the data */
          return RMAC_SendACK(packet); /* send ack message back */
        }
      }
    } else {
      return ERR_FAULT; /* wrong message type? */
    }
  }
  return ERR_FAILED;
}
예제 #4
0
uint8_t RNWK_PutPayload(uint8_t *buf, size_t bufSize, uint8_t payloadSize, RNWK_ShortAddrType dstAddr, RPHY_FlagsType flags) {
  RNWK_ShortAddrType srcAddr;
  
  srcAddr = RNWK_GetThisNodeAddr();
  RNWK_BUF_SET_SRC_ADDR(buf, srcAddr);
  RNWK_BUF_SET_DST_ADDR(buf, dstAddr);
  return RMAC_PutPayload(buf, bufSize, payloadSize+RNWK_HEADER_SIZE, flags);
}
예제 #5
0
파일: RApp.c 프로젝트: FlorianOechslin/FRDM
RNWK_ShortAddrType RAPP_GetThisNodeAddr(void) {
  return RNWK_GetThisNodeAddr();
}