Microchip® Advanced Software Framework

httpdownloader.c File Reference

HTTP File Downloader Example Implementation.

Copyright (c) 2018 Microchip Technology Inc. and its subsidiaries.

#include <errno.h>
#include "asf.h"
#include "httpdownloader.h"
#include "FreeRTOS.h"
#include "iot/http/http_client.h"
#include "osprintf.h"
#include "lwip/ip.h"
#include "lwip/api.h"
#include "lwip/tcpip.h"
#include "lwip/sockets.h"
#include "os/include/net_init.h"
#include "os/include/m2m_wifi_ex.h"
#include "tinyservices.h"
#include "conf_wilc.h"
#include "ota_fw_update/ota_fw_update.h"
#include <string.h>
#include <stdio.h>

Functions

static void add_state (download_state mask)
 Add state parameter at download processing state. More...
 
static void clear_state (download_state mask)
 Clear state parameter at download processing state. More...
 
static int configure_http_client (void)
 Configure HTTP client module. More...
 
static void configure_timer (void)
 Configure Timer module. More...
 
static int dismantle_http_client (void)
 close HTTP client module. More...
 
static void http_client_callback (struct http_client_module *module_inst, int type, union http_client_data *data)
 Callback of the HTTP client. More...
 
int http_downloader (char *fileURL)
 http downloader function. More...
 
static void init_state (void)
 Initialize download state to not ready. More...
 
static bool is_state_set (download_state mask)
 File download processing state check. More...
 
void setFirmwareDownload (int val)
 
static void start_download (char *fileURL)
 Start file download via HTTP connection. More...
 
static void store_file_packet (char *data, uint32_t length)
 Ignore data, but calculate the total received size TODO: Store received packet to file. More...
 

Variables

static download_state down_state = NOT_READY
 File download processing state. More...
 
char * gfileURL
 
struct http_client_module http_client_module_inst
 Instance of HTTP client module. More...
 
static uint32_t http_file_size = 0
 Http content length. More...
 
static int is_firmware = 0
 File name to download. More...
 
static uint32_t received_file_size = 0
 Receiving content length. More...
 
struct sw_timer_module swt_module_inst
 Instance of Timer module. More...
 

static void add_state ( download_state  mask)
static

Add state parameter at download processing state.

Parameters
[in]maskCheck download_state.

References down_state.

Referenced by http_client_callback(), and store_file_packet().

static void clear_state ( download_state  mask)
static

Clear state parameter at download processing state.

Parameters
[in]maskCheck download_state.

References down_state.

Referenced by http_client_callback().

static void configure_timer ( void  )
static

Configure Timer module.

References sw_timer_enable(), sw_timer_get_config_defaults(), sw_timer_init(), and swt_module_inst.

Referenced by http_downloader().

static int dismantle_http_client ( void  )
static

close HTTP client module.

References FAILURE, http_client_close(), http_client_deinit(), http_client_module_inst, osprintf(), and SUCCESS.

Referenced by http_downloader().

int http_downloader ( char *  fileURL)
static void init_state ( void  )
static

Initialize download state to not ready.

References down_state, and NOT_READY.

Referenced by http_downloader().

static bool is_state_set ( download_state  mask)
inlinestatic

File download processing state check.

Parameters
[in]maskCheck download_state.
Returns
true if this state is set, false otherwise.

References down_state.

Referenced by http_client_callback(), http_downloader(), start_download(), and store_file_packet().

void setFirmwareDownload ( int  val)

References is_firmware.

static void start_download ( char *  fileURL)
static
static void store_file_packet ( char *  data,
uint32_t  length 
)
static

Ignore data, but calculate the total received size TODO: Store received packet to file.

Parameters
[in]dataPacket data.
[in]lengthPacket data length.

References add_state(), CANCELED, COMPLETED, DOWNLOADING, http_file_size, is_firmware, is_state_set(), NULL, osprintf(), received_file_size, and SUCCESS.

Referenced by http_client_callback().

download_state down_state = NOT_READY
static

File download processing state.

Referenced by add_state(), clear_state(), init_state(), and is_state_set().

char* gfileURL
struct http_client_module http_client_module_inst

Instance of HTTP client module.

Referenced by configure_http_client(), dismantle_http_client(), and start_download().

uint32_t http_file_size = 0
static

Http content length.

Referenced by http_client_callback(), and store_file_packet().

int is_firmware = 0
static

File name to download.

Referenced by setFirmwareDownload(), and store_file_packet().

uint32_t received_file_size = 0
static

Receiving content length.

Referenced by http_client_callback(), and store_file_packet().

struct sw_timer_module swt_module_inst

Instance of Timer module.

Referenced by configure_http_client(), configure_timer(), and main().