final groupe 1
GSM.h@11:79ff36296092, 2019-02-03 (annotated)
- Committer:
- GrandDiego
- Date:
- Sun Feb 03 19:36:14 2019 +0000
- Revision:
- 11:79ff36296092
- Parent:
- 10:24671d8aa0c9
final groupe 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 0:a5ae94727346 | 1 | /* |
screamer | 10:24671d8aa0c9 | 2 | GSM.h |
lawliet | 0:a5ae94727346 | 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. |
lawliet | 0:a5ae94727346 | 4 | |
lawliet | 0:a5ae94727346 | 5 | Author:lawliet.zou@gmail.com |
lawliet | 0:a5ae94727346 | 6 | 2013-11-14 |
lawliet | 0:a5ae94727346 | 7 | */ |
lawliet | 0:a5ae94727346 | 8 | |
screamer | 10:24671d8aa0c9 | 9 | #ifndef __GSM_H__ |
screamer | 10:24671d8aa0c9 | 10 | #define __GSM_H__ |
lawliet | 0:a5ae94727346 | 11 | |
lawliet | 3:48ee24a4b0f3 | 12 | #include <stdio.h> |
lawliet | 0:a5ae94727346 | 13 | #include "mbed.h" |
lawliet | 3:48ee24a4b0f3 | 14 | |
lawliet | 7:1278e9dde24e | 15 | #define DEFAULT_TIMEOUT 5 |
lawliet | 7:1278e9dde24e | 16 | #define SMS_MAX_LENGTH 16 |
lawliet | 7:1278e9dde24e | 17 | |
lawliet | 4:63a2619b423b | 18 | |
screamer | 10:24671d8aa0c9 | 19 | enum GSM_MESSAGE { |
lawliet | 4:63a2619b423b | 20 | MESSAGE_RING = 0, |
lawliet | 4:63a2619b423b | 21 | MESSAGE_SMS = 1, |
lawliet | 4:63a2619b423b | 22 | MESSAGE_ERROR |
lawliet | 4:63a2619b423b | 23 | }; |
lawliet | 4:63a2619b423b | 24 | |
lawliet | 3:48ee24a4b0f3 | 25 | |
screamer | 10:24671d8aa0c9 | 26 | /** GSM class. |
screamer | 10:24671d8aa0c9 | 27 | * Used for mobile communication. attention that GSM module communicate with MCU in serial protocol |
lawliet | 2:16985da3a446 | 28 | */ |
screamer | 10:24671d8aa0c9 | 29 | class GSM |
lawliet | 1:642a8dbe076c | 30 | { |
lawliet | 1:642a8dbe076c | 31 | public: |
screamer | 10:24671d8aa0c9 | 32 | /** Create GSM instance |
screamer | 10:24671d8aa0c9 | 33 | * @param tx uart transmit pin to communicate with GSM module |
screamer | 10:24671d8aa0c9 | 34 | * @param rx uart receive pin to communicate with GSM module |
lawliet | 2:16985da3a446 | 35 | * @param baudRate baud rate of uart communication |
lawliet | 2:16985da3a446 | 36 | * @param number default phone number during mobile communication |
lawliet | 2:16985da3a446 | 37 | */ |
screamer | 10:24671d8aa0c9 | 38 | GSM(PinName tx, PinName rx, int baudRate,char *number) : gprsSerial(tx, rx) { |
GrandDiego | 11:79ff36296092 | 39 | gprsSerial.baud(baudRate); |
GrandDiego | 11:79ff36296092 | 40 | phoneNumber = number; |
lawliet | 1:642a8dbe076c | 41 | }; |
lawliet | 7:1278e9dde24e | 42 | |
GrandDiego | 11:79ff36296092 | 43 | // Fonctions rajoutées pour le projet HAB ; |
GrandDiego | 11:79ff36296092 | 44 | void gprs_message(char * url , char * message); |
GrandDiego | 11:79ff36296092 | 45 | |
GrandDiego | 11:79ff36296092 | 46 | |
GrandDiego | 11:79ff36296092 | 47 | |
GrandDiego | 11:79ff36296092 | 48 | |
lawliet | 7:1278e9dde24e | 49 | int powerCheck(void); |
screamer | 10:24671d8aa0c9 | 50 | /** init GSM module including SIM card check & signal strength & network check |
lawliet | 2:16985da3a446 | 51 | * @returns |
screamer | 8:1ee8ba65061a | 52 | * 0 on success, |
lawliet | 2:16985da3a446 | 53 | * -1 on error |
lawliet | 2:16985da3a446 | 54 | */ |
lawliet | 1:642a8dbe076c | 55 | int init(void); |
lawliet | 2:16985da3a446 | 56 | |
screamer | 8:1ee8ba65061a | 57 | /** Check SIM card' Status |
lawliet | 4:63a2619b423b | 58 | * @returns |
screamer | 8:1ee8ba65061a | 59 | * 0 on success, |
lawliet | 4:63a2619b423b | 60 | * -1 on error |
lawliet | 4:63a2619b423b | 61 | */ |
lawliet | 4:63a2619b423b | 62 | int checkSIMStatus(void); |
lawliet | 4:63a2619b423b | 63 | |
screamer | 8:1ee8ba65061a | 64 | /** Check signal strength |
lawliet | 4:63a2619b423b | 65 | * @returns |
screamer | 8:1ee8ba65061a | 66 | * signal strength in number(ex 3,4,5,6,7,8...) on success, |
lawliet | 4:63a2619b423b | 67 | * -1 on error |
lawliet | 4:63a2619b423b | 68 | */ |
lawliet | 4:63a2619b423b | 69 | int checkSignalStrength(void); |
lawliet | 4:63a2619b423b | 70 | |
screamer | 8:1ee8ba65061a | 71 | /** Set SMS format and processing mode |
lawliet | 4:63a2619b423b | 72 | * @returns |
screamer | 8:1ee8ba65061a | 73 | * 0 on success, |
lawliet | 4:63a2619b423b | 74 | * -1 on error |
lawliet | 4:63a2619b423b | 75 | */ |
lawliet | 4:63a2619b423b | 76 | int settingSMS(void); |
lawliet | 4:63a2619b423b | 77 | |
screamer | 8:1ee8ba65061a | 78 | /** Send text SMS |
lawliet | 4:63a2619b423b | 79 | * @param *number phone number which SMS will be send to |
lawliet | 4:63a2619b423b | 80 | * @param *data message that will be send to |
lawliet | 4:63a2619b423b | 81 | * @returns |
screamer | 8:1ee8ba65061a | 82 | * 0 on success, |
lawliet | 4:63a2619b423b | 83 | * -1 on error |
lawliet | 4:63a2619b423b | 84 | */ |
lawliet | 4:63a2619b423b | 85 | int sendSMS(char *number, char *data); |
lawliet | 4:63a2619b423b | 86 | |
screamer | 8:1ee8ba65061a | 87 | /** Read SMS by index |
lawliet | 4:63a2619b423b | 88 | * @param *message buffer used to get SMS message |
screamer | 8:1ee8ba65061a | 89 | * @param index which SMS message to read |
lawliet | 4:63a2619b423b | 90 | * @returns |
screamer | 8:1ee8ba65061a | 91 | * 0 on success, |
lawliet | 4:63a2619b423b | 92 | * -1 on error |
lawliet | 4:63a2619b423b | 93 | */ |
lawliet | 4:63a2619b423b | 94 | int readSMS(char *message, int index); |
lawliet | 4:63a2619b423b | 95 | |
screamer | 8:1ee8ba65061a | 96 | /** Delete SMS message on SIM card |
lawliet | 4:63a2619b423b | 97 | * @param *index the index number which SMS message will be delete |
lawliet | 4:63a2619b423b | 98 | * @returns |
screamer | 8:1ee8ba65061a | 99 | * 0 on success, |
lawliet | 4:63a2619b423b | 100 | * -1 on error |
lawliet | 4:63a2619b423b | 101 | */ |
lawliet | 4:63a2619b423b | 102 | int deleteSMS(int index); |
lawliet | 4:63a2619b423b | 103 | |
screamer | 8:1ee8ba65061a | 104 | /** Read SMS when coming a message,it will be store in messageBuffer. |
lawliet | 4:63a2619b423b | 105 | * @param message buffer used to get SMS message |
lawliet | 4:63a2619b423b | 106 | */ |
lawliet | 4:63a2619b423b | 107 | int getSMS(char* message); |
lawliet | 4:63a2619b423b | 108 | |
screamer | 8:1ee8ba65061a | 109 | /** Call someone |
lawliet | 4:63a2619b423b | 110 | * @param *number the phone number which you want to call |
lawliet | 4:63a2619b423b | 111 | * @returns |
screamer | 8:1ee8ba65061a | 112 | * 0 on success, |
lawliet | 4:63a2619b423b | 113 | * -1 on error |
lawliet | 4:63a2619b423b | 114 | */ |
lawliet | 4:63a2619b423b | 115 | int callUp(char *number); |
lawliet | 4:63a2619b423b | 116 | |
screamer | 8:1ee8ba65061a | 117 | /** Auto answer if coming a call |
lawliet | 4:63a2619b423b | 118 | * @returns |
screamer | 8:1ee8ba65061a | 119 | * 0 on success, |
lawliet | 4:63a2619b423b | 120 | * -1 on error |
lawliet | 4:63a2619b423b | 121 | */ |
lawliet | 4:63a2619b423b | 122 | int answer(void); |
lawliet | 4:63a2619b423b | 123 | |
screamer | 8:1ee8ba65061a | 124 | /** A loop to wait for some event. if a call comes in, it will auto answer it and if a SMS message comes in, it will read the message |
lawliet | 4:63a2619b423b | 125 | * @param *check whether to check phone number when get event |
lawliet | 4:63a2619b423b | 126 | * @returns |
screamer | 8:1ee8ba65061a | 127 | * 0 on success, |
lawliet | 4:63a2619b423b | 128 | * -1 on error |
lawliet | 4:63a2619b423b | 129 | */ |
lawliet | 4:63a2619b423b | 130 | int loopHandle(void); |
lawliet | 4:63a2619b423b | 131 | |
screamer | 10:24671d8aa0c9 | 132 | /** GSM network init |
lawliet | 5:ac2342f162fa | 133 | * @param *apn Access Point Name to connect network |
lawliet | 5:ac2342f162fa | 134 | * @param *userName general is empty |
lawliet | 5:ac2342f162fa | 135 | * @param *passWord general is empty |
lawliet | 5:ac2342f162fa | 136 | */ |
screamer | 8:1ee8ba65061a | 137 | |
lawliet | 5:ac2342f162fa | 138 | int networkInit(char* apn, char* userName = NULL, char* passWord = NULL); |
screamer | 8:1ee8ba65061a | 139 | /** Build TCP connect |
lawliet | 4:63a2619b423b | 140 | * @param *ip ip address which will connect to |
lawliet | 4:63a2619b423b | 141 | * @param *port TCP server' port number |
lawliet | 4:63a2619b423b | 142 | * @returns |
screamer | 8:1ee8ba65061a | 143 | * 0 on success, |
lawliet | 4:63a2619b423b | 144 | * -1 on error |
lawliet | 4:63a2619b423b | 145 | */ |
lawliet | 4:63a2619b423b | 146 | int connectTCP(char *ip, char *port); |
lawliet | 4:63a2619b423b | 147 | |
screamer | 8:1ee8ba65061a | 148 | /** Send data to TCP server |
lawliet | 4:63a2619b423b | 149 | * @param *data data that will be send to TCP server |
lawliet | 4:63a2619b423b | 150 | * @returns |
screamer | 8:1ee8ba65061a | 151 | * 0 on success, |
lawliet | 4:63a2619b423b | 152 | * -1 on error |
lawliet | 4:63a2619b423b | 153 | */ |
lawliet | 4:63a2619b423b | 154 | int sendTCPData(char *data); |
lawliet | 4:63a2619b423b | 155 | |
screamer | 8:1ee8ba65061a | 156 | /** Close TCP connection |
lawliet | 4:63a2619b423b | 157 | * @returns |
screamer | 8:1ee8ba65061a | 158 | * 0 on success, |
lawliet | 4:63a2619b423b | 159 | * -1 on error |
lawliet | 4:63a2619b423b | 160 | */ |
lawliet | 4:63a2619b423b | 161 | int closeTCP(void); |
lawliet | 4:63a2619b423b | 162 | |
screamer | 8:1ee8ba65061a | 163 | /** Close TCP service |
lawliet | 4:63a2619b423b | 164 | * @returns |
screamer | 8:1ee8ba65061a | 165 | * 0 on success, |
lawliet | 4:63a2619b423b | 166 | * -1 on error |
lawliet | 4:63a2619b423b | 167 | */ |
lawliet | 4:63a2619b423b | 168 | int shutTCP(void); |
lawliet | 4:63a2619b423b | 169 | |
lawliet | 6:e508f9ee7922 | 170 | Serial gprsSerial; |
lawliet | 4:63a2619b423b | 171 | //USBSerial pc; |
screamer | 8:1ee8ba65061a | 172 | |
GrandDiego | 11:79ff36296092 | 173 | |
GrandDiego | 11:79ff36296092 | 174 | |
lawliet | 4:63a2619b423b | 175 | private: |
GrandDiego | 11:79ff36296092 | 176 | |
GrandDiego | 11:79ff36296092 | 177 | |
screamer | 10:24671d8aa0c9 | 178 | /** Read from GSM module and save to buffer array |
screamer | 10:24671d8aa0c9 | 179 | * @param *buffer buffer array to save what read from GSM module |
screamer | 10:24671d8aa0c9 | 180 | * @param *count the maximal bytes number read from GSM module |
lawliet | 2:16985da3a446 | 181 | * @returns |
screamer | 8:1ee8ba65061a | 182 | * 0 on success, |
lawliet | 2:16985da3a446 | 183 | * -1 on error |
lawliet | 2:16985da3a446 | 184 | */ |
lawliet | 1:642a8dbe076c | 185 | int readBuffer(char *buffer,int count); |
lawliet | 2:16985da3a446 | 186 | |
screamer | 10:24671d8aa0c9 | 187 | /** Send AT command to GSM module |
screamer | 10:24671d8aa0c9 | 188 | * @param *cmd command array which will be send to GSM module |
lawliet | 2:16985da3a446 | 189 | */ |
lawliet | 1:642a8dbe076c | 190 | void sendCmd(char *cmd); |
lawliet | 2:16985da3a446 | 191 | |
screamer | 10:24671d8aa0c9 | 192 | /** Check GSM module response before timeout |
screamer | 10:24671d8aa0c9 | 193 | * @param *resp correct response which GSM module will return |
lawliet | 2:16985da3a446 | 194 | * @param *timeout waiting seconds till timeout |
lawliet | 2:16985da3a446 | 195 | * @returns |
screamer | 8:1ee8ba65061a | 196 | * 0 on success, |
lawliet | 2:16985da3a446 | 197 | * -1 on error |
lawliet | 2:16985da3a446 | 198 | */ |
lawliet | 1:642a8dbe076c | 199 | int waitForResp(char *resp, int timeout); |
lawliet | 2:16985da3a446 | 200 | |
screamer | 10:24671d8aa0c9 | 201 | /** Send AT command to GSM module and wait for correct response |
screamer | 10:24671d8aa0c9 | 202 | * @param *cmd AT command which will be send to GSM module |
screamer | 10:24671d8aa0c9 | 203 | * @param *resp correct response which GSM module will return |
lawliet | 2:16985da3a446 | 204 | * @param *timeout waiting seconds till timeout |
lawliet | 2:16985da3a446 | 205 | * @returns |
screamer | 8:1ee8ba65061a | 206 | * 0 on success, |
lawliet | 2:16985da3a446 | 207 | * -1 on error |
lawliet | 2:16985da3a446 | 208 | */ |
lawliet | 1:642a8dbe076c | 209 | int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout); |
lawliet | 2:16985da3a446 | 210 | |
lawliet | 1:642a8dbe076c | 211 | Timer timeCnt; |
lawliet | 1:642a8dbe076c | 212 | char *phoneNumber; |
lawliet | 4:63a2619b423b | 213 | char messageBuffer[SMS_MAX_LENGTH]; |
lawliet | 0:a5ae94727346 | 214 | }; |
lawliet | 0:a5ae94727346 | 215 | |
lawliet | 0:a5ae94727346 | 216 | #endif |
lawliet | 4:63a2619b423b | 217 |