forked from adafruit/Adafruit_FONA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdafruit_FONA.h
178 lines (146 loc) · 6.36 KB
/
Adafruit_FONA.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/***************************************************
This is a library for our Adafruit FONA Cellular Module
Designed specifically to work with the Adafruit FONA
----> http://www.adafruit.com/products/1946
----> http://www.adafruit.com/products/1963
These displays use TTL Serial to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#if (ARDUINO >= 100)
#include "Arduino.h"
#include <SoftwareSerial.h>
#else
#include "WProgram.h"
#include <NewSoftSerial.h>
#endif
//#define ADAFRUIT_FONA_DEBUG
#define FONA_HEADSETAUDIO 0
#define FONA_EXTAUDIO 1
#define FONA_STTONE_DIALTONE 1
#define FONA_STTONE_BUSY 2
#define FONA_STTONE_CONGESTION 3
#define FONA_STTONE_PATHACK 4
#define FONA_STTONE_DROPPED 5
#define FONA_STTONE_ERROR 6
#define FONA_STTONE_CALLWAIT 7
#define FONA_STTONE_RINGING 8
#define FONA_STTONE_BEEP 16
#define FONA_STTONE_POSTONE 17
#define FONA_STTONE_ERRTONE 18
#define FONA_STTONE_INDIANDIALTONE 19
#define FONA_STTONE_USADIALTONE 20
#define FONA_DEFAULT_TIMEOUT_MS 500
class Adafruit_FONA : public Stream {
public:
#if ARDUINO >= 100
Adafruit_FONA(SoftwareSerial *, int8_t r);
#else
Adafruit_FONA(NewSoftSerial *, int8_t r);
#endif
boolean begin(uint16_t baud);
// Stream
int available(void);
size_t write(uint8_t x);
int read(void);
int peek(void);
void flush();
// Battery and ADC
boolean getADCVoltage(uint16_t *v);
boolean getBattPercent(uint16_t *p);
boolean getBattVoltage(uint16_t *v);
// SIM query
uint8_t unlockSIM(char *pin);
uint8_t getSIMCCID(char *ccid);
uint8_t getNetworkStatus(void);
uint8_t getRSSI(void);
// IMEI
uint8_t getIMEI(char *imei);
// set Audio output
boolean setAudio(uint8_t a);
boolean setVolume(uint8_t i);
uint8_t getVolume(void);
boolean playToolkitTone(uint8_t t, uint16_t len);
boolean setMicVolume(uint8_t a, uint8_t level);
// FM radio functions.
boolean tuneFMradio(uint16_t station);
boolean FMradio(boolean onoff, uint8_t a = FONA_HEADSETAUDIO);
boolean setFMVolume(uint8_t i);
int8_t getFMVolume();
int8_t getFMSignalLevel(uint16_t station);
// SMS handling
int8_t getNumSMS(void);
boolean readSMS(uint8_t i, char *smsbuff, uint16_t max, uint16_t *readsize);
boolean sendSMS(char *smsaddr, char *smsmsg);
boolean deleteSMS(uint8_t i);
// Time
boolean enableNetworkTimeSync(boolean onoff);
boolean enableNTPTimeSync(boolean onoff, const __FlashStringHelper *ntpserver=0);
boolean getTime(char *buff, uint16_t maxlen);
// GPRS handling
boolean enableGPRS(boolean onoff);
uint8_t GPRSstate(void);
boolean getGSMLoc(uint16_t *replycode, char *buff, uint16_t maxlen);
void setGPRSNetworkSettings(const __FlashStringHelper *apn, const __FlashStringHelper *username=0, const __FlashStringHelper *password=0);
// HTTP
boolean HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen);
void HTTP_GET_end(void);
boolean HTTP_POST_start(char *url, const __FlashStringHelper *contenttype, const uint8_t *postdata, uint16_t postdatalen, uint16_t *status, uint16_t *datalen);
void HTTP_POST_end(void);
void setUserAgent(const __FlashStringHelper *useragent);
// HTTPS
void setHTTPSRedirect(boolean onoff);
// PWM (buzzer)
boolean PWM(uint16_t period, uint8_t duty = 50);
// Phone calls
boolean callPhone(char *phonenum);
boolean hangUp(void);
boolean pickUp(void);
boolean callerIdNotification(boolean enable, uint8_t interrupt = 0);
boolean incomingCallNumber(char* phonenum);
private:
int8_t _rstpin;
char replybuffer[255];
const __FlashStringHelper *apn;
const __FlashStringHelper *apnusername;
const __FlashStringHelper *apnpassword;
boolean httpsredirect;
const __FlashStringHelper *useragent;
// HTTP helpers
boolean HTTP_initialize(char *url);
boolean HTTP_response(uint16_t *status, uint16_t *datalen);
void HTTP_terminate(void);
void flushInput();
uint16_t readRaw(uint16_t b);
uint8_t readline(uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS, boolean multiline = false);
uint8_t getReply(char *send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
uint8_t getReply(const __FlashStringHelper *send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
uint8_t getReply(const __FlashStringHelper *prefix, char *suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
uint8_t getReply(const __FlashStringHelper *prefix, int32_t suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
uint8_t getReply(const __FlashStringHelper *prefix, int32_t suffix1, int32_t suffix2, uint16_t timeout); // Don't set default value or else function call is ambiguous.
uint8_t getReplyQuoted(const __FlashStringHelper *prefix, const __FlashStringHelper *suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReply(char *send, char *reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReply(const __FlashStringHelper *send, const __FlashStringHelper *reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReply(const __FlashStringHelper *prefix, char *suffix, const __FlashStringHelper *reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReply(const __FlashStringHelper *prefix, int32_t suffix, const __FlashStringHelper *reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReply(const __FlashStringHelper *prefix, int32_t suffix, int32_t suffix2, const __FlashStringHelper *reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReplyQuoted(const __FlashStringHelper *prefix, const __FlashStringHelper *suffix, const __FlashStringHelper *reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean parseReply(const __FlashStringHelper *toreply,
uint16_t *v, char divider = ',', uint8_t index=0);
boolean parseReply(const __FlashStringHelper *toreply,
char *v, char divider = ',', uint8_t index=0);
boolean sendParseReply(const __FlashStringHelper *tosend,
const __FlashStringHelper *toreply,
uint16_t *v, char divider = ',', uint8_t index=0);
static boolean _incomingCall;
static void onIncomingCall();
#if ARDUINO >= 100
SoftwareSerial *mySerial;
#else
NewSoftSerial *mySerial;
#endif
};