nRF Connect SDK API 2.8.99
Loading...
Searching...
No Matches
parser.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#include <stdint.h>
8#include <stdbool.h>
9
10#ifndef _PARSER_H_
11#define _PARSER_H_
12
13/*
14 * Maximum length of a valid SMS message is 175 bytes so we'll reserve buffer
15 * of 180 bytes to be safe and we are able to handle properly few extra bytes.
16 * 175 is result of the following calculation of maximum field lengths:
17 * 12: SMSC address
18 * 4: Misc bytes in SMS-DELIVER msg:
19 * First byte with several bit fields, TP-PID, TP-DCS, TP-UDL.
20 * 12: Originating address (phone number)
21 * 7: Timestamp
22 * 140: User data
23 */
24#define PARSER_BUF_SIZE 180
25
26/* Forward declaration of the parser struct */
27struct parser;
28
29typedef int (*parser_module)(struct parser *parser, uint8_t *buf);
30
34struct parser_api {
36 uint32_t (*data_size)(void);
38 void* (*get_parsers)(void);
40 void* (*get_decoder)(void);
42 int (*get_parser_count)(void);
44 int (*get_header)(struct parser *parser, void *header);
45};
46
55struct parser {
57 uint8_t buf_pos;
61 uint16_t buf_size;
62
64 uint8_t *payload;
68 uint8_t payload_pos;
69
71 void *data;
72
74 struct parser_api *api;
75};
76
85int parser_create(struct parser *parser, struct parser_api *api);
86
97
111int parser_process_str(struct parser *parser, const char *data);
112
124int parser_get_payload(struct parser *parser, char *buf, uint8_t buf_size);
125
137int parser_get_header(struct parser *parser, void *header);
138
139#endif /* _PARSER_H_ */
int parser_delete(struct parser *parser)
Parser instance deletion.
int parser_get_payload(struct parser *parser, char *buf, uint8_t buf_size)
Get the payload.
#define PARSER_BUF_SIZE
Definition parser.h:24
int(* parser_module)(struct parser *parser, uint8_t *buf)
Definition parser.h:29
int parser_get_header(struct parser *parser, void *header)
Get the header.
int parser_process_str(struct parser *parser, const char *data)
Parse ASCII formatted hexadecimal string.
int parser_create(struct parser *parser, struct parser_api *api)
Parser instance creation.
int(* get_header)(struct parser *parser, void *header)
Function type for getting header information.
Definition parser.h:44
uint32_t(* data_size)(void)
Function type for getting data size.
Definition parser.h:36
int(* get_parser_count)(void)
Function type for getting number of sub parsers.
Definition parser.h:42
Set of parser functions needed for parser framework to operate.
Definition parser.h:34
void * data
Data structure to hold the parsed information.
Definition parser.h:71
uint8_t payload_buf_size
Payload output buffer size.
Definition parser.h:66
uint8_t buf[180]
Parser data buffer that is processed.
Definition parser.h:59
struct parser_api * api
Functions defining the functionality of this specific parser.
Definition parser.h:74
uint8_t payload_pos
Index to the start of the payload within buf.
Definition parser.h:68
uint8_t * payload
Payload output buffer that is processed.
Definition parser.h:64
uint16_t buf_size
Size of the actual data in buf.
Definition parser.h:61
uint8_t buf_pos
Iterator type of state information on where the parsing is proceeding.
Definition parser.h:57
Set of parser variables needed for parser framework to operate.
Definition parser.h:55