shuichan_old/V1.1/STM32F103_App1/m_app/proto.h

37 lines
1.6 KiB
C
Raw Normal View History

#ifndef PROTO_H
#define PROTO_H
#include <stdint.h>
/* 轻量 JSON 取值工具:按键名定位,仅适配平台下发的扁平/一层嵌套报文。
* */
/* 定位 "key" 并返回冒号后的值起点(跳过空白),未找到返回 NULL。
* "sw2" "sw21" */
const char *proto_locate(const char *json, const char *key);
/* 取布尔值:在 key 的值区域内查找 true/false
* "key":true "key":{"time":...,"value":true} 0/1
* 1 *val1/0 0 */
int proto_get_bool(const char *json, const char *key, int *val);
/* 取无符号整数:"key":123。成功返回 1失败返回 0 */
int proto_get_u32(const char *json, const char *key, uint32_t *val);
/* 取 16 位十六进制数:"key":"1A2B" 或不带引号。成功返回 1失败返回 0 */
int proto_get_hex16(const char *json, const char *key, uint16_t *val);
/* 取字符串:"key":"xxx"。成功返回 1空串返回 0输出以 '\0' 结尾 */
int proto_get_str(const char *json, const char *key, char *out, int cap);
/* 取消息 id兼容 "id":"abc123" 与 "id":123 两种格式。
* 1 0 */
int proto_get_id(const char *json, char *out, int cap);
/* 取重量类数值,返回 0.1KG 单位:
* "key":2.0"key":"2.0""key":{"time":...,"value":2.0}
* 1 0 */
int proto_get_kg100(const char *json, const char *key, uint16_t *val);
#endif /* PROTO_H */