-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathTelnetClient.h
More file actions
72 lines (59 loc) · 2.26 KB
/
TelnetClient.h
File metadata and controls
72 lines (59 loc) · 2.26 KB
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
/*
* Copyright 2017 Alessio Villa
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have negotiationd a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#ifndef TELNETC_H
#define TELNETC_H
#include <Ethernet.h>
//#define TNDBG 1
//#define MT_VM 1//for me to work with a virtual machine running a mikrotik router
#ifdef TNDBG
#define DEBUG_PRINT(x) Serial.println (x)
#else
#define DEBUG_PRINT(x)
#endif
#define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
const uint8_t NEGOTIATION_DELAY = 100;
////////////////CONFIGURATION////////////////////////////////////////////////////////////////////////////////////////////////////
//how long the command sent may be long
const uint8_t MAX_OUT_BUFFER_LENGTH = 150;
//how long you'll wait for an expected answer from the server
const unsigned int LISTEN_TOUT = 5000;
//how long, after a "prompt char" is received you can confirm it's the real prompt and not just part of the server's answer
const uint16_t PROMPT_REC_TOUT = 300;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class telnetClient{
public:
telnetClient(EthernetClient& client);
bool login(IPAddress serverIpAddress, const char* username, const char* password, uint8_t port = 23);
bool sendCommand(const char* cmd);
void disconnect();
void setPromptChar(char c);
private:
EthernetClient* client;
char m_promptChar = '>';
bool send(const char* buf, bool waitEcho = true);
void negotiate();
void listen();
bool listenUntil(char c);
bool waitPrompt();
void print(char c);
};
#endif