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
19e63444
Commit
19e63444
authored
Aug 25, 2020
by
黄振令
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】设备加入后,发送/topo/add和/status/online 服务器交互命令
【修改人】huang.zhenling
parent
17c5ff55
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
40 deletions
+41
-40
midware/midware/dm/kk_dm_mng.c
midware/midware/dm/kk_dm_mng.c
+8
-20
midware/midware/dm/kk_dm_msg.c
midware/midware/dm/kk_dm_msg.c
+8
-4
midware/midware/dm/kk_dm_msg.h
midware/midware/dm/kk_dm_msg.h
+1
-0
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+12
-10
midware/midware/dm/kk_sub_db.c
midware/midware/dm/kk_sub_db.c
+4
-1
midware/midware/midware.c
midware/midware/midware.c
+8
-5
No files found.
midware/midware/dm/kk_dm_mng.c
View file @
19e63444
...
...
@@ -728,7 +728,7 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
gw
_node
=
NULL
;
dm_mgr_dev_node_t
*
father
_node
=
NULL
;
dm_msg_request_t
request
;
if
(
devid
<
0
)
{
...
...
@@ -741,7 +741,7 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
ERROR_PRINT
(
"ERROR res:%d
\n
"
,
res
);
return
FAIL_RETURN
;
}
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
gw
_node
);
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
father
_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
...
...
@@ -750,13 +750,13 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
request
.
msgTypeStr
=
DM_URI_THING_TOPO_ADD
;
memcpy
(
request
.
productType
,
gw_node
->
productType
,
strlen
(
gw
_node
->
productType
));
memcpy
(
request
.
productCode
,
gw_node
->
productCode
,
strlen
(
gw
_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
gw_node
->
deviceCode
,
strlen
(
gw
_node
->
deviceCode
));
memcpy
(
request
.
productType
,
father_node
->
productType
,
strlen
(
father
_node
->
productType
));
memcpy
(
request
.
productCode
,
father_node
->
productCode
,
strlen
(
father
_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
father_node
->
deviceCode
,
strlen
(
father
_node
->
deviceCode
));
/* Get Params And Method */
res
=
dm_msg_thing_topo_add
(
node
->
productType
,
node
->
productCode
,
node
->
deviceCode
,
&
request
);
res
=
dm_msg_thing_topo_add
(
node
->
productType
,
node
->
productCode
,
node
->
deviceCode
,
node
->
deviceCode
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -1172,11 +1172,11 @@ int dm_mgr_ota_report_version(_IN_ int devid, char *version)
int
dm_mgr_subdev_create
(
_IN_
char
productType
[
PRODUCT_TYPE_MAXLEN
],
int
dm_mgr_subdev_create
(
int
devtype
,
_IN_
char
productType
[
PRODUCT_TYPE_MAXLEN
],
_IN_
char
productCode
[
PRODUCT_CODE_MAXLEN
],
_IN_
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
_IN_
char
fatherMac
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
devid
){
int
res
=
0
;
res
=
dm_mgr_device_create
(
KK_DM_DEVICE_SUBDEV
,
productType
,
productCode
,
deviceCode
,
fatherMac
,
devid
);
res
=
dm_mgr_device_create
(
devtype
,
productType
,
productCode
,
deviceCode
,
fatherMac
,
devid
);
if
(
TSL_ALREADY_EXIST
==
res
)
{
ERROR_PRINT
(
"SUBDEV ALREADY EXIST!!!
\n
"
);
...
...
@@ -1184,15 +1184,3 @@ int dm_mgr_subdev_create(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
return
res
;
}
int
dm_mgr_gw_create
(
_IN_
char
productType
[
PRODUCT_TYPE_MAXLEN
],
_IN_
char
productCode
[
PRODUCT_CODE_MAXLEN
],
_IN_
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
_IN_
char
fatherMac
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
devid
){
int
res
=
0
;
res
=
dm_mgr_device_create
(
KK_DM_DEVICE_GATEWAY
,
productType
,
productCode
,
deviceCode
,
fatherMac
,
devid
);
if
(
TSL_ALREADY_EXIST
==
res
)
{
ERROR_PRINT
(
"GATEWAY ALREADY EXIST!!!
\n
"
);
}
return
res
;
}
midware/midware/dm/kk_dm_msg.c
View file @
19e63444
...
...
@@ -98,10 +98,13 @@ int dm_msg_thing_sub_unregister(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
const
char
DM_MSG_THING_TOPO_ADD_SIGN_SOURCE
[]
DM_READ_ONLY
=
"clientId%sdeviceName%sproductKey%stimestamp%s"
;
const
char
DM_MSG_THING_TOPO_ADD_METHOD
[]
DM_READ_ONLY
=
"thing.topo.add"
;
const
char
DM_MSG_THING_TOPO_ADD_PARAMS
[]
DM_READ_ONLY
=
"[{
\"
productKey
\"
:
\"
%s
\"
,
\"
deviceName
\"
:
\"
%s
\"
,
\"
signmethod
\"
:
\"
%s
\"
,
\"
sign
\"
:
\"
%s
\"
,
\"
timestamp
\"
:
\"
%s
\"
,
\"
clientId
\"
:
\"
%s
\"
}]"
;
//"[{\"productKey\":\"%s\",\"deviceName\":\"%s\",\"signmethod\":\"%s\",\"sign\":\"%s\",\"timestamp\":\"%s\",\"clientId\":\"%s\"}]";
"[{
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
,
\"
mac
\"
:
\"
%s
\"
}]"
;
int
dm_msg_thing_topo_add
(
_IN_
char
productType
[
PRODUCT_TYPE_MAXLEN
],
_IN_
char
productCode
[
PRODUCT_CODE_MAXLEN
],
_IN_
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
_IN_
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
_IN_
char
mac
[
DEVICE_MAC_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
{
char
*
params
=
NULL
;
int
params_len
=
0
;
...
...
@@ -169,8 +172,9 @@ int dm_msg_thing_topo_add(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
return
MEMORY_NOT_ENOUGH
;
}
memset
(
params
,
0
,
params_len
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_THING_TOPO_ADD_PARAMS
,
productType
,
deviceCode
,
sign_method
,
sign
,
timestamp
,
client_id
);
//HAL_Snprintf(params, params_len, DM_MSG_THING_TOPO_ADD_PARAMS, productType, deviceCode,
// sign_method, sign, timestamp, client_id);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_THING_TOPO_ADD_PARAMS
,
productCode
,
deviceCode
,
mac
);
request
->
params
=
params
;
request
->
params_len
=
strlen
(
request
->
params
);
...
...
midware/midware/dm/kk_dm_msg.h
View file @
19e63444
...
...
@@ -44,6 +44,7 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#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_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
...
...
midware/midware/dm/kk_linkkit.c
View file @
19e63444
...
...
@@ -249,7 +249,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
//get devicececret and save it
INFO_PRINT
(
" topic:register_reply
\n
"
);
dm_msg_response_payload_t
response
;
res
=
dm_msg_response_parse
((
char
*
)
payload_Str
,
strlen
(
payload
->
valuestring
)
+
1
,
&
response
);
res
=
dm_msg_response_parse
((
char
*
)
payload_Str
,
strlen
(
payload
_Str
)
+
1
,
&
response
);
if
(
res
!=
SUCCESS_RETURN
)
{
goto
directReturn
;
}
...
...
@@ -263,7 +263,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
//
INFO_PRINT
(
" topic:add_reply
\n
"
);
dm_msg_response_payload_t
response
;
res
=
dm_msg_response_parse
((
char
*
)
payload_Str
,
strlen
(
payload
->
valuestring
)
+
1
,
&
response
);
res
=
dm_msg_response_parse
((
char
*
)
payload_Str
,
strlen
(
payload
_Str
)
+
1
,
&
response
);
if
(
res
!=
SUCCESS_RETURN
)
{
goto
directReturn
;
}
...
...
@@ -272,12 +272,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_mutex_unlock
();
}
else
if
(
strstr
(
typeJson
->
valuestring
,
KK_LOGIN_TOPIC_REPLY
)){
}
else
if
(
strstr
(
typeJson
->
valuestring
,
KK_LOGIN_TOPIC_REPLY
)
||
strstr
(
typeJson
->
valuestring
,
KK_ONLINE_TOPIC_REPLY
)
){
//====todo======
//
INFO_PRINT
(
" topic:login_reply
\n
"
);
dm_msg_response_payload_t
response
;
res
=
dm_msg_response_parse
((
char
*
)
payload_Str
,
strlen
(
payload
->
valuestring
)
+
1
,
&
response
);
res
=
dm_msg_response_parse
((
char
*
)
payload_Str
,
strlen
(
payload
_Str
)
+
1
,
&
response
);
if
(
res
!=
SUCCESS_RETURN
)
{
goto
directReturn
;
}
...
...
@@ -1035,6 +1035,7 @@ int _iotx_linkkit_slave_connect(int devid)
return
FAIL_RETURN
;
}
#if 0
/* Subdev Register */
res = kk_dm_subdev_register(devid);
if (res < SUCCESS_RETURN) {
...
...
@@ -1075,7 +1076,9 @@ int _iotx_linkkit_slave_connect(int devid)
_iotx_linkkit_upstream_mutex_unlock();
}
#endif
/* Subdev Add Topo */
res
=
kk_dm_subdev_topo_add
(
devid
);
if
(
res
<
SUCCESS_RETURN
)
{
...
...
@@ -1336,7 +1339,7 @@ static int _iotx_linkkit_subdev_login(int devid)
void
*
semaphore
=
NULL
;
void
*
callback
=
NULL
;
res
=
iotx_dm_subdev_login
(
devid
);
res
=
iotx_dm_
dev_online
(
devid
);
//iotx_dm_
subdev_login(devid);
if
(
res
<
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -1669,18 +1672,18 @@ int iot_linkkit_subdev_query_id(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char
#endif /* #ifdef DEVICE_MODEL_GATEWAY */
int
kk_mid_subdev_add
(
char
productType
[
PRODUCT_TYPE_MAXLEN
],
char
productCode
[
PRODUCT_CODE_MAXLEN
],
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
char
fatherMac
[
DEVICE_MAC_MAXLEN
]){
int
kk_mid_subdev_add
(
int
devType
,
char
productType
[
PRODUCT_TYPE_MAXLEN
],
char
productCode
[
PRODUCT_CODE_MAXLEN
],
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
char
fatherMac
[
DEVICE_MAC_MAXLEN
]){
int
res
=
0
;
int
devid
=
0
;
res
=
dm_mgr_subdev_create
(
productType
,
productCode
,
deviceCode
,
fatherMac
,
&
devid
);
res
=
dm_mgr_subdev_create
(
devType
,
productType
,
productCode
,
deviceCode
,
fatherMac
,
&
devid
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"subdev create Failed
\n
"
);
return
FAIL_RETURN
;
}
INFO_PRINT
(
"subdev open susseed, devid = %d
\n
"
,
devid
);
res
=
kk_subDev_insert_db
(
KK_DM_DEVICE_SUBDEV
,
productCode
,
deviceCode
,
fatherMac
,
"1.1.0"
);
res
=
kk_subDev_insert_db
(
devType
,
productCode
,
deviceCode
,
fatherMac
,
"1.1.0"
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
...
...
@@ -1700,4 +1703,3 @@ int kk_mid_subdev_add(char productType[PRODUCT_TYPE_MAXLEN], char productCode[PR
return
SUCCESS_RETURN
;
}
midware/midware/dm/kk_sub_db.c
View file @
19e63444
...
...
@@ -90,7 +90,7 @@ static int _kk_load_subDevice(void)
INFO_PRINT
(
"_kk_load_subDevice total_column = %d
\n
"
,
sqlite3_column_count
(
stmt
));
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
res
=
dm_mgr_subdev_create
(
""
,
sqlite3_column_text
(
stmt
,
2
),
sqlite3_column_text
(
stmt
,
3
),
res
=
dm_mgr_subdev_create
(
sqlite3_column_int
(
stmt
,
7
),
""
,
sqlite3_column_text
(
stmt
,
2
),
sqlite3_column_text
(
stmt
,
3
),
sqlite3_column_text
(
stmt
,
4
),
&
devId
);
if
(
res
!=
SUCCESS_RETURN
){
...
...
@@ -100,6 +100,9 @@ static int _kk_load_subDevice(void)
ctx
->
subDevNum
++
;
}
usleep
(
100000
);
//如果为认证,需要认证
//再上线
iotx_dm_subscribe
(
devId
);
kk_dm_ota_report_version
(
devId
,
sqlite3_column_text
(
stmt
,
5
));
//version
//usleep(100000);
...
...
midware/midware/midware.c
View file @
19e63444
...
...
@@ -27,7 +27,8 @@ char * g_filerToPlatTable[] =
{
KK_ADD_TOPIC_REPLY
},
{
KK_LOGIN_TOPIC_REPLY
},
{
KK_THING_OTA_DEVICE_UPGRADE
},
{
KK_THING_CLOUDSTATE_MSG
},
{
KK_THING_CLOUDSTATE_MSG
},
{
KK_ONLINE_TOPIC_REPLY
},
};
static
int
_kk_filter_to_plat
(
const
char
*
msgtype
)
...
...
@@ -161,7 +162,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
proCode
=
cJSON_GetObjectItem
(
jsonPay
,
"productCode"
);
devCode
=
cJSON_GetObjectItem
(
jsonPay
,
"deviceCode"
);
INFO_PRINT
(
"productType productCode mac: [%s][%s] [%s]
\n
"
,
proType
->
valuestring
,
proCode
->
valuestring
,
mac
->
valuestring
);
kk_mid_subdev_add
(
proType
->
valuestring
,
proCode
->
valuestring
,
devCode
->
valuestring
,
mac
->
valuestring
);
kk_mid_subdev_add
(
KK_DM_DEVICE_SUBDEV
,
proType
->
valuestring
,
proCode
->
valuestring
,
devCode
->
valuestring
,
mac
->
valuestring
);
}
else
if
(
method
!=
NULL
&&
mac
!=
NULL
){
INFO_PRINT
(
"save property and send to cloud
\n
"
);
...
...
@@ -376,12 +377,14 @@ void *udp_dispatch_yield(void *args){
INFO_PRINT
(
"productType productCode deviceCode mac: [%s][%s][%s][%s]
\n
"
,
proType
->
valuestring
,
proCode
->
valuestring
,
devCode
->
valuestring
,
macstr
->
valuestring
);
int
res
=
dm_mgr_gw_create
(
proType
->
valuestring
,
proCode
->
valuestring
,
devCode
->
valuestring
,
macstr
->
valuestring
,
&
devId
);
char
device_code
[
DEVICE_CODE_LEN
]
=
{
0
};
HAL_GetDevice_Code
(
device_code
);
int
res
=
kk_mid_subdev_add
(
KK_DM_DEVICE_GATEWAY
,
proType
->
valuestring
,
proCode
->
valuestring
,
devCode
->
valuestring
,
device_code
);
if
(
res
!=
SUCCESS_RETURN
)
{
WARNING_PRINT
(
"
dm_mgr_gw_create
error"
);
WARNING_PRINT
(
"
kk_mid_gw_add
error"
);
}
kk_ipc_send
(
IPC_MID2APP
,
szDec
,
size
);
//
kk_ipc_send(IPC_MID2APP, szDec, size);
memset
(
host_ip
,
0
,
sizeof
(
host_ip
));
memset
(
mac
,
0
,
sizeof
(
mac
));
...
...
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