Beispiel #1
0
/*************************************************************************************************
 * @fn          sysPingRsp
 *
 * @brief       Build and send Ping response
 *
 * @param       none
 *
 * @return      none
**************************************************************************************************
 */
static void sysPingRsp(void)
{
    uint8 pingBuff[7];

    // Start of Frame Delimiter
    pingBuff[0] = 0xFE;

    // Length
    pingBuff[1] = 0x02;

    // Command type
    pingBuff[2] = LO_UINT16(0x0161);
    pingBuff[3] = HI_UINT16(0x0161);

    // Stack profile
    pingBuff[4] = LO_UINT16(0x0041);
    pingBuff[5] = HI_UINT16(0x0041);

    // Frame Check Sequence
    pingBuff[6] = calcFCS(&pingBuff[1], 5);


    HalUARTWrite(MHMS_PORT,pingBuff, 7);

}
void sendNodeReport(uint8 onoff)
{
  uint8 pFrame[NODE_ALARM_MSG_LEN];
  
  // Start of Frame Delimiter
  pFrame[FRAME_SOF_OFFSET] = CPT_SOP; // Start of Frame Delimiter
  
  // Length
  pFrame[FRAME_LENGTH_OFFSET] = 7;
  
  // Command type
  //pFrame[FRAME_CMD0_OFFSET] = LO_UINT16(ZB_RECEIVE_DATA_INDICATION);   
  //pFrame[FRAME_CMD1_OFFSET] = HI_UINT16(ZB_RECEIVE_DATA_INDICATION); 
  pFrame[FRAME_CMD0_OFFSET] = LO_UINT16(0);   
  pFrame[FRAME_CMD1_OFFSET] = HI_UINT16(0); 
  
  // Source address
  pFrame[FRAME_DATA_OFFSET+ ZB_RECV_SRC_OFFSET] = LO_UINT16(0); 
  pFrame[FRAME_DATA_OFFSET+ ZB_RECV_SRC_OFFSET+ 1] = HI_UINT16(0);
  
  // Command ID
  //pFrame[FRAME_DATA_OFFSET+ ZB_RECV_CMD_OFFSET] = LO_UINT16(SENSOR_REPORT_CMD_ID); 
  //pFrame[FRAME_DATA_OFFSET+ ZB_RECV_CMD_OFFSET+ 1] = HI_UINT16(SENSOR_REPORT_CMD_ID);
  pFrame[FRAME_DATA_OFFSET+ ZB_RECV_CMD_OFFSET] = LO_UINT16(0); 
  pFrame[FRAME_DATA_OFFSET+ ZB_RECV_CMD_OFFSET+ 1] = HI_UINT16(0);
  
  // Length
  pFrame[FRAME_DATA_OFFSET+ ZB_RECV_LEN_OFFSET] = LO_UINT16(1); 
  pFrame[FRAME_DATA_OFFSET+ ZB_RECV_LEN_OFFSET+ 1] = HI_UINT16(1);
  
  // Data
  pFrame[FRAME_DATA_OFFSET+ ZB_RECV_DATA_OFFSET] = onoff;
  
  // Frame Check Sequence
  pFrame[NODE_ALARM_MSG_LEN- 1] = calcFCS(&pFrame[FRAME_LENGTH_OFFSET], (NODE_ALARM_MSG_LEN - 2) );
  
  // Write report to UART
  write(uart_fd, pFrame, NODE_ALARM_MSG_LEN);
}
Beispiel #3
0
void sysPingRsp(void)
{
  uint8 pBuf[7];
  
  // Start of Frame Delimiter
  pBuf[0] = CPT_SOP;
  
  // Length
  pBuf[1] = 2; 
  
  // Command type
  pBuf[2] = LO_UINT16(SYS_PING_RESPONSE); 
  pBuf[3] = HI_UINT16(SYS_PING_RESPONSE);
  
  // Stack profile
  pBuf[4] = LO_UINT16(STACK_PROFILE);
  pBuf[4+ 1] = HI_UINT16(STACK_PROFILE);
  
  // Frame Check Sequence
  pBuf[7 - 1] = calcFCS(&pBuf[1], (7 - 2));
  
  // Write frame to UART
  UART_Send_String (pBuf, 7);
}
/**************************************************************************************************
 * @fn          MHMSTestingDataRx
 *
 * @brief       This function is called by MHMSAfMsgRx() to process incoming data  This is not used in 
 *              normal operation.  This is used for testing system with differnt payload sizes.
 * input parameters
 *
 * @param       msg - A pointer to the afIncomingMSGPacket_t packet.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void MHMSTestingDataRx(afIncomingMSGPacket_t *msg)
{
   uint8 fcs = 0, idx;
   int8 Rssi;

   //Convert LQI to RSSI
   Rssi =(int8)(((msg->LinkQuality * 97)/0xFF) -87); 

  if (INVALID_NODE_ADDR == MHMSAddr)
  {
    (void)osal_set_event(MHMSTaskId, MHMS_EVT_ANN);
  }

  TestRxBuffer[MHMS_SOP_IDX] = MHMS_SOP_VAL;
  TestRxBuffer[MHMS_ADR_LSB] = LO_UINT16(msg->srcAddr.addr.shortAddr);
  TestRxBuffer[MHMS_ADR_MSB] = HI_UINT16(msg->srcAddr.addr.shortAddr);

  // 1st byte of message is skipped - CMD is always 0 for data.
  (void)osal_memcpy(TestRxBuffer+MHMS_DAT_OFF, msg->cmd.Data+1, MHMS_TEST_PAYLOAD_LEN-1);  //MHMS copies one buffer to another

  for (idx = MHMS_ADR_LSB; idx < MHMS_FCS_IDX; idx++)
  {
    fcs ^= TestRxBuffer[idx];
  }
  TestRxBuffer[idx] = fcs;
  
  uint8 PktSeqNum; 
  
  uint8 parentAddrLSB;
  uint8 parentAddrMSB;
  uint8 tsensorBuf[15];
  
  parentAddrLSB= TestRxBuffer[11];
  parentAddrMSB= TestRxBuffer[12];  
  
  PktSeqNum = TestRxBuffer[13];
  
  //Start of Frame Delimiter
  tsensorBuf[0]=0xFE;
  tsensorBuf[1]=10;
  tsensorBuf[2]=LO_UINT16(0x8746);
  tsensorBuf[3]=HI_UINT16(0x8746);
  
  //Source Address
  tsensorBuf[4] = LO_UINT16(msg->srcAddr.addr.shortAddr);
  tsensorBuf[5] = HI_UINT16(msg->srcAddr.addr.shortAddr);
  
  tsensorBuf[6]=LO_UINT16(2);  
  tsensorBuf[7]=HI_UINT16(2);
  tsensorBuf[8]=LO_UINT16(4);
  tsensorBuf[9]=HI_UINT16(4);
  
  //Temperature and Voltage Data
  tsensorBuf[10]= Rssi;
  tsensorBuf[11]= PktSeqNum; 
  
  //Parent Address
  tsensorBuf[12]= parentAddrLSB;
  tsensorBuf[13]= parentAddrMSB;


  //FCS Check on the middle 13 bytes
  tsensorBuf[14] = calcFCS(&tsensorBuf[1], 13 );

  HalUARTWrite(MHMS_PORT, tsensorBuf, 15);  //For communicating with the Zigbee sensor Monitor

}
/**************************************************************************************************
 * @fn          MHMSDataRx
 *
 * @brief       This function is called by MHMSAfMsgRx() to process incoming MHMS data.
 *
 * input parameters
 *
 * @param       msg - A pointer to the afIncomingMSGPacket_t packet.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void MHMSDataRx(afIncomingMSGPacket_t *msg)
{
  uint8 fcs = 0, idx;
    
  if (INVALID_NODE_ADDR == MHMSAddr)
  {
    (void)osal_set_event(MHMSTaskId, MHMS_EVT_ANN);
  }

  MHMSBuf[MHMS_SOP_IDX] = MHMS_SOP_VAL;
  MHMSBuf[MHMS_ADR_LSB] = LO_UINT16(msg->srcAddr.addr.shortAddr);
  MHMSBuf[MHMS_ADR_MSB] = HI_UINT16(msg->srcAddr.addr.shortAddr);

  // 1st byte of message is skipped - CMD is always 0 for data.
  (void)osal_memcpy(MHMSBuf+MHMS_DAT_OFF, msg->cmd.Data+1, MHMS_DAT_LEN-1);  //MHMS copies one buffer to another

  for (idx = MHMS_ADR_LSB; idx < MHMS_FCS_IDX; idx++)
  {
    fcs ^= MHMSBuf[idx];
  }
  MHMSBuf[idx] = fcs;
  
  uint8 deviceBPM;
  uint8 parentAddrLSB;
  uint8 parentAddrMSB;
  uint8 zsensorBuf[15];
  
  parentAddrLSB= MHMSBuf[11];
  parentAddrMSB= MHMSBuf[12];  
  
  if(MHMSBuf[13] == CHECK_IN_INACTIVE){
  deviceBPM = MHMSBuf[15];
  }
  else{
  deviceBPM = 5;
  }
  
  //Start of Frame Delimiter
  zsensorBuf[0]=0xFE;
  zsensorBuf[1]=10;
  zsensorBuf[2]=LO_UINT16(0x8746);
  zsensorBuf[3]=HI_UINT16(0x8746);
  
  //Source Address
  zsensorBuf[4] = LO_UINT16(msg->srcAddr.addr.shortAddr);
  zsensorBuf[5] = HI_UINT16(msg->srcAddr.addr.shortAddr);
  
  //Default commands that Mobile Health Monitor software needs by default
  zsensorBuf[6]=LO_UINT16(2);  
  zsensorBuf[7]=HI_UINT16(2);
  zsensorBuf[8]=LO_UINT16(4);
  zsensorBuf[9]=HI_UINT16(4);
  
  //Collected data to be displayed on Mobile Health Monitor software 
  zsensorBuf[10]= deviceBPM;
  zsensorBuf[11]= deviceBPM; 
  
  //Parent Address
  zsensorBuf[12]=parentAddrLSB;
  zsensorBuf[13]=parentAddrMSB;

  //FCS Check on the middle 13 bytes
  zsensorBuf[14] = calcFCS(&zsensorBuf[1], 13 );

  HalUARTWrite(MHMS_PORT, zsensorBuf, 15);  //For communicating with the Zigbee sensor Monitor
  
}
Beispiel #6
0
/**************************************************************************************************
 * @fn          MHMSDataRx
 *
 * @brief       This function is called by MHMSAfMsgRx() to process incoming MHMS data.
 *
 * input parameters
 *
 * @param       msg - A pointer to the afIncomingMSGPacket_t packet.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void MHMSDataRx(afIncomingMSGPacket_t *msg)
{
    uint8 fcs = 0, idx;

    // Last announce broadcast to stop must have expired before a parent could forward to a ZED.
    if (INVALID_NODE_ADDR == MHMSAddr)
    {
        (void)osal_set_event(MHMSTaskId, MHMS_EVT_ANN);
    }

    MHMSBuf[MHMS_SOP_IDX] = MHMS_SOP_VAL;
    MHMSBuf[MHMS_ADR_LSB] = LO_UINT16(msg->srcAddr.addr.shortAddr);
    MHMSBuf[MHMS_ADR_MSB] = HI_UINT16(msg->srcAddr.addr.shortAddr);

    // 1st byte of message is skipped - CMD is always 0 for data.
    (void)osal_memcpy(MHMSBuf+MHMS_DAT_OFF, msg->cmd.Data+1, MHMS_DAT_LEN-1);  //MHMS copies one buffer to another

    for (idx = MHMS_ADR_LSB; idx < MHMS_FCS_IDX; idx++)
    {
        fcs ^= MHMSBuf[idx];
    }
    MHMSBuf[idx] = fcs;

    uint8 deviceBPM;
    uint8 parentAddrLSB;
    uint8 parentAddrMSB;
    uint8 zsensorBuf[15];

    parentAddrLSB= MHMSBuf[11];
    parentAddrMSB= MHMSBuf[12];

    if(MHMSBuf[13] == CHECK_IN_INACTIVE) {
        deviceBPM = MHMSBuf[15];
    }
    else {
        deviceBPM = 5;
    }

    //Start of Frame Delimiter
    zsensorBuf[0]=0xFE;
    zsensorBuf[1]=10;
    zsensorBuf[2]=LO_UINT16(0x8746);
    zsensorBuf[3]=HI_UINT16(0x8746);

    //Source Address
    zsensorBuf[4] = LO_UINT16(msg->srcAddr.addr.shortAddr);
    zsensorBuf[5] = HI_UINT16(msg->srcAddr.addr.shortAddr);

    zsensorBuf[6]=LO_UINT16(2);  //MHMS are 6 - 9 being used for anything?
    zsensorBuf[7]=HI_UINT16(2);
    zsensorBuf[8]=LO_UINT16(4);
    zsensorBuf[9]=HI_UINT16(4);

    //Temperature and Voltage Data
    zsensorBuf[10]= deviceBPM;
    zsensorBuf[11]= deviceBPM; //deviceVolt;

    //Parent Address
    zsensorBuf[12]=parentAddrLSB;
    zsensorBuf[13]=parentAddrMSB;


    //FCS Check on the middle 13 bytes
    zsensorBuf[14] = calcFCS(&zsensorBuf[1], 13 );

    HalUARTWrite(MHMS_PORT, zsensorBuf, 15);  //For communicating with the Zigbee sensor Monitor

    /*  //MHMS USB communication with Pulse sensor Processor application


      uint8 BPMBuf[7] = {'B',0,0,0,10,13};
      uint8 IBIBuf[7] = {'Q',0,0,0,10,13};
      uint8 SignalBuf[7] = {'S',0,0,0,10,13};

      //conversion Signal Dec to ASCII
      uint16 temp = (BUILD_UINT16(MHMSBuf[16], MHMSBuf[17])) - 400;
      if(temp > 999){
        SignalBuf[1] = '9';
        SignalBuf[2] = '9';
        SignalBuf[3] = '9';
      }
      else {
        SignalBuf[1] = (uint8)((temp/100)+ 48);
        SignalBuf[2] = (uint8)((((temp%100) - (temp % 100)%10)/10) + 48);
        SignalBuf[3] = (uint8)(((temp % 100)%10)+ 48);
      }

      //conversion BPM Dec to ASCII
      temp = (uint16)MHMSBuf[14];
      BPMBuf[1] = (uint8)((temp/100)+ 48);
      BPMBuf[2] = (uint8)((((temp%100) - (temp % 100)%10)/10) + 48);
      BPMBuf[3] = (uint8)(((temp % 100)%10)+ 48);

      //conversion IBI Dec to ASCII
      temp = (uint16)MHMSBuf[19];
      IBIBuf[1] = (uint8)((temp/100)+ 48);
      IBIBuf[2] = (uint8)((((temp%100) - (temp % 100)%10)/10) + 48);
      IBIBuf[3] = (uint8)(((temp % 100)%10)+ 48);


      //HalUARTWrite(MHMS_PORT, SignalBuf, 6);
     // HalUARTWrite(MHMS_PORT, BPMBuf, 6);
     // HalUARTWrite(MHMS_PORT, IBIBuf, 6);
    */

}
/**************************************************************************************************
 * @fn          pulseTestingDataRx
 *
 * @brief       This function is called by pulseAfMsgRx() to process incoming data  This is not used in 
 *              normal operation.  This is used for testing system with differnt payload sizes.
 * input parameters
 *
 * @param       msg - A pointer to the afIncomingMSGPacket_t packet.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void pulseTestingDataRx(afIncomingMSGPacket_t *msg)
{
   uint8 fcs = 0, idx;
   int8 Rssi;
   //Convert LQI to RSSI
   Rssi =(int8)(((msg->LinkQuality * 97)/0xFF) -87); 
   //uint8 *TestRxBuffer;
   //TestRxBuffer = (uint8*)osal_mem_alloc(MHMS_TEST_BUFF_LEN);
    
  

  // Last announce broadcast to stop must have expired before a parent could forward to a ZED.
  if (INVALID_NODE_ADDR == pulseAddr)
  {
    (void)osal_set_event(pulseTaskId, PULSE_EVT_ANN);
  }

  TestRxBuffer[PULSE_SOP_IDX] = PULSE_SOP_VAL;
  TestRxBuffer[PULSE_ADR_LSB] = LO_UINT16(msg->srcAddr.addr.shortAddr);
  TestRxBuffer[PULSE_ADR_MSB] = HI_UINT16(msg->srcAddr.addr.shortAddr);

  // 1st byte of message is skipped - CMD is always 0 for data.
  (void)osal_memcpy(TestRxBuffer+PULSE_DAT_OFF, msg->cmd.Data+1, MHMS_TEST_PAYLOAD_LEN-1);  //MHMS copies one buffer to another

  for (idx = PULSE_ADR_LSB; idx < MHMS_FCS_IDX; idx++)
  {
    fcs ^= TestRxBuffer[idx];
  }
  TestRxBuffer[idx] = fcs;
  
  uint8 PktSeqNum; 
  
  uint8 parentAddrLSB;
  uint8 parentAddrMSB;
  uint8 tsensorBuf[15];
  
  parentAddrLSB= TestRxBuffer[11];
  parentAddrMSB= TestRxBuffer[12];  
  
  PktSeqNum = TestRxBuffer[13];
  
  //Start of Frame Delimiter
  tsensorBuf[0]=0xFE;
  tsensorBuf[1]=10;
  tsensorBuf[2]=LO_UINT16(0x8746);
  tsensorBuf[3]=HI_UINT16(0x8746);
  
  //Source Address
  tsensorBuf[4] = LO_UINT16(msg->srcAddr.addr.shortAddr);
  tsensorBuf[5] = HI_UINT16(msg->srcAddr.addr.shortAddr);
  
  tsensorBuf[6]=LO_UINT16(2);  //MHMS are 6 - 9 being used for anything?
  tsensorBuf[7]=HI_UINT16(2);
  tsensorBuf[8]=LO_UINT16(4);
  tsensorBuf[9]=HI_UINT16(4);
  
  //Temperature and Voltage Data
  tsensorBuf[10]= Rssi;
  tsensorBuf[11]= PktSeqNum; 
  
  //Parent Address
  tsensorBuf[12]= parentAddrLSB;
  tsensorBuf[13]= parentAddrMSB;


  //FCS Check on the middle 13 bytes
  tsensorBuf[14] = calcFCS(&tsensorBuf[1], 13 );

  HalUARTWrite(PULSE_PORT, tsensorBuf, 15);  //For communicating with the Zigbee sensor Monitor
  
  //osal_mem_free(TestRxBuffer);
}