Code Monkey home page Code Monkey logo

telnetserial's Introduction

TelnetSerial: A Serial + Telnet console class.

Extends Print class allowing Serial-like I/O to the serial port and/or a Telnet connection. The TelnetSerial object reads from any channel that has data available (Serial first). The writes are sent to all the connected channels at any given time.

Additional primitives provide command line parsing.

Usage

  • Create a TelnetSerial object and use it as you wolud use a Serial object:
#include <TelnetSerial.h>
int incomingByte = 0; // for incoming serial data
TelnetSerial Tty;

void setup() {

    // opens serial port, sets data rate to 9600 bps
    Tty.begin(9600);
    // Soft AP
    WiFi.softAP("MY_APSSID", "mypassword"); // Remove password parameter if you want the AP to be open.
    IPAddress myIP = WiFi.softAPIP();
    Tty.print("AP started. IP address: ");
    Tty.println(myIP);
}
void loop() {
    // send data only when you receive data:
    if (Tty.available() > 0) {
    // read the incoming byte:
    incomingByte = Tty.read();
    // say what you got:
    Tty.print("I received: ");
    Tty.println(incomingByte, DEC);
}
  • Add frequent calls to check_conn() to ensure that incoming Telnet connections are accepted. Other methods also call check_conn(): check() (test whether any console is attached) and available() (check if there is input data available for reading, see example above).

  • The class provides some handy methods to handle command line inputs:

      if (Tty.cmd_available())
         int num_par = Tty.cmd_num_params(); 
         Tty.printf("Command: %s  with  %d parameters\n", Tty.cmd_verb(), Tty.cmd_num_params());  
         for  (int i=0; i<=Tty.cmd_num_params(); i++)  { 
             Tty.printf("Parameter %d: \"%s\" [%d/%f]\n", 
                i, Tty.cmd_param_str(i), Tty.cmd_param_int(i), Tty.cmd_param_double(i));  
         }
         Tty.cmd_init();  // Clear for a new command
      }

API

TelnetSerialderives from the Stream base class, so it implements all its functions (available() , read(), flush(), find(), findUntil(), peek(), readBytes(), readBytesUntil(), readString(), readStringUntil(), parseInt(), parseFloat(), setTimeout()) as well as those of the Print base class (print(), println(), write()).

Constructors

TelnetSerial() Create and begin with default speed

TelnetSerial(long speed) Create and begin serial with given speed

Configuration

bool check_conn() Test for incomming telnet connections (call frequently)

bool check() Is any console connected? (calls check_conn())

operator bool() Allows use of the if(TelnetSerialObject) ... idiom

uint16_t portnum() Return numbre of port to use

bool begin(long speed = 9600) For compatibility witj Serialobject

void autocr(bool onoff) Enable (true) or disable (false) auto CR on LF

void inputecho(bool on_off) Enable (true) or disable (false) keystroke echo on al inputs

void inputecho(bool onoff_serial, bool onoff_telnet) Enable (true) or disable (false) keystroke echo on serial and telnet

void crossecho(bool on_off) Enable (true) or disable (false) keystroke echo on the other source (Telnet <-> Serial)

void telnetsync(bool onoff) Enable/disable sync (behave more like a (slow) character oriented serial connection

bool is_synced() Is sync enabled?

Command line processing

void cmd_set_timeout(unsigned long ms)
Set input timeout (time before the command line being entered is ignored

void cmd_init(const char *prompt = NULL)
Initialize for a new command line

void send_error_message(const char* message)
Send an error message (just println it)

bool cmd_in_progress()
Is user is currently typing a command?

bool cmd_available()
Is a complete command line read and parsed in buffer?

int cmd_num_params()
Get number of parameters in command line

char* cmd_verb()
Pointer to command verb in commns line buffer

bool cmd_equal(const char *expect, int minpar = -1, int maxpar = -1) Is the given command present in the input buffer and has enough parameters?
(min defaults to don't care, max defaults to min)

char* cmd_param_str(uint8_t n)
Get pointer to n-th parameter string (starting with 1)

int cmd_param_int(uint8_t n)
reinterpret n-th parameter as integer

double cmd_param_double(uint8_t n)
reinterpret n-th parameter as double

telnetserial's People

Contributors

mikeofqyn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.