forked from plbyrd/hayesduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModemBase.h
178 lines (153 loc) · 4.63 KB
/
ModemBase.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
/***********************************************
HAYESDUINO PROJECT - COPYRIGHT 2013, PAYTON BYRD
Project homepage: http://hayesduino.codeplex.com
License: http://hayesduino.codeplex.com/license
***********************************************/
#include "HardwareSerial.h"
#ifdef UBRR1H
#define __MEGA__
#define POWER_LED 29
#else
#define __UNO__
#endif
#ifndef _MODEMBASE_h
#define _MODEMBASE_h
#include <Stream.h>
#include <SD.h>
#include "EthernetClient.h"
#include "Arduino.h"
#include "DEBUG.h"
#include "Global.h"
#define STATUS_LED 8
#ifdef __UNO__
#define DTE_RTS 2 // Orange
#define DCE_CTS 2
#define DTE_DTR 7 // White/Green
#define DCE_DCD 7
#define DCE_RI 4 // White/Brown
#define DTE_DCD 5 // Brown
#define DCE_DTR 5
#define DTE_CTS 6 // White/Orange
#define DCE_RTS 6
#define DTE_DSR 3 // White/Blue
#define TxD 0 // Blue
#define RxD 1 // Green
#else
// MEGA
#define DTE_RTS 22 // Orange
#define DCE_CTS 22
#define DTE_DTR 23 // White/Green
#define DCE_DCD 23
#define DCE_RI 24 // White/Brown
#define DTE_DCD 25 // Brown
#define DCE_DTR 25
#define DTE_CTS 27 // White/Orange
#define DCE_RTS 27
#define DTE_DSR 29 // White/Blue
#define TxD 18 // Blue
#define RxD 19 // Green
//#define DTE_RTS 2 // Orange
//#define DCE_CTS 2
//#define DTE_DTR 7 // White/Green
//#define DCE_DCD 7
//#define DCE_RI 4 // White/Brown
//#define DTE_DCD 5 // Brown
//#define DCE_DTR 5
//#define DTE_CTS 6 // White/Orange
//#define DCE_RTS 6
//#define DTE_DSR 3 // White/Blue
//#define TxD 19 // Blue
//#define RxD 18 // Green
#endif
class ModemBase : public Stream
{
private:
int _escapeCount;
char _lastCommandBuffer[81];
char _commandBuffer[81];
HardwareSerial* _serial;
uint32_t _baudRate;
bool _isCommandMode;
bool _isConnected;
bool _isRinging;
uint8_t _isDcdInverted;
bool _echoOn;
bool _verboseResponses;
bool _quietMode;
bool _S0_autoAnswer; // Default false
uint8_t _S1_ringCounter; // Default 0
uint8_t _S2_escapeCharacter; // Default 43
uint8_t _S3_crCharacter; // Default 13
uint8_t _S4_lfCharacter; // Default 10
uint8_t _S5_bsCharacter; // Default 8
uint8_t _S6_waitBlindDial; // Default 2 seconds
uint8_t _S7_waitForCarrier; // Default 50 seconds
uint8_t _S8_pauseForComma; // Default 2 seconds
uint8_t _S9_cdResponseTime; // Default 6 (0.6 seconds)
uint8_t _S10_delayHangup; // Default 14 (1.4 seconds)
uint8_t _S11_dtmf; // Default 95 miliseconds
uint8_t _S12_escGuardTime; // Default 50 (1.0 second)
uint8_t _S18_testTimer; // Default 0 seconds
uint8_t _S25_delayDTR; // Default 5
uint8_t _S26_delayRTS2CTS; // Default 5 miliseconds
uint8_t _S30_inactivityTimer; // Default 0 (disable)
uint8_t _S37_lineSpeed; // Default 0 (auto)
uint8_t _S38_delayForced; // Default 20 seconds
/*
S37 Command options:
0 Attempt auto mode connection
1 Attempt to connect at 300 bit/s
2 Attempt to connect at 300 bit/s
3 Attempt to connect at 300 bit/s
5 Attempt to connect at 1200 bit/s
6 Attempt to connect at 2400 bit/s
7 Attempt to connect in V.23 75/1200 mode.
8 Attempt to connect at 9600 bit/s
9 Attempt to connect at 12000 bit/s
10 Attempt to connect at 14400 bit/s
*/
void resetCommandBuffer(bool);
void (*onDisconnect)(EthernetClient *client);
void (*onDialout)(char*, ModemBase*);
void setLineSpeed(void);
void loadDefaults(void);
void saveDefaults(void);
void writeAddressBook(uint16_t, char *);
char* getAddressBook(uint16_t);
#ifndef __UNO__
bool processCommandBufferExtended(EthernetClient *client);
#endif
void printOK(void);
void printResponse(const char* code, const char* msg);
void printResponse(const char* code, const __FlashStringHelper * msg);
int getString(EthernetClient *client, char *buffer, int maxLength);
public:
ModemBase();
void begin(
HardwareSerial *serial,
void (*onDisconnectHandler)(EthernetClient *client),
void (*onDialoutHandler)(char*, ModemBase*));
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual size_t write(uint8_t);
void factoryReset(void);
uint32_t getBaudRate(void);
void setDefaultBaud(uint32_t baudRate);
void setDcdInverted(char isInverted);
bool getDcdInverted(void);
bool getIsConnected(void);
bool getIsRinging(void);
void setIsRinging(bool);
bool getIsCommandMode(void);
int toggleCarrier(boolean isHigh);
void disconnect(EthernetClient *client);
void connect(EthernetClient *client);
void connectOut(void);
void processCommandBuffer(EthernetClient *client);
void processData(EthernetClient *client, File *myLogFile);
void resetToDefaults(void);
using Print::write;
};
#endif