RUI3 (RAK Unified Interface 3) - RAK4631
service_mode_proto.h
Go to the documentation of this file.
1 #ifndef __SERVICE_MODE_PROTO_H__
2 #define __SERVICE_MODE_PROTO_H__
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 //standard libary include
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include <stdbool.h>
13 #include "udrv_serial.h"
14 
15 //#define PROTO_BUFFER_SIZE (65536)
16 #define PROTO_BUFFER_SIZE (256)//FIXME: (65536 is too big for RAM consumption!)
17 #define PROTO_START_DELIMITER 0x7E
18 #define PROTO_UPPER_LAYER_NUM_MAX 256
19 
20 #define PROTO_PKT_TIMEOUT (3000)
21 
22 #define PROTO_USE_POPCOUNT_CHKSUM
23 
24 typedef void (*SERVICE_MODE_PROTOCOL_HANDLER) (int, uint8_t *, uint16_t);
25 
27 {
31 
32 typedef enum _PROTO_STATE{
40 #ifdef PROTO_USE_POPCOUNT_CHKSUM
42 #else
43  PROTO_STATE_RECV_CRC_1 = 8,
44  PROTO_STATE_RECV_CRC_2 = 9,
45  PROTO_STATE_RECV_CRC_3 = 10,
46  PROTO_STATE_RECV_CRC_4 = 11,
47 #endif
51 
52 typedef enum _PROTO_EVENT{
57 
58 typedef PROTO_STATE (*proto_event_handler)(SERIAL_PORT port, PROTO_STATE state, uint8_t ch);
59 
60 #define PROTO_FLAG_RESPONSE 0x01
61 
62 typedef struct proto_packet_header_{
63  uint8_t start_delimiter;
64  uint16_t length;
65  uint8_t frame_type;
66  uint8_t flag;
67 } __attribute__ ((packed)) proto_packet_header;
68 
69 typedef struct proto_packet_tailer_{
70 #ifdef PROTO_USE_POPCOUNT_CHKSUM
71  uint8_t chksum;
72 #else
73  uint32_t crc;
74 #endif
75 } __attribute__ ((packed)) proto_packet_tailer;
76 
77 void service_mode_proto_recv(SERIAL_PORT port, uint8_t ch);
78 void service_mode_proto_send(SERIAL_PORT port, uint8_t flag, uint8_t frame_type, uint8_t *payload, uint16_t length, SERVICE_MODE_PROTOCOL_HANDLER response_handler);
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #endif /* __SERVICE_MODE_PROTO_H__ */
89 
uint16_t length
Definition: service_mode_proto.h:60
Definition: service_mode_proto.h:26
Definition: service_mode_proto.h:69
SERVICE_MODE_PROTOCOL_HANDLER request_handler
Definition: service_mode_proto.h:28
uint16_t length
Definition: service_mode_proto.h:64
Definition: service_mode_proto.h:35
uint8_t frame_type
Definition: service_mode_proto.h:65
Definition: service_mode_proto.h:38
uint8_t start_delimiter
Definition: service_mode_proto.h:63
Definition: service_mode_proto.h:39
Definition: service_mode_proto.h:33
SERVICE_MODE_PROTOCOL_HANDLER response_handler
Definition: service_mode_proto.h:29
void service_mode_proto_deinit(SERIAL_PORT port)
enum _PROTO_EVENT PROTO_EVENT
void service_mode_proto_init(SERIAL_PORT port)
uint8_t chksum
Definition: service_mode_proto.h:71
Definition: service_mode_proto.h:41
int32_t service_mode_proto_register(uint8_t frame_type, SERVICE_MODE_PROTOCOL_HANDLER request_handler)
struct _proto_upper_layer_info proto_upper_layer_info
uint8_t flag
Definition: service_mode_proto.h:66
int32_t service_mode_proto_deregister(uint8_t frame_type)
_PROTO_STATE
Definition: service_mode_proto.h:32
Definition: service_mode_proto.h:48
Provide a hardware independent serial driver layer for API layer to use.
PROTO_STATE(* proto_event_handler)(SERIAL_PORT port, PROTO_STATE state, uint8_t ch)
Definition: service_mode_proto.h:58
Definition: service_mode_proto.h:37
Definition: service_mode_proto.h:53
Definition: service_mode_proto.h:36
void service_mode_proto_recv(SERIAL_PORT port, uint8_t ch)
Definition: service_mode_proto.h:54
Definition: service_mode_proto.h:62
void service_mode_proto_send(SERIAL_PORT port, uint8_t flag, uint8_t frame_type, uint8_t *payload, uint16_t length, SERVICE_MODE_PROTOCOL_HANDLER response_handler)
Definition: service_mode_proto.h:55
void(* SERVICE_MODE_PROTOCOL_HANDLER)(int, uint8_t *, uint16_t)
Definition: service_mode_proto.h:24
Definition: service_mode_proto.h:49
uint8_t frame_type
Definition: service_mode_proto.h:61
uint8_t flag
Definition: service_mode_proto.h:62
Definition: service_mode_proto.h:34
struct proto_packet_header_ __attribute__((packed)) proto_packet_header
enum _SERIAL_PORT SERIAL_PORT
enum _PROTO_STATE PROTO_STATE
_PROTO_EVENT
Definition: service_mode_proto.h:52