Guo Wenxue
2022-09-22 732d1963ed83abf4e5f1b06ec451a6943421d716
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_  ----- */