|
@@ -667,6 +667,55 @@ char *makeJson_C01_Warn(uint16_t code,double process)
|
|
|
return w;
|
|
return w;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * @brief 创建JSON-RPC 2.0请求字符串
|
|
|
|
|
+ * @param method 方法名(必须)
|
|
|
|
|
+ * @param params 参数对象(可选)
|
|
|
|
|
+ * @param id 请求ID(可选,NULL表示通知)
|
|
|
|
|
+ * @return 返回JSON字符串,需要调用者释放,失败返回NULL
|
|
|
|
|
+ */
|
|
|
|
|
+char* makeJsonRpc2_0(const char* method, cJSON* params, int id)
|
|
|
|
|
+{
|
|
|
|
|
+ // 参数检查
|
|
|
|
|
+ if (method == NULL || method[0] == '\0') {
|
|
|
|
|
+ fprintf(stderr, "Error: method cannot be NULL or empty\n");
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ cJSON* root = cJSON_CreateObject();
|
|
|
|
|
+ if (root == NULL) {
|
|
|
|
|
+ fprintf(stderr, "Error: Failed to create JSON object\n");
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 添加 jsonrpc 版本
|
|
|
|
|
+ if (!cJSON_AddStringToObject(root, "jsonrpc", "2.0")) {
|
|
|
|
|
+ cJSON_Delete(root);
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 添加 method
|
|
|
|
|
+ if (!cJSON_AddStringToObject(root, "method", method)) {
|
|
|
|
|
+ cJSON_Delete(root);
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 添加 params(如果有)
|
|
|
|
|
+ if (params != NULL) {
|
|
|
|
|
+ // 注意:这里不复制params,调用者需要保证params在函数调用期间有效
|
|
|
|
|
+ cJSON_AddItemToObject(root, "params", params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ cJSON_AddNumberToObject(root, "id", id);
|
|
|
|
|
+ // 生成JSON字符串
|
|
|
|
|
+ char* json_str = cJSON_PrintUnformatted(root);
|
|
|
|
|
+
|
|
|
|
|
+ // 清理
|
|
|
|
|
+ cJSON_Delete(root);
|
|
|
|
|
+
|
|
|
|
|
+ return json_str;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/*生成JSON数据*/
|
|
/*生成JSON数据*/
|
|
|
char * makeJson()
|
|
char * makeJson()
|
|
|
{
|
|
{
|
|
@@ -760,6 +809,7 @@ char * makeJson()
|
|
|
}
|
|
}
|
|
|
if(device_status.all_ycct==0&&device_status.gaoya_count!=0)
|
|
if(device_status.all_ycct==0&&device_status.gaoya_count!=0)
|
|
|
{
|
|
{
|
|
|
|
|
+ if(device_status.gaoya_count>=10) device_status.gaoya_count = device_status.gaoya_count/10;
|
|
|
device_status.all_ycct = device_status.gaoya_count;
|
|
device_status.all_ycct = device_status.gaoya_count;
|
|
|
device_status.gaoya_count = 0;
|
|
device_status.gaoya_count = 0;
|
|
|
}
|
|
}
|