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
39117df4
Commit
39117df4
authored
Sep 11, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://172.17.3.10:17001/chenweican/k-sdk
# Conflicts: # midware/midware/dm/kk_dm_msg.h
parents
490a67cf
051541e3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
251 additions
and
90 deletions
+251
-90
common/curl/README.txt
common/curl/README.txt
+1
-0
midware/midware/dm/kk_dm_msg.h
midware/midware/dm/kk_dm_msg.h
+60
-59
midware/midware/midware.c
midware/midware/midware.c
+22
-20
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 @
39117df4
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
...
...
midware/midware/dm/kk_dm_msg.h
View file @
39117df4
...
...
@@ -46,6 +46,7 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_ONLINE_TOPIC_REPLY "/thing/status/online_reply"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_SERVICE_PROPERTY_GET "/thing/service/property/get"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate_reply"
#define KK_THING_TOPO_ADD_MSG "/thing/topo/add"
...
...
midware/midware/midware.c
View file @
39117df4
...
...
@@ -27,7 +27,7 @@ char * g_filerToPlatTable[] =
{
KK_REGISTER_TOPIC_REPLY
},
{
KK_ADD_TOPIC_REPLY
},
{
KK_LOGIN_TOPIC_REPLY
},
{
KK_THING_
OTA_DEVICE_UPGRADE
},
{
KK_THING_
SERVICE_PROPERTY_GET
},
{
KK_THING_CLOUDSTATE_MSG
},
};
...
...
@@ -61,38 +61,42 @@ void kk_sendData2gw(void* data, int len, char* chalMark){
void
mid_cb
(
void
*
data
,
int
len
){
if
(
data
!=
NULL
){
char
*
out
;
cJSON
*
json
;
cJSON
*
info_root
,
*
info
,
*
type
;
cJSON
*
payload
;
cJSON
*
info_root
,
*
type
;
cJSON
*
deviceCode
;
int
res
;
void
*
buf
=
malloc
(
len
);
memcpy
(
buf
,
data
,
len
);
res
=
dm_queue_msg_insert
((
void
*
)
buf
);
if
(
res
!=
SUCCESS_RETURN
)
{
free
(
buf
);
//return FAIL_RETURN;
}
json
=
cJSON_Parse
(
data
);
if
(
!
json
)
{
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
ERROR_PRINT
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
}
else
{
info_root
=
cJSON_GetObjectItem
(
json
,
MSG_INFO_STR
);
if
(
info_root
==
NULL
){
ERROR_PRINT
(
" params [%s] can't find
\n
"
,
MSG_INFO_STR
);
cJSON_Delete
(
json
);
return
;
}
deviceCode
=
cJSON_GetObjectItem
(
info_root
,
MSG_DEVICE_CODE_STR
);
type
=
cJSON_GetObjectItem
(
info_root
,
MSG_TYPE_STR
);
if
(
_kk_filter_to_plat
(
type
->
valuestring
)){
if
(
deviceCode
==
NULL
||
type
==
NULL
){
ERROR_PRINT
(
" params [%s] or [%s] can't find
\n
"
,
MSG_DEVICE_CODE_STR
,
MSG_TYPE_STR
);
cJSON_Delete
(
json
);
cJSON_Delete
(
info
);
return
;
}
int
devType
=
0
;
dm_mgr_get_devicetype_by_devicecode
(
deviceCode
->
valuestring
,
&
devType
);
if
(
devType
==
KK_DM_DEVICE_GATEWAY
){
//主机的device或过滤的
if
(
devType
==
KK_DM_DEVICE_CCU
||
_kk_filter_to_plat
(
type
->
valuestring
)){
void
*
buf
=
malloc
(
len
);
memcpy
(
buf
,
data
,
len
);
res
=
dm_queue_msg_insert
((
void
*
)
buf
);
if
(
res
!=
SUCCESS_RETURN
)
{
free
(
buf
);
}
}
else
if
(
devType
==
KK_DM_DEVICE_GATEWAY
){
kk_sendData2gw
(
data
,
strlen
(
data
),
deviceCode
->
valuestring
);
//send to gw itself
}
else
if
(
devType
==
KK_DM_DEVICE_SUBDEV
){
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
...
...
@@ -100,7 +104,6 @@ void mid_cb(void* data, int len){
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"res:%d
\n
"
,
res
);
cJSON_Delete
(
json
);
cJSON_Delete
(
info
);
return
;
}
kk_sendData2gw
(
data
,
strlen
(
data
),
gw_node
->
fatherDeviceCode
);
//send to sub device
...
...
@@ -109,7 +112,6 @@ void mid_cb(void* data, int len){
ERROR_PRINT
(
"wrong type
\n
"
);
}
cJSON_Delete
(
json
);
cJSON_Delete
(
info
);
}
}
...
...
platform/zigbee/app/builder/Z3GatewayHost/Makefile
View file @
39117df4
...
...
@@ -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 @
39117df4
#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 @
39117df4
...
...
@@ -222,24 +222,26 @@ 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
)
{
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
rpc_cJSON_Delete
(
root
);
...
...
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