m2m_ota.c
Go to the documentation of this file.
1 
37 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
38 INCLUDES
39 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
42 #include "driver/include/m2m_ota.h"
44 #include "driver/source/m2m_hif.h"
45 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
46 MACROS
47 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
48 
49 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
50 DATA TYPES
51 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
54 
55 
56 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
57 FUNCTION PROTOTYPES
58 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
74 static void m2m_ota_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr)
75 {
76  sint8 ret = M2M_SUCCESS;
77  if(u8OpCode == M2M_OTA_RESP_NOTIF_UPDATE_INFO)
78  {
79  tstrOtaUpdateInfo strOtaUpdateInfo;
80  m2m_memset((uint8*)&strOtaUpdateInfo,0,sizeof(tstrOtaUpdateInfo));
81  ret = hif_receive(u32Addr,(uint8*)&strOtaUpdateInfo,sizeof(tstrOtaUpdateInfo),0);
82  if(ret == M2M_SUCCESS)
83  {
84  if(gpfOtaNotifCb)
85  gpfOtaNotifCb(&strOtaUpdateInfo);
86  }
87  }
88  else if (u8OpCode == M2M_OTA_RESP_UPDATE_STATUS)
89  {
90  tstrOtaUpdateStatusResp strOtaUpdateStatusResp;
91  m2m_memset((uint8*)&strOtaUpdateStatusResp,0,sizeof(tstrOtaUpdateStatusResp));
92  ret = hif_receive(u32Addr, (uint8*) &strOtaUpdateStatusResp,sizeof(tstrOtaUpdateStatusResp), 0);
93  if(ret == M2M_SUCCESS)
94  {
95  if(gpfOtaUpdateCb)
96  gpfOtaUpdateCb(strOtaUpdateStatusResp.u8OtaUpdateStatusType,strOtaUpdateStatusResp.u8OtaUpdateStatus);
97  }
98  }
99  else
100  {
101  M2M_ERR("Invaild OTA resp %d ?\n",u8OpCode);
102  }
103 
104 }
122 {
123  sint8 ret = M2M_SUCCESS;
124 
125  if(pfOtaUpdateCb){
126  gpfOtaUpdateCb = pfOtaUpdateCb;
127  }else{
128  M2M_ERR("Invaild Ota update cb\n");
129  }
130  if(pfOtaNotifCb){
131  gpfOtaNotifCb = pfOtaNotifCb;
132  }else{
133  M2M_ERR("Invaild Ota notify cb\n");
134  }
135 
137 
138  return ret;
139 }
154 {
155  sint8 ret = M2M_SUCCESS;
156  uint16 u16UrlSize = m2m_strlen(u8Url) + 1;
157  /*Todo: we may change it to data pkt but we need to give it higer priority
158  but the priorty is not implemnted yet in data pkt
159  */
160  ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_START_UPDATE,u8Url,u16UrlSize,NULL,0,0);
161  return ret;
162 
163 }
164 
176 {
177  sint8 ret = M2M_SUCCESS;
179  return ret;
180 }
181 
196 {
197  sint8 ret = M2M_SUCCESS;
199  return ret;
200 }
201 
217 {
218  sint8 ret = M2M_SUCCESS;
219  uint16 u16DurlSize = m2m_strlen(u8DownloadUrl) + 1;
220  /*Todo: we may change it to data pkt but we need to give it higer priority
221  but the priorty is not implemnted yet in data pkt
222  */
223  ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_START_UPDATE,u8DownloadUrl,u16DurlSize,NULL,0,0);
224  return ret;
225 }
226 
227 
239 {
240  sint8 ret = M2M_SUCCESS;
241  tstrM2mRev strRev;
242 
243  ret = m2m_ota_get_firmware_version(&strRev);
244  if(ret == M2M_SUCCESS)
245  {
247  {
249  }
250  else
251  {
252  ret = M2M_ERR_FAIL;
253  }
254  }
255  return ret;
256 }
257 
258 
270 {
271  sint8 ret = M2M_SUCCESS;
273  return ret;
274 }
275 
276 
288 {
289  sint8 ret = M2M_SUCCESS;
290  tstrM2mRev strRev;
291 
292  ret = m2m_ota_get_firmware_version(&strRev);
293  if(ret == M2M_SUCCESS)
294  {
296  {
298  }
299  else
300  {
301  ret = M2M_ERR_FAIL;
302  }
303  }
304  return ret;
305 }
306 #if 0
307 #define M2M_OTA_FILE "../../../m2m_ota.dat"
308 NMI_API sint8 m2m_ota_test(void)
309 {
310  uint32 page = 0;
311  uint8 buffer[1500];
312  uint32 u32Sz = 0;
313  sint8 ret = M2M_SUCCESS;
314  FILE *fp =NULL;
315  fp = fopen(M2M_OTA_FILE,"rb");
316  if(fp)
317  {
318  fseek(fp, 0L, SEEK_END);
319  u32Sz = ftell(fp);
320  fseek(fp, 0L, SEEK_SET);
321 
322  while(u32Sz > 0)
323  {
324  {
325  page = (rand()%1400);
326 
327  if((page<100)||(page>1400)) page = 1400;
328  }
329 
330  if(u32Sz>page)
331  {
332  u32Sz-=page;
333  }
334  else
335  {
336  page = u32Sz;
337  u32Sz = 0;
338  }
339  printf("page %d\n", (int)page);
340  fread(buffer,page,1,fp);
342  if(ret != M2M_SUCCESS)
343  {
344  M2M_ERR("\n");
345  }
346  nm_bsp_sleep(1);
347  }
348 
349  }
350  else
351  {
352  M2M_ERR("nO err\n");
353  }
354  return ret;
355 }
356 #endif
357 
static tpfOtaNotifCb gpfOtaNotifCb
Definition: m2m_ota.c:53
#define M2M_ERR_FAIL
Definition: nm_common.h:63
This module contains common APIs declarations.
#define M2M_HIF_BLOCK_VALUE
Definition: m2m_types.h:133
signed char sint8
Range of values between -128 to 127.
Definition: nm_bsp.h:111
NMI_API sint8 m2m_ota_notif_check_for_update(void)
check for ota update
Definition: m2m_ota.c:175
NMI_API sint8 m2m_ota_notif_sched(uint32 u32Period)
Schedule OTA update.
Definition: m2m_ota.c:195
NMI_API sint8 m2m_ota_start_update(uint8 *u8DownloadUrl)
Request OTA start update using the downloaded url.
Definition: m2m_ota.c:216
#define M2M_SUCCESS
Definition: nm_common.h:51
NMI_API sint8 m2m_ota_rollback(void)
Request OTA Rollback image.
Definition: m2m_ota.c:238
WINC3400 IoT Application Interface Internal Types.
#define NULL
Definition: nm_bsp.h:52
NMI_API sint8 m2m_ota_notif_set_url(uint8 *u8Url)
Set the OTA url.
Definition: m2m_ota.c:153
unsigned short uint16
Range of values between 0 to 65535.
Definition: nm_bsp.h:96
This struct contains the OTA update information.
Definition: m2m_types.h:2182
WINC3400 IoT Application Interface.
sint8 hif_register_cb(uint8 u8Grp, tpfHifCallBack fn)
Definition: m2m_hif.c:839
#define printf(...)
Definition: evb_tasks.h:36
void nm_bsp_sleep(uint32 u32TimeMsec)
NMI_API void m2m_memset(uint8 *pBuf, uint8 val, uint32 sz)
Set specified number of data bytes in specified data buffer to specified value.
Definition: nm_common.c:58
WINC3400 IoT OTA Interface.
NMI_API uint16 m2m_strlen(uint8 *pcStr)
Returns the string length of a null terminated string buffer.
Definition: nm_common.c:68
#define M2M_ERR(...)
Definition: nm_debug.h:80
uint16 u16FirmwareHifInfo
Definition: nmdrv.h:45
void(* tpfOtaUpdateCb)(uint8 u8OtaUpdateStatusType, uint8 u8OtaUpdateStatus)
A callback to get OTA status update, the callback provides the download status, the switch to the dow...
Definition: m2m_ota.h:90
sint8 hif_send(uint8 u8Gid, uint8 u8Opcode, uint8 *pu8CtrlBuf, uint16 u16CtrlBufSize, uint8 *pu8DataBuf, uint16 u16DataSize, uint16 u16DataOffset)
Send packet using host interface.
Definition: m2m_hif.c:439
NMI_API sint8 m2m_ota_switch_firmware(void)
Switch to the upgraded Firmware.
Definition: m2m_ota.c:287
unsigned long uint32
Range of values between 0 to 4294967295.
Definition: nm_bsp.h:103
static void m2m_ota_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr)
Definition: m2m_ota.c:74
static tpfOtaUpdateCb gpfOtaUpdateCb
Definition: m2m_ota.c:52
void(* tpfOtaNotifCb)(tstrOtaUpdateInfo *pstrOtaUpdateInfo)
A callback to get notification about a potential OTA update.
Definition: m2m_ota.h:68
unsigned char uint8
Range of values between 0 to 255.
Definition: nm_bsp.h:89
This struct contains the OTA update status.
Definition: m2m_types.h:2153
NMI_API sint8 m2m_ota_get_firmware_version(tstrM2mRev *pstrRev)
Synchronous API to obtain the firmware version of the WINC image that is stored in the inactive flash...
Definition: m2m_wifi.c:1186
This module contains M2M host interface APIs implementation.
NMI_API sint8 m2m_ota_init(tpfOtaUpdateCb pfOtaUpdateCb, tpfOtaNotifCb pfOtaNotifCb)
Initialize the OTA layer.
Definition: m2m_ota.c:121
#define M2M_GET_HIF_BLOCK(hif_info)
Definition: m2m_types.h:120
Structure holding firmware version parameters and build date/time.
Definition: nmdrv.h:44
NMI_API sint8 m2m_ota_abort(void)
Request OTA Abort.
Definition: m2m_ota.c:269
sint8 hif_receive(uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone)
Definition: m2m_hif.c:762
#define NMI_API
Definition: nm_bsp.h:45


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57