-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSIM800Module.h
164 lines (110 loc) · 2.84 KB
/
SIM800Module.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
/*
* SIM800Module.h
*
* Created on: 8 août 2015
* Author: horfee
*/
#ifndef SIM800MODULE_H_
#define SIM800MODULE_H_
#include <string>
#include <exception>
#include <vector>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <ctime>
#include <atomic>
namespace alarmpi {
class SIM800ModuleListener {
public:
virtual void onMessageReceived(int messageId) = 0;
virtual void onIncomingCall(std::string callingNumber) = 0;
virtual ~SIM800ModuleListener() {} ;
};
class SIM800UARTException: public std::exception {};
class SIM800Exception: public std::exception {};
class SIM800TransmitException: public std::exception {};
class SIM800ReceiveException: public std::exception {};
typedef struct {
short rssi;
float bitErrorRate;
} SignalQuality;
typedef struct {
std::string text;
int status;
} SIM800Command;
typedef enum {
READ = 1,
UNREAD = 2,
SENT = 3,
UNSENT = 4,
INBOX = 5,
ALL = 6
} SMSStatus;
typedef struct {
int msgId;
std::string phoneNumber;
time_t timestamp;
std::string text;
SMSStatus status;
} SMS;
class SIM800Module {
public:
SIM800Module(int resetPin, std::string uartStream, int baudrate);
virtual ~SIM800Module();
void reset();
// void sleep();
//
// void wakeUp();
void addListener(SIM800ModuleListener *listener);
void removeListener(SIM800ModuleListener *listener);
bool callPhone(std::string numberPhone);
void hangUp();
int sendMessage(std::string numberPhone, std::string message);
int sendUnicodeMessage(std::string numberPhone, std::string message);
std::string getModuleVersion();
std::string getIMEI();
bool isReady();
int getNetworkStatus();
SignalQuality getSignalQuality();
std::string getOperator();
std::vector<std::string> listOperators();
bool needPinCode();
void setPinCode(std::string pinCode);
bool isCallingPhone();
void answerIncommingCall();
void toggleDisplayCalleeNumber(); //AT+CLIP=0|1
void toggleBusy();
std::vector<SMS> listSMS(SMSStatus status);
void deleteSMS(int msgId); //AT+CMGD
void deleteSMS(SMSStatus status); // AT+CMGDA="DEL <TYPE>"
bool getClipStatus();
SMS getSms(int msgId);
private:
bool callingPhone;
std::thread* deamon;
std::thread* unattendedCommands;
std::vector<SIM800ModuleListener*> listeners;
//#if defined(RPI) and defined(WIRINGPI)
int simUARTFileStream = 0;
//#endif
std::atomic<bool> stop;
#ifdef RPI
int resetPin;
#endif
//#if defined(RPI) and !defined(WIRINGPI)
// int pi;
//#endif
void receivingThreadCallBack();
void unattendCommandsCallBack();
void sendCommand(std::string command, bool includeRF = true);
SIM800Command readCommand(std::string awaitedCommand);
std::vector<std::string> readCommands;
std::mutex mutex;
std::mutex sendingMutex;
// std::mutex sendingMessageMutex;
std::condition_variable condition;
bool clipFlag;
};
} /* namespace alarmpi */
#endif /* SIM800MODULE_H_ */