1、搭建https服务器 (请参考如下文章,按照里面的做即可)
https://blog.csdn.net/laing92/article/details/104378537
install过后 ,根目录地址:usr/share/nginx/html
更改根目录地址,未能成功,折腾一番后,决定暂时先这样,急着完成下面的步骤。
将下载文件(升级文件)拷贝到usr/share/nginx/html目录下 。
2、写ITE soc平台代码
#define AUDIOLINK_CONTENT_LENGTHS "Content-Length:"
#define CURL_READ_SIZE 64 * 1024
#include "curl/curl.h"
#define HTTPS_ADDRESS "https://192.168.43.65/ITEPKG03.pkg"
char _certsPath[128];
struct httpBuf
{
uint8_t *buf;
uint32_t pos;
};
typedef struct MemoryStruct
{
uint32_t *memory;
uint32_t size;
}MemoryStruct;
void CreateWorkerThread(void *(*start_routine)(void *), void *arg)
{
pthread_t task;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&task, &attr, start_routine, arg);
}
size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userdata)
{
size_t realsize = size * nmemb;
#if 1
MemoryStruct *mem = (MemoryStruct *)userdata;
mem->memory = (char*)realloc(mem->memory, mem->size + realsize + 1);
if(mem->memory == NULL) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
printf("download :realsize = %d / %d\n",realsize,mem->size);
#endif
return realsize;
}
void * DownPackage(void * argv)
{
CURL *curl;
CURLcode res;
bool downloadOK = false;
curl = curl_easy_init();
if(curl)
{
MemoryStruct writedatachunk;
writedatachunk.memory = (char*)malloc(1);
writedatachunk.size = 0;
//struct curl_slist *curlheaders = NULL;
//curlheaders = curl_slist_append(curlheaders, s2);
//curlheaders = curl_slist_append(curlheaders, "Accept: */*");
//curlheaders = curl_slist_append(curlheaders, "Content-Type: application/octet-stream");
//curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curlheaders);
curl_easy_setopt(curl, CURLOPT_URL, HTTPS_ADDRESS1);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 300L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3600L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&writedatachunk);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
//curl_easy_setopt(curl, CURLOPT_CAPATH, _certsPath);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
//curl_slist_free_all(curlheaders);
curl_easy_cleanup(curl);
free(writedatachunk.memory);
}
return NULL;
}
void main()
{
//create thread download package
CreateWorkerThread(DownPackage,NULL);
.....
......
}
打印信息如下:
GET /ITEPKG03.pkg HTTP/1.1
Host: 192.168.43.65
Accept: */*
< HTTP/1.1 200 OK
< Server: nginx/1.14.0 (Ubuntu)
< Date: Mon, 27 Dec 2021 15:39:21 GMT
< Content-Type: application/octet-stream
< Content-Length: 3310449
< Last-Modified: Mon, 27 Dec 2021 15:29:19 GMT
< Connection: keep-alive
< ETag: "61c9dbcf-328371"
< Accept-Ranges: bytes
<
download :realsize = 16115 / mem->size
download :realsize = 16384 / mem->size
.....
.....
download :realsize = 16384 / mem->size
download :realsize = 16384 / mem->size
download :realsize = 16384 / mem->size
download :realsize = 16384 / mem->size
download :realsize = 1150 / mem->size
具体也可参考curl 官网的相关范例进行修改。
谢谢!