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
09a5546a
Commit
09a5546a
authored
Jul 15, 2021
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】1,增加PowerSwitch与epNum的处理
【提交人】陈伟灿
parent
8fcfbe3a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
9 deletions
+65
-9
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+59
-5
application/kcloud/kk_register.c
application/kcloud/kk_register.c
+2
-0
application/kcloud/kk_topic_mng.c
application/kcloud/kk_topic_mng.c
+4
-4
No files found.
application/kcloud/kcloud_data_handle.c
View file @
09a5546a
...
...
@@ -51,7 +51,7 @@ const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"
#define KK_POWER_SWITCH_1 "PowerSwitch_1"
#define KK_POWER_SWITCH_2 "PowerSwitch_2"
#define KK_POWER_SWITCH_3 "PowerSwitch_3"
#define KK_POWER_SWITCH_4 "PowerSwitch_4"
extern
char
*
KK_Make_Topic
(
cJSON
*
info
);
extern
int
KK_Subdev_UnSubscribe
(
cJSON
*
payload
);
extern
int
KK_Subdev_UnSubscribe_By_DeviceCode
(
const
char
*
deviceCode
,
const
char
*
productCode
);
...
...
@@ -67,6 +67,7 @@ static char *s_split_product[] = {
"3024"
//肖邦系列三路面板
};
static
int
kk_utils_memtok
(
_IN_
char
*
input
,
_IN_
int
input_len
,
_IN_
char
delimiter
,
_IN_
int
index
,
_OU_
int
*
offset
)
{
int
item_index
=
0
;
...
...
@@ -134,6 +135,7 @@ static int kk_split_send_data(cJSON *pData,const char* topic)
cJSON
*
powerswitch1
=
NULL
;
cJSON
*
powerswitch2
=
NULL
;
cJSON
*
powerswitch3
=
NULL
;
cJSON
*
powerswitch4
=
NULL
;
if
(
pData
==
NULL
){
return
RETURN_FAIL
;
}
...
...
@@ -146,7 +148,8 @@ static int kk_split_send_data(cJSON *pData,const char* topic)
if
(
powerswitch1
!=
NULL
){
cJSON_DeleteItemFromObject
(
pData
,
MSG_PARAMS_STR
);
cJSON
*
pParam_new
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pParam_new
,
KK_POWER_SWITCH_1
,
powerswitch1
->
valueint
);
cJSON_AddNumberToObject
(
pParam_new
,
"PowerSwitch"
,
powerswitch1
->
valueint
);
cJSON_AddStringToObject
(
pParam_new
,
"epNum"
,
"1"
);
cJSON_AddItemToObject
(
pData
,
MSG_PARAMS_STR
,
pParam_new
);
char
*
out
=
cJSON_Print
(
pData
);
KK_MQTT_SendMsg
((
char
*
)
topic
,(
const
char
*
)
out
);
...
...
@@ -158,7 +161,8 @@ static int kk_split_send_data(cJSON *pData,const char* topic)
if
(
powerswitch2
!=
NULL
){
cJSON_DeleteItemFromObject
(
pData
,
MSG_PARAMS_STR
);
pParam_new
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pParam_new
,
KK_POWER_SWITCH_2
,
powerswitch2
->
valueint
);
cJSON_AddNumberToObject
(
pParam_new
,
"PowerSwitch"
,
powerswitch2
->
valueint
);
cJSON_AddStringToObject
(
pParam_new
,
"epNum"
,
"2"
);
cJSON_AddItemToObject
(
pData
,
MSG_PARAMS_STR
,
pParam_new
);
char
*
out
=
cJSON_Print
(
pData
);
KK_MQTT_SendMsg
((
char
*
)
topic
,(
const
char
*
)
out
);
...
...
@@ -168,7 +172,19 @@ static int kk_split_send_data(cJSON *pData,const char* topic)
if
(
powerswitch3
!=
NULL
){
cJSON_DeleteItemFromObject
(
pData
,
MSG_PARAMS_STR
);
pParam_new
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pParam_new
,
KK_POWER_SWITCH_3
,
powerswitch3
->
valueint
);
cJSON_AddNumberToObject
(
pParam_new
,
"PowerSwitch"
,
powerswitch3
->
valueint
);
cJSON_AddStringToObject
(
pParam_new
,
"epNum"
,
"3"
);
cJSON_AddItemToObject
(
pData
,
MSG_PARAMS_STR
,
pParam_new
);
char
*
out
=
cJSON_Print
(
pData
);
KK_MQTT_SendMsg
((
char
*
)
topic
,(
const
char
*
)
out
);
free
(
out
);
}
powerswitch4
=
cJSON_GetObjectItem
(
pParam
,
KK_POWER_SWITCH_4
);
if
(
powerswitch4
!=
NULL
){
cJSON_DeleteItemFromObject
(
pData
,
MSG_PARAMS_STR
);
pParam_new
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pParam_new
,
"PowerSwitch"
,
powerswitch4
->
valueint
);
cJSON_AddStringToObject
(
pParam_new
,
"epNum"
,
"4"
);
cJSON_AddItemToObject
(
pData
,
MSG_PARAMS_STR
,
pParam_new
);
char
*
out
=
cJSON_Print
(
pData
);
KK_MQTT_SendMsg
((
char
*
)
topic
,(
const
char
*
)
out
);
...
...
@@ -248,6 +264,26 @@ int _kk_sendto_cloud(cJSON *root)
kk_split_send_data
(
pData
,
topic
);
}
else
{
cJSON
*
pParam
=
NULL
;
cJSON
*
PowerSwitch
=
NULL
;
int
i
=
0
;
int
tmpPS
[
32
]
=
{
0
};
int
tmpIdx
[
4
]
=
{
0
};
pParam
=
cJSON_GetObjectItem
(
pData
,
MSG_PARAMS_STR
);
if
(
pParam
==
NULL
){
return
RETURN_FAIL
;
}
for
(
i
=
0
;
i
<
64
;
i
++
){
sprintf
(
tmpPS
,
"PowerSwitch_%d"
,
i
);
PowerSwitch
=
cJSON_GetObjectItem
(
pParam
,
tmpPS
);
if
(
PowerSwitch
!=
NULL
){
cJSON_DeleteItemFromObject
(
pParam
,
tmpPS
);
sprintf
(
tmpIdx
,
"%d"
,
i
);
cJSON_AddNumberToObject
(
pParam
,
"PowerSwitch"
,
PowerSwitch
->
valueint
);
cJSON_AddStringToObject
(
pParam
,
"epNum"
,
tmpIdx
);
break
;
}
}
char
*
out
=
cJSON_Print
(
pData
);
KK_MQTT_SendMsg
(
topic
,(
const
char
*
)
out
);
free
(
out
);
...
...
@@ -471,12 +507,29 @@ static char * _kk_data_create(const char *topic,const char *data)
free
(
msgStr
);
return
NULL
;
}
memset
(
infoStr
,
0x0
,
infoStr_len
);
snprintf
(
infoStr
,
infoStr_len
,
DM_MSG_TO_MIDDWARE
,
msgStr
,
productCode
,
deviceCode
);
root
=
cJSON_CreateObject
();
cJSON
*
infoObj
=
cJSON_Parse
(
infoStr
);
cJSON
*
payloadObj
=
cJSON_Parse
(
data
);
#if 1
cJSON
*
params
=
cJSON_GetObjectItem
(
payloadObj
,
"params"
);
if
(
params
!=
NULL
){
cJSON
*
PowerSwitch
=
cJSON_GetObjectItem
(
params
,
"PowerSwitch"
);
cJSON
*
epNUm
=
cJSON_GetObjectItem
(
params
,
"epNUm"
);
if
(
PowerSwitch
!=
NULL
&&
epNUm
!=
NULL
){
char
tmpPS
[
32
]
=
{
0
};
strcat
(
tmpPS
,
"PowerSwitch"
);
strcat
(
tmpPS
,
"_"
);
strcat
(
tmpPS
,
epNUm
->
valuestring
);
cJSON_AddNumberToObject
(
params
,
tmpPS
,
PowerSwitch
->
valueint
);
cJSON_DeleteItemFromObject
(
params
,
"PowerSwitch"
);
cJSON_DeleteItemFromObject
(
params
,
"epNUm"
);
}
}
#endif
cJSON_AddItemToObject
(
root
,
MSG_INFO_STR
,
infoObj
);
cJSON_AddItemToObject
(
root
,
MSG_PAYLOAD_STR
,
payloadObj
);
if
(
strstr
(
topic
,
KK_TOPO_CHANGE_MSG_STR
)){
...
...
@@ -559,6 +612,7 @@ void KK_Sendto_DevData(const char *topic,const char *data)
return
;
//ingore the message
}
INFO_PRINT
(
"[%s][%d]receive from cloud,topic:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
INFO_PRINT
(
"[%s][%d]receive from cloud,data:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
data
);
char
*
send_data
=
_kk_data_create
(
topic
,
data
);
if
(
send_data
==
NULL
){
return
;
...
...
application/kcloud/kk_register.c
View file @
09a5546a
...
...
@@ -315,11 +315,13 @@ int kk_start_ccu_register(void)
if
(
inet_pton
(
AF_INET
,
IPSTR
,
&
servaddr
.
sin_addr
)
<=
0
){
printf
(
"--inet_pton error!
\n
"
);
close
(
sockfd
);
return
-
1
;
};
if
(
connect
(
sockfd
,
(
struct
sockaddr
*
)
&
servaddr
,
sizeof
(
servaddr
))
<
0
){
printf
(
"connect error!
\n
"
);
close
(
sockfd
);
return
-
1
;
}
printf
(
"connect successful
\n
"
);
...
...
application/kcloud/kk_topic_mng.c
View file @
09a5546a
...
...
@@ -9,10 +9,10 @@
#include "kk_hal.h"
#include "mqtt_api.h"
const
char
KK_URI_SYS_PREFIX
[]
=
"biz/kk/%s/%s/thing/service/property/set"
;
const
char
KK_URI_SYS_PREFIX_SERVICE
[]
=
"biz/kk/%s/%s/thing/service/+"
;
const
char
KK_URI_SYS_PREFIX_TOPO_CHANGE
[]
=
"biz/kk/%s/%s/thing/topo/change"
;
const
char
KK_URI_SYS_PREFIX_EX
[]
=
"biz/kk/%s/%s"
;
const
char
KK_URI_SYS_PREFIX
[]
=
"biz/
new
kk/%s/%s/thing/service/property/set"
;
const
char
KK_URI_SYS_PREFIX_SERVICE
[]
=
"biz/
new
kk/%s/%s/thing/service/+"
;
const
char
KK_URI_SYS_PREFIX_TOPO_CHANGE
[]
=
"biz/
new
kk/%s/%s/thing/topo/change"
;
const
char
KK_URI_SYS_PREFIX_EX
[]
=
"biz/
new
kk/%s/%s"
;
const
char
KK_URI_OTA_PREFIX
[]
=
"ota/device/%s/%s/upgrade"
;
const
char
KK_URI_OTA_PROCESS
[]
=
"/ota/device/progress/%s/%s"
;
const
char
KK_URI_OTA_INFORM
[]
=
"/ota/device/inform/%s/%s"
;
...
...
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