Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈伟灿
k-sdk
Commits
051541e3
Commit
051541e3
authored
Sep 09, 2020
by
黄振令
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】网关增加ota 文件下载
【提交人】huang.zhenling
parent
fc3fe0ee
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
169 additions
and
11 deletions
+169
-11
common/curl/README.txt
common/curl/README.txt
+1
-0
platform/zigbee/app/builder/Z3GatewayHost/Makefile
platform/zigbee/app/builder/Z3GatewayHost/Makefile
+4
-2
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_palt_ota.c
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_palt_ota.c
+153
-0
platform/zigbee/app/builder/Z3GatewayHost/rpc_api/src/rpc_interface_parse.c
...p/builder/Z3GatewayHost/rpc_api/src/rpc_interface_parse.c
+11
-9
No files found.
common/curl/README.txt
View file @
051541e3
1. 版本:tiny-curl-7.72.0
download:https://curl.haxx.se/tiny/
2. 编译so选项:./configure --disable-dict --disable-ftp --disable-imap --disable-ldap --disable-file --disable-gopher --disable-imap --disable-ldaps --disable-pop3 --disable-proxy --disable-rtsp --disable-smtp --disable-telnet --disable-tftp --disable-zlib --without-ca-bundle --without-gnutls --without-libidn --without-librtmp --without-libssh2 --without-nss --without-zlib
...
...
platform/zigbee/app/builder/Z3GatewayHost/Makefile
View file @
051541e3
...
...
@@ -87,6 +87,7 @@ INCLUDES= \
-I
./../../../platform/base/hal/micro/unix/host
\
-I
../../../platform/base/hal/micro/unix/host/board
\
-I
./rpc_api/inc
\
-I
../../../../../common/curl/include
\
-I
./ZB
\
...
...
@@ -284,6 +285,7 @@ APPLICATION_FILES= \
./ZB/kk_zigbee_api.c
\
./ZB/kk_tsl_property_report.c
\
./ZB/kk_tsl_property_set.c
\
./ZB/kk_palt_ota.c
\
./kk_test.c
\
./kk_sub_tsl.c
\
./kk_tsl_zigbee_map.c
\
...
...
@@ -373,10 +375,10 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
else
$(TARGET_FILE)
:
$(APPLICATION_OBJECTS) $(LIBRARIES)
ifeq
($(CONFIG_VENDOR),ubuntu)
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-lapi_com_ubuntu
-lnanomsg_ubuntu
-lanl
-pthread
-lev_ubuntu
-lkk_hal_ubuntu
-o
$(TARGET_FILE)
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-lapi_com_ubuntu
-lnanomsg_ubuntu
-lanl
-pthread
-lev_ubuntu
-lkk_hal_ubuntu
-L
../../../../../common/curl
-lcurl_ubuntu
-o
$(TARGET_FILE)
@
echo
-e
'\n$@ build success'
else
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-lapi_com
-lnanomsg
-lanl
-pthread
-lev
-lkk_hal
-o
$(TARGET_FILE)
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-lapi_com
-lnanomsg
-lanl
-pthread
-lev
-lkk_hal
-L
../../../../../common/curl
-lcurl
-o
$(TARGET_FILE)
@
echo
-e
'\n$@ build success'
endif
endif
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_palt_ota.c
0 → 100644
View file @
051541e3
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include "curl.h"
#include "./jsonrpc/rpccJSON.h"
size_t
kk_write_func
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
FILE
*
stream
)
{
return
fwrite
(
ptr
,
size
,
nmemb
,
stream
);
}
int
kk_progress_func
(
char
*
progress_data
,
double
t
,
/* dltotal */
double
d
,
/* dlnow */
double
ultotal
,
double
ulnow
)
{
printf
(
"%s %g / %g (%g %%)
\n
"
,
progress_data
,
d
,
t
,
d
*
100
.
0
/
t
);
return
0
;
}
int
kk_http_download
(
char
*
url
,
char
*
filename
)
{
CURL
*
curl
;
CURLcode
res
;
FILE
*
outfile
;
char
*
progress_data
=
"* "
;
if
(
url
==
NULL
||
filename
==
NULL
){
printf
(
"params error url or filename
\n
"
);
return
-
1
;
}
curl
=
curl_easy_init
();
if
(
curl
)
{
outfile
=
fopen
(
filename
,
"wb"
);
//fopen("test.jpg", "wb");
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
outfile
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
kk_write_func
);
curl_easy_setopt
(
curl
,
CURLOPT_NOPROGRESS
,
0
);
curl_easy_setopt
(
curl
,
CURLOPT_PROGRESSFUNCTION
,
kk_progress_func
);
curl_easy_setopt
(
curl
,
CURLOPT_PROGRESSDATA
,
progress_data
);
res
=
curl_easy_perform
(
curl
);
fclose
(
outfile
);
/* always cleanup */
curl_easy_cleanup
(
curl
);
}
return
0
;
}
int
kk_ota_process
(
cJSON
*
root
){
cJSON
*
params
;
cJSON
*
id
;
cJSON
*
mac
;
cJSON
*
info
;
cJSON
*
msgType
;
cJSON
*
payload
;
cJSON
*
url
;
cJSON
*
md5
;
cJSON
*
size
;
int
ret
=
0
;
struct
stat
st
;
int
iFileSize
;
printf
(
"===============kk_ota_process
\n
"
);
info
=
rpc_cJSON_GetObjectItem
(
root
,
"info"
);
if
(
info
!=
NULL
){
msgType
=
rpc_cJSON_GetObjectItem
(
info
,
"msgType"
);
mac
=
rpc_cJSON_GetObjectItem
(
info
,
"deviceCode"
);
}
payload
=
rpc_cJSON_GetObjectItem
(
root
,
"payload"
);
if
(
payload
!=
NULL
){
printf
(
"===============kk_ota_process ===========11111111
\n
"
);
params
=
rpc_cJSON_GetObjectItem
(
payload
,
"data"
);
//id = rpc_cJSON_GetObjectItem(payload, "msgId");
url
=
rpc_cJSON_GetObjectItem
(
params
,
"url"
);
md5
=
rpc_cJSON_GetObjectItem
(
params
,
"md5"
);
size
=
rpc_cJSON_GetObjectItem
(
params
,
"size"
);
printf
(
"===============kk_ota_process ===========[%s][%s][%s]
\n
"
,
url
->
valuestring
,
mac
->
valuestring
,
size
->
valuestring
);
kk_http_download
(
url
->
valuestring
,
mac
->
valuestring
);
if
(
stat
(
mac
->
valuestring
,
&
st
))
printf
(
"读取出错!
\n
"
);
iFileSize
=
st
.
st_size
;
if
(
iFileSize
!=
atoi
(
size
->
valuestring
)){
printf
(
"check file size failed [%d][%s]
\n
"
,
iFileSize
,
size
->
valuestring
);
return
-
1
;
}
char
md5File
[
21
]
=
{
0
};
char
cmd
[
100
]
=
{
0
};
char
md5str
[
34
]
=
{
0
};
FILE
*
fp
;
sprintf
(
md5File
,
"%s.md5"
,
mac
->
valuestring
);
sprintf
(
cmd
,
"md5sum %s|cut -d
\"
\"
-f1 > %s"
,
mac
->
valuestring
,
md5File
);
system
(
cmd
);
//snprintf(filepath, sizeof(filepath), "./%s", "alinkconf");
fp
=
fopen
(
md5File
,
"r"
);
if
(
!
fp
)
{
printf
(
"open file failed
\n
"
);
return
-
1
;
}
int
readlen
=
fread
(
md5str
,
1
,
32
,
fp
);
printf
(
"md5sum readlen=%d, md5str=%s,md5->valuestring=%s
\n
"
,
readlen
,
md5str
,
md5
->
valuestring
);
if
(
readlen
>
0
&&
strcmp
(
md5str
,
md5
->
valuestring
)
==
0
){
printf
(
"check md5sum succees
\n
"
);
ret
=
0
;
}
else
{
printf
(
"check md5sum failed
\n
"
);
ret
=
-
1
;
}
fclose
(
fp
);
return
ret
;
}
return
-
1
;
}
platform/zigbee/app/builder/Z3GatewayHost/rpc_api/src/rpc_interface_parse.c
View file @
051541e3
...
...
@@ -222,23 +222,25 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
return
-
1
;
}
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
void
_cb
(
void
*
data
){
void
_cb
(
void
*
data
,
int
len
,
char
*
chlmark
){
if
(
data
!=
NULL
){
//printf("plat2mid_cb: %s RECEIVED \r\n", data);
printf
(
"plat_cb: %s RECEIVED
\r\n
"
,
data
);
cJSON
*
root
;
char
*
end_ptr
=
NULL
;
if
((
root
=
rpc_cJSON_Parse_Stream
(
data
,
&
end_ptr
))
!=
NULL
)
{
if
(
1
)
{
char
*
str_result
=
rpc_cJSON_Print
(
root
);
printf
(
"Valid JSON Received:
\n
%s
\n
"
,
str_result
);
free
(
str_result
);
}
if
(
root
->
type
==
cJSON_Object
)
{
eval_request
(
&
my_server
,
root
);
cJSON
*
info
=
rpc_cJSON_GetObjectItem
(
root
,
"info"
);
if
(
info
!=
NULL
&&
strstr
(
rpc_cJSON_GetObjectItem
(
info
,
"msgType"
)
->
valuestring
,
KK_THING_OTA_DEVICE_UPGRADE
)
!=
NULL
){
kk_ota_process
(
root
);
}
else
{
eval_request
(
&
my_server
,
root
);
}
}
//shift processed request, discarding it
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment