commit | author | age
|
29b331
|
1 |
/******************************************************************************** |
GW |
2 |
* Copyright: (C) 2022 LingYun IoT System Studio |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* Filename: packet.h |
|
6 |
* Description: This head file is packet API functions. |
|
7 |
* |
|
8 |
* Version: 1.0.0(18/04/22) |
|
9 |
* Author: Guo Wenxue <guowenxue@gmail.com> |
|
10 |
* ChangeLog: 1, Release initial version on "18/04/22 16:24:40" |
|
11 |
* |
|
12 |
********************************************************************************/ |
|
13 |
|
|
14 |
|
|
15 |
#ifndef _PACKET_H_ |
|
16 |
#define _PACKET_H_ |
|
17 |
|
|
18 |
#include <stdint.h> |
|
19 |
#include <time.h> |
|
20 |
|
|
21 |
#define DEVID_LEN 16 |
|
22 |
#define TIME_LEN 32 |
|
23 |
|
|
24 |
typedef struct pack_info_s |
|
25 |
{ |
|
26 |
char devid[DEVID_LEN]; /* device ID */ |
|
27 |
struct tm sample_time; /* sample time */ |
|
28 |
float temper; /* sample temperature */ |
|
29 |
} pack_info_t; |
|
30 |
|
|
31 |
/* packet function pointer type */ |
|
32 |
typedef int (* pack_proc_t)(pack_info_t *pack_info, char *pack_buf, int size); |
|
33 |
|
|
34 |
/* description: get device ID |
|
35 |
* input args: |
|
36 |
* $devid : device ID string |
|
37 |
* $size : device ID output buffer size |
|
38 |
* $sn : serial number |
|
39 |
* return value: <0: failure 0:ok |
|
40 |
*/ |
|
41 |
extern int get_devid(char *devid, int size, int sn); |
|
42 |
|
|
43 |
/* description: get current system in struct tm |
|
44 |
* input args: |
|
45 |
* $sample_time: sample time in struct tm |
|
46 |
* return value: <0: failure 0:ok |
|
47 |
*/ |
|
48 |
extern int get_time(struct tm *sample_time); |
|
49 |
|
|
50 |
/* description: package a string packet in format "devid|time|temper" |
|
51 |
* input args: |
|
52 |
* $pack_info: packet data contains devid, time and temperature |
|
53 |
* $pack_buf : packet output buffer |
|
54 |
* $size : packet output buffer size |
|
55 |
* return value: <0: failure >0: packet bytes |
|
56 |
*/ |
|
57 |
extern int packet_segmented_pack(pack_info_t *pack_info, char *pack_buf, int size); |
|
58 |
|
|
59 |
|
|
60 |
/* description: package a json string packet: {"devid":"xxx", "time":"xxx", "temperature":"xxx"} |
|
61 |
* input args: |
|
62 |
* $pack_info: packet data contains devid, time and temperature |
|
63 |
* $pack_buf : packet output buffer |
|
64 |
* $size : packet output buffer size |
|
65 |
* return value: <0: failure >0: packet bytes |
|
66 |
*/ |
|
67 |
extern int packet_json_pack(pack_info_t *pack_info, char *pack_buf, int size); |
|
68 |
|
|
69 |
|
|
70 |
#endif /* ----- #ifndef _PACKET_H_ ----- */ |