123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- #ifdef MT_OTA_FUNC
- #include "ZComDef.h"
- #include "OSAL.h"
- #include "MT.h"
- #include "MT_OTA.h"
- #if !defined( WIN32 )
- #include "OnBoard.h"
- #endif
- uint8 OTA_Task = 0xFF;
- void MT_OtaRegister(uint8 taskId)
- {
- OTA_Task = taskId;
- }
- uint8 MT_OtaCommandProcessing(uint8* pBuf)
- {
- uint8 status = MT_RPC_SUCCESS;
- uint8 len;
- OTA_MtMsg_t *pMsg;
- uint8 cmd = pBuf[MT_RPC_POS_CMD1];
- if (cmd == MT_OTA_FILE_READ_RSP || cmd == MT_OTA_NEXT_IMG_RSP)
- {
-
- if (OTA_Task != 0xff)
- {
- len = pBuf[MT_RPC_POS_LEN];
- pMsg = (OTA_MtMsg_t*) osal_msg_allocate(len + sizeof(OTA_MtMsg_t));
-
- if (pMsg)
- {
- pMsg->hdr.event = MT_SYS_OTA_MSG;
- pMsg->cmd = cmd;
-
- osal_memcpy(pMsg->data, &pBuf[MT_RPC_POS_DAT0], len);
- osal_msg_send(OTA_Task, (uint8*) pMsg);
- }
- }
- }
- else
- {
- status = MT_RPC_ERR_COMMAND_ID;
- }
- return status;
- }
- uint8 MT_OtaFileReadReq(afAddrType_t *pAddr, zclOTA_FileID_t *pFileId, uint8 len, uint32 offset)
- {
- uint8 msgLen;
- uint8 *pBuf;
- uint8 *p;
-
- if (len + MT_OTA_FILE_READ_RSP_LEN + SPI_0DATA_MSG_LEN > MT_UART_RX_BUFF_MAX)
- return 0;
-
-
- msgLen = MT_OTA_FILE_READ_REQ_LEN;
-
-
- if ((p = pBuf = MT_TransportAlloc(0, msgLen)) != NULL)
- {
-
- *p++ = msgLen;
- *p++ = (uint8) MT_RPC_CMD_AREQ | (uint8) MT_RPC_SYS_OTA;
- *p++ = MT_OTA_FILE_READ_REQ;
-
-
- p = OTA_FileIdToStream(pFileId, p);
-
- p = OTA_AfAddrToStream(pAddr, p);
-
- *p++ = BREAK_UINT32(offset, 0);
- *p++ = BREAK_UINT32(offset, 1);
- *p++ = BREAK_UINT32(offset, 2);
- *p++ = BREAK_UINT32(offset, 3);
- *p = len;
-
-
- MT_TransportSend(pBuf);
-
- return ZSuccess;
- }
-
- return ZMemError;
- }
- uint8 MT_OtaGetImage(afAddrType_t *pAddr, zclOTA_FileID_t *pFileId, uint16 hwVer,
- uint8 *ieee, uint8 options)
- {
- uint8 msgLen;
- uint8 *pBuf;
- uint8 *p;
-
- msgLen = MT_OTA_GET_IMG_MSG_LEN;
-
-
- if ((p = pBuf = MT_TransportAlloc(0, msgLen)) != NULL)
- {
-
- *p++ = msgLen;
- *p++ = (uint8) MT_RPC_CMD_AREQ | (uint8) MT_RPC_SYS_OTA;
- *p++ = MT_OTA_NEXT_IMG_REQ;
-
-
- p = OTA_FileIdToStream(pFileId, p);
-
- p = OTA_AfAddrToStream(pAddr, p);
-
- *p++ = options;
-
- *p++ = LO_UINT16(hwVer);
- *p = HI_UINT16(hwVer);
-
- if (ieee)
- osal_memcpy(p, ieee, Z_EXTADDR_LEN);
-
-
- MT_TransportSend(pBuf);
-
- return ZSuccess;
- }
-
- return ZMemError;
- }
- uint8 MT_OtaSendStatus(uint16 shortAddr, uint8 type, uint8 status, uint8 optional)
- {
- uint8 msgLen;
- uint8 *pBuf;
- uint8 *p;
-
- msgLen = 7;
-
-
- if ((p = pBuf = MT_TransportAlloc(0, msgLen)) != NULL)
- {
-
- *p++ = msgLen;
- *p++ = (uint8) MT_RPC_CMD_AREQ | (uint8) MT_RPC_SYS_OTA;
- *p++ = MT_OTA_STATUS_IND;
-
-
- *p++ = LO_UINT16(_NIB.nwkPanId);
- *p++ = HI_UINT16(_NIB.nwkPanId);
- *p++ = LO_UINT16(shortAddr);
- *p++ = HI_UINT16(shortAddr);
- *p++ = type;
- *p++ = status;
- *p = optional;
-
-
- MT_TransportSend(pBuf);
-
- return ZSuccess;
- }
-
- return ZMemError;
- }
- #endif
|