Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
at-master.h
1
/*
2
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of the Institute nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
* SUCH DAMAGE.
28
*
29
*/
30
#ifndef AT_MASTER_H_
31
#define AT_MASTER_H_
32
#include "contiki.h"
33
/*---------------------------------------------------------------------------*/
34
#define AT_DEFAULT_RESPONSE_OK "\r\nOK\r\n"
35
#define AT_DEFAULT_RESPONSE_ERROR "\r\nERROR\r\n"
36
/*---------------------------------------------------------------------------*/
37
#define AT_RESPONSE(x) at_send((x), (strlen(x)))
38
/*---------------------------------------------------------------------------*/
39
extern
process_event_t at_cmd_received_event;
40
struct
at_cmd;
41
/*---------------------------------------------------------------------------*/
42
typedef
enum
{
43
AT_STATUS_OK,
44
AT_STATUS_ERROR,
45
AT_STATUS_INVALID_ARGS_ERROR,
46
} at_status_t;
47
/*---------------------------------------------------------------------------*/
48
/**
49
* \brief AT initialization
50
* \param uart selects which UART to use
51
*
52
* The AT driver invokes this function upon registering a command, this will
53
* wait for the serial_line_event_message event
54
*/
55
void
at_init(uint8_t uart);
56
/*---------------------------------------------------------------------------*/
57
/**
58
* \brief AT initialization
59
* \param uart selects which UART to use
60
*
61
* The AT driver invokes this function upon registering a command, this will
62
* wait for the serial_line_event_message event
63
*/
64
uint8_t at_send(
char
*s, uint8_t len);
65
/*---------------------------------------------------------------------------*/
66
/**
67
* \brief AT event callback
68
* \param cmd A pointer to the AT command placeholder
69
* \param len Lenght of the received data (including the AT command header)
70
* \param data A user-defined pointer
71
*
72
* The AT event callback function gets called whenever there is an
73
* event on an incoming AT command
74
*/
75
typedef
void (*at_event_callback_t)(
struct
at_cmd *cmd,
76
uint8_t len,
77
char
*data);
78
/*---------------------------------------------------------------------------*/
79
struct
at_cmd {
80
struct
at_cmd *next;
81
const
char
*cmd_header;
82
uint8_t cmd_hdr_len;
83
uint8_t cmd_max_len;
84
at_event_callback_t event_callback;
85
struct
process *app_process;
86
};
87
/*---------------------------------------------------------------------------*/
88
/**
89
* \brief Registers the callback to return an AT command
90
* \param cmd A pointer to the CMD placeholder
91
* \param cmd_hdr String to compare when an AT command is received
92
* \param cmd_len Lenght of cmd_hdr
93
* \param event_callback Callback function to handle the AT command
94
* \return AT_STATUS_OK or AT_STATUS_INVALID_ARGS_ERROR
95
*
96
* Register the commands to search for when a valid AT frame has been received
97
*/
98
at_status_t at_register(
struct
at_cmd *cmd,
99
struct
process *app_process,
100
const
char
*cmd_hdr,
101
const
uint8_t cmd_hdr_len,
102
const
uint8_t cmd_max_len,
103
at_event_callback_t event_callback);
104
/*---------------------------------------------------------------------------*/
105
struct
at_cmd *at_list(
void
);
106
/*---------------------------------------------------------------------------*/
107
/**
108
* \brief Registers the callback to return an AT command
109
* \param cmd A pointer to the CMD placeholder
110
* \param cmd_hdr String to compare when an AT command is received
111
* \param cmd_len Lenght of cmd_hdr
112
* \param event_callback Callback function to handle the AT command
113
* \return AT_STATUS_OK or AT_STATUS_INVALID_ARGS_ERROR
114
*
115
* Register the commands to search for when a valid AT frame has been received
116
*/
117
at_status_t at_register(
struct
at_cmd *cmd,
118
struct
process *app_process,
119
const
char
*cmd_hdr,
120
const
uint8_t cmd_hdr_len,
121
const
uint8_t cmd_max_len,
122
at_event_callback_t event_callback);
123
#endif
/* AT_MASTER_H_ */
os
services
at-master
at-master.h
Generated on
for Contiki-NG by
1.17.0