GuoWenxue
2022-04-29 47579e3790b1ee5a1ad2ce35ea6028cd9ddf6ea0
apue/project_socket/src/packet.c
@@ -4,11 +4,11 @@
 *
 *       Filename:  packet.c
 *    Description:  This file is packet API functions
 *
 *
 *        Version:  1.0.0(18/04/22)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "18/04/22 16:30:25"
 *
 *
 ********************************************************************************/
#include <stdio.h>
@@ -43,14 +43,14 @@
      return -1;
   }
   snprintf(strtime, size, "%04d-%02d-%2d %02d:%02d:%02d",
   snprintf(strtime, size, "%04d-%02d-%2d %02d:%02d:%02d",
         tnow->tm_year+1900, tnow->tm_mon+1, tnow->tm_mday,
         tnow->tm_hour, tnow->tm_min, tnow->tm_sec);
   return 0;
}
int packet_string_pack(pack_info_t *pack_info, char *pack_buf, int size)
int packet_segmented_pack(pack_info_t *pack_info, char *pack_buf, int size)
{
   if( !pack_info || !pack_buf || size<=0 )
   {
@@ -58,10 +58,29 @@
      return -1;
   }
   snprintf(pack_buf, size, "%s|%s|%d.%d", pack_info->devid, pack_info->strtime,
    memset(pack_buf, 0, size);
   snprintf(pack_buf, size, "%s|%s|%d.%d", pack_info->devid, pack_info->strtime,
         temper_integer(pack_info->temper), temper_fract(pack_info->temper));
   return strlen(pack_buf);
}
int packet_json_pack(pack_info_t *pack_info, char *pack_buf, int size)
{
   if( !pack_info || !pack_buf || size<=0 )
   {
      log_error("Invalid input arguments\n");
      return -1;
   }
    memset(pack_buf, 0, size);
   snprintf(pack_buf, size, "{\"devid\":\"%s\", \"time\":\"%s\",\"temperature\":\"%d.%d\"}",
            pack_info->devid, pack_info->strtime,
            temper_integer(pack_info->temper), temper_fract(pack_info->temper));
   return strlen(pack_buf);
}