From fbbb2d0b2aba4ddc42651096b20dd4a7ca4a33f2 Mon Sep 17 00:00:00 2001 From: Guo Wenxue <guowenxue@gmail.com> Date: Wed, 21 Sep 2022 23:04:57 +0800 Subject: [PATCH] Merge branch 'master' of ssh://master.iot-yun.club:2280/raspberrypi --- apue/project_socket/src/packet.h | 27 +++++++++++++++++++-------- 1 files changed, 19 insertions(+), 8 deletions(-) diff --git a/apue/project_socket/src/packet.h b/apue/project_socket/src/packet.h index 1c18b84..d1b176e 100644 --- a/apue/project_socket/src/packet.h +++ b/apue/project_socket/src/packet.h @@ -16,15 +16,16 @@ #define _PACKET_H_ #include <stdint.h> +#include <time.h> #define DEVID_LEN 16 #define TIME_LEN 32 typedef struct pack_info_s { - char devid[DEVID_LEN]; /* device ID */ - char strtime[TIME_LEN]; /* sample time */ - uint16_t temper; /* sample temperature */ + char devid[DEVID_LEN]; /* device ID */ + struct tm sample_time; /* sample time */ + uint16_t temper; /* sample temperature */ } pack_info_t; /* packet function pointer type */ @@ -39,13 +40,12 @@ */ extern int get_devid(char *devid, int size, int sn); -/* description: get current system in format "YYYY-MM-DD HH:MM:SS" +/* description: get current system in struct tm * input args: - * $strtime: time string output buf - * $size : time string output buffer size + * $sample_time: sample time in struct tm * return value: <0: failure 0:ok */ -extern int get_time(char *strtime, int size); +extern int get_time(struct tm *sample_time); /* description: package a string packet in format "devid|time|temper" * input args: @@ -54,6 +54,17 @@ * $size : packet output buffer size * return value: <0: failure >0: packet bytes */ -extern int packet_string_pack(pack_info_t *pack_info, char *pack_buf, int size); +extern int packet_segmented_pack(pack_info_t *pack_info, char *pack_buf, int size); + + +/* description: package a json string packet: {"devid":"xxx", "time":"xxx", "temperature":"xxx"} + * input args: + * $pack_info: packet data contains devid, time and temperature + * $pack_buf : packet output buffer + * $size : packet output buffer size + * return value: <0: failure >0: packet bytes + */ +extern int packet_json_pack(pack_info_t *pack_info, char *pack_buf, int size); + #endif /* ----- #ifndef _PACKET_H_ ----- */ -- Gitblit v1.9.1