-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDFRobot_SIMcore.h
193 lines (174 loc) · 4.96 KB
/
DFRobot_SIMcore.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*!
* @file DFRobot_SIMcore.h
* @brief Basic structure of DFRobot_SIMcore class
* @details A basic class library for SIM product series communication.
* @copyright Copyright (c) 2021 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [TangJie]([email protected])
* @version V1.0.1
* @date 2021-09-16
* @url https://github.com/DFRobot/DFRobot_SIM
*/
#ifndef __DFRobot_SIMCORE_H__
#define __DFRobot_SIMCORE_H__
#include <Arduino.h>
#include <stdint.h>
#include <Wire.h>
#include <stdio.h>
#include "SoftwareSerial.h"
#if 0
#define DBG(...) {Serial.print("["); Serial.print(__FUNCTION__); Serial.print("(): "); Serial.print(__LINE__); Serial.print(" ] "); Serial.println(__VA_ARGS__);}
#else
#define DBG(...)
#endif
#define DEFAULT_TIMEOUT 5 //seconds
#define DEFAULT_INTERCHAR_TIMEOUT 1500 //miliseconds
class DFRobot_SIMcore{
public:
/**
* @enum eSIMCommand_t
* @brief SIM mode select command
*/
typedef enum {
eXON,
eNONE,
eMODEMCONFIG,
eALIVETEST,
eBEGINSMS,
eENDSMS,
eAVAILABLESMS,
eFLUSHSMS,
eVOICECALL,
eANSWERCALL,
eHANGCALL,
eRETRIEVECALLINGNUMBER,
eATTACHGPRS,
eDETACHGPRS,
eCONNECTTCPCLIENT,
eDISCONNECTTCP,
eBEGINWRITESOCKET,
eENDWRITESOCKET,
eAVAILABLESOCKET,
eFLUSHSOCKET,
eCONNECTSERVER,
eGETIP,
eGETCONNECTSTATUS,
eGETLOCATION,
eGETICCID
}eSIMCommand_t;
/**
* @fn DFRobot_SIMcore
* @brief DFRobot_SIMcore constructor of abstract class. Construct serial ports.
* @param s The pointer to abstract class, where you can fill in the pointer to serial object.
*/
DFRobot_SIMcore(Stream *s);
~DFRobot_SIMcore(){};
/**
* @fn begin
* @brief Init specified module
* @return bool type, indicating initialization status
* @retval true Success
* @retval false Failed
*/
bool begin(void);
/**
* @fn checkSendCmd
* @brief Send data and judge the accuracy the returned data
* @param cmd Command to be sent
* @param resp The returned data to be judged
* @param timeout Timeout value (unit: ms)
* @return bool type, indicating the status of judging the returned data
* @retval true same
* @retval false different
*/
bool checkSendCmd(const char* cmd = NULL, const char* resp = NULL, uint32_t timeout = 1000);
/**
* @fn checkReadable
* @brief Check the number of data in serial port
* @return Return the number of data in serial port
*/
int checkReadable(void);
/**
* @fn sendCmd
* @brief Send command
* @param cmd The sent command
*/
void sendCmd(const char* cmd);
/**
* @fn sendBuff
* @brief Send data
* @param buff Data to be sent
* @param num Length of data to be sent
*/
void sendBuff(const char* buff, size_t num);
/**
* @fn sendString
* @brief Send string through serial port
* @param buff Buffer for string to be sent
*/
void sendString(const char* buff);
/**
* @fn cleanBuffer
* @brief Clear data in buffer
* @param buffer Buffer to be cleared
* @param count Length of data to be cleared
*/
void cleanBuffer(char *buffer, int count);
/**
* @fn readBuffer
* @brief Parse the data returned by the serial port
* @param buffer Buffer for data to be received
* @param count Length of data to be received
* @param timeout Timeout value (unit: ms)
* @return Receive data length
*/
uint16_t readBuffer(char *buffer = NULL, uint16_t count = 1, uint32_t timeout =1000);
/**
* @fn turnOFF
* @brief Turn off SIM7000X module
* @return bool type, indicating closing status
* @retval true Success
* @retval false Failed
*/
bool turnOFF(void);
/**
* @fn setCommandCounter
* @brief Set command counter
* @param c Command value
*/
void setCommandCounter(uint8_t c);
/**
* @fn getCommandCounter
* @brief Get command counter
* @return Command count value
*/
uint8_t getCommandCounter();
/**
* @fn get_String
* @brief Print the string returned by the serial port
*/
void get_String(void);
/**
* @fn closeCommand
* @brief Close control command
*/
void closeCommand(void);
private:
void setPhoneNumber(char *n);
char* getPhoneNumber();
void setPort(int p);
int16_t getPort(void);
void setCommandError(uint8_t n);
uint8_t getCommandError(void);
void setOngoingCommand(eSIMCommand_t c);
eSIMCommand_t getOngoingCommand(void);
void openCommand(eSIMCommand_t c);
char* _phoneNumber;
uint8_t _commandCounter;
int16_t _port;
uint8_t _commandError;
eSIMCommand_t _ongoingCommand;
Stream *_s;
long _baudrate = 19200;
};
#endif