Esempio n. 1
0
/***************************************************************************************************
 * @fn      MT_OtaSendStatus
 *
 * @brief   Sends the status of the OTA transfer. 
 *          eg. "MT_OTA_DL_COMPLETE" to the PC OTA Console tool
 *
 * @param   shortAddr - Short Address of the device the status relates to
 * @param   type - The type of status being reported
 * @param   status - The status value
 * @param   optional - Optional type specific additional information
 *
 * @return  status
 *
 ***************************************************************************************************/
uint8 MT_OtaSendStatus(uint16 shortAddr, uint8 type, uint8 status, uint8 optional)
{
  uint8   msgLen;
  uint8   *pBuf;
  uint8   *p;

  // Get length
  msgLen = 7;
  
  // Allocate a buffer
  if ((p = pBuf = MT_TransportAlloc(0, msgLen)) != NULL)
  {
    // build header
    *p++ = msgLen;
    *p++ = (uint8) MT_RPC_CMD_AREQ | (uint8) MT_RPC_SYS_OTA;
    *p++ = MT_OTA_STATUS_IND;
    
    // Add message parameters
    *p++ = LO_UINT16(_NIB.nwkPanId);
    *p++ = HI_UINT16(_NIB.nwkPanId);
    *p++ = LO_UINT16(shortAddr);
    *p++ = HI_UINT16(shortAddr);
    *p++ = type;
    *p++ = status;
    *p = optional;
  
    // Send command to server
    MT_TransportSend(pBuf);
    
    return ZSuccess;
  }
  
  return ZMemError;  
}
Esempio n. 2
0
/***************************************************************************************************
 * @fn      MT_BuildAndSendZToolResponse
 *
 * @brief   Build and send a ZTOOL msg
 * @param   uint8 cmdType - include type and subsystem
 *          uint8 cmdId - command ID
 *          byte dataLen
 *          byte *pData
 *
 * @return  void
 ***************************************************************************************************/
void MT_BuildAndSendZToolResponse(uint8 cmdType, uint8 cmdId, uint8 dataLen, uint8 *pData)
{
    uint8 *msg_ptr;

    if ((msg_ptr = MT_TransportAlloc((mtRpcCmdType_t)(cmdType & 0xE0), dataLen)) != NULL)
    {
        msg_ptr[MT_RPC_POS_LEN] = dataLen;
        msg_ptr[MT_RPC_POS_CMD0] = cmdType;
        msg_ptr[MT_RPC_POS_CMD1] = cmdId;
        (void)osal_memcpy(msg_ptr+MT_RPC_POS_DAT0, pData, dataLen);

        MT_TransportSend(msg_ptr);
    }
}
Esempio n. 3
0
/***************************************************************************************************
 * @fn      MT_OtaFileReadReq
 *
 * @brief   Requests a block of a file be read from the remote.
 *
 * @param   pAddr - The addres of the device requsting the data
 * @param   pFileId - Teh id of the image to read from
 * @param       len - Amount of data to read (must be smaller than the max MT message payload len)
 * @param    offset - The offset into the image to start reading from
 *
 * @return  status
 ***************************************************************************************************/
uint8 MT_OtaFileReadReq(afAddrType_t *pAddr, zclOTA_FileID_t *pFileId, uint8 len, uint32 offset)
{
  uint8   msgLen;
  uint8   *pBuf;
  uint8   *p;

  // Check if the requested length is longer than the RX receive buffer
  if (len + MT_OTA_FILE_READ_RSP_LEN + SPI_0DATA_MSG_LEN > MT_UART_RX_BUFF_MAX)
    return 0;
  
  // Get length
  msgLen = MT_OTA_FILE_READ_REQ_LEN;
  
  // Allocate a buffer
  if ((p = pBuf = MT_TransportAlloc(0, msgLen)) != NULL)
  {
    /* build header */
    *p++ = msgLen;
    *p++ = (uint8) MT_RPC_CMD_AREQ | (uint8) MT_RPC_SYS_OTA;
    *p++ = MT_OTA_FILE_READ_REQ;
    
    // Add the file ID
    p = OTA_FileIdToStream(pFileId, p);

    // Add the device address 
    p = OTA_AfAddrToStream(pAddr, p);

    // File ofset to read from
    *p++ = BREAK_UINT32(offset, 0);
    *p++ = BREAK_UINT32(offset, 1);
    *p++ = BREAK_UINT32(offset, 2);
    *p++ = BREAK_UINT32(offset, 3);

    *p = len;
    
    // Send command to server
    MT_TransportSend(pBuf);
    
    return ZSuccess;
  }
  
  return ZMemError;
}
Esempio n. 4
0
/***************************************************************************************************
 * @fn      MT_OtaGetImage
 *
 * @brief   Requests the next OTA image for a given device.
 *
 * @param   pAddr - Address of the device requesting the image
 * @param   pFileId - The file ID of the image currently on the device
 * @param   hwVer - The hardware version of the device (optional)
 * @param   ieee - The IEEE address of the device (optional)
 * @param   options - The get image options
 *
 * @return  Status
 *
 ***************************************************************************************************/
uint8 MT_OtaGetImage(afAddrType_t *pAddr, zclOTA_FileID_t *pFileId, uint16 hwVer, 
                     uint8 *ieee, uint8 options)
{
  uint8   msgLen;
  uint8   *pBuf;
  uint8   *p;

  // Get length
  msgLen = MT_OTA_GET_IMG_MSG_LEN;
  
  // Allocate a buffer
  if ((p = pBuf = MT_TransportAlloc(0, msgLen)) != NULL)
  {
    // build header
    *p++ = msgLen;
    *p++ = (uint8) MT_RPC_CMD_AREQ | (uint8) MT_RPC_SYS_OTA;
    *p++ = MT_OTA_NEXT_IMG_REQ;
    
    // Add the file ID
    p = OTA_FileIdToStream(pFileId, p);

    // Add the device address 
    p = OTA_AfAddrToStream(pAddr, p);

    // Add the options
    *p++ = options;

    // Add the hardware ID (optional)
    *p++ = LO_UINT16(hwVer);
    *p = HI_UINT16(hwVer);
    
    if (ieee)
      osal_memcpy(p, ieee, Z_EXTADDR_LEN);
  
    // Send command to server
    MT_TransportSend(pBuf);
    
    return ZSuccess;
  }
  
  return ZMemError;
}