DeepPass / mDot_AT_firmware

Dependencies:   MTS-Serial libmDot mbed-rtos mbed-src

Fork of mDot_AT_firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CommandTerminal.h Source File

CommandTerminal.h

00001 /**
00002   ******************************************************************************
00003   * File Name          : command.h
00004   * Date               : 18/04/2014 10:57:12
00005   * Description        : This file provides code for command line prompt
00006   ******************************************************************************
00007   *
00008   * COPYRIGHT(c) 2014 MultiTech Systems, Inc.
00009   *
00010   * Redistribution and use in source and binary forms, with or without modification,
00011   * are permitted provided that the following conditions are met:
00012   *   1. Redistributions of source code must retain the above copyright notice,
00013   *      this list of conditions and the following disclaimer.
00014   *   2. Redistributions in binary form must reproduce the above copyright notice,
00015   *      this list of conditions and the following disclaimer in the documentation
00016   *      and/or other materials provided with the distribution.
00017   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00018   *      may be used to endorse or promote products derived from this software
00019   *      without specific prior written permission.
00020   *
00021   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00022   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00025   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00027   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00030   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031   *
00032   ******************************************************************************
00033   */
00034   
00035 #include "mbed.h"
00036 #include "MTSSerial.h"
00037 #include "Commands.h"
00038 #include "mDot.h"
00039   
00040 /* Define to prevent recursive inclusion -------------------------------------*/
00041 #ifndef __command_terminal_H__
00042 #define __command_terminal_H__
00043 
00044 class CommandTerminal {
00045 
00046 public:
00047 
00048     enum WaitType {
00049         WAIT_JOIN,
00050         WAIT_RECV,
00051         WAIT_LINK,
00052         WAIT_SEND,
00053         WAIT_NA
00054     };
00055 
00056     CommandTerminal(mts::MTSSerial& serial, mDot* dot);
00057     
00058     // Command prompt text...
00059     static const char banner[];
00060     static const char helpline[];
00061     static const char prompt[];
00062     
00063     // Command error text...
00064     static const char command_error[];
00065     
00066     // Response texts...
00067     static const char help[];
00068     static const char cmd_error[];
00069     static const char newline[];
00070     static const char done[];
00071     static const char error[];
00072 
00073     // Escape sequence
00074     static const char escape_sequence[];
00075     
00076     static std::string formatPacketData(const std::vector<uint8_t>& data, const uint8_t& format);
00077     static bool waitForEscape(int timeout, mDot* dot=NULL, WaitType wait=WAIT_NA);
00078 
00079     void start();
00080     
00081 private: 
00082 
00083     mts::MTSSerial& _serial;
00084     static mts::MTSSerial* _serialp;
00085 
00086     mDot* _dot;
00087     mDot::Mode _mode;
00088     std::vector<Command*> _commands;
00089     bool _sleep_standby;
00090     DigitalOut _xbee_on_sleep;
00091     bool _serial_up;
00092 
00093     void addCommand(Command* cmd);
00094     
00095     void serial_loop();
00096     bool autoJoinCheck();
00097 
00098     void printHelp();
00099 
00100     bool readable();
00101     bool writeable();
00102     char read();
00103     void write(const char* message);
00104     void writef(const char* format, ... );
00105 
00106     void sleep(bool standby);
00107     void wakeup(bool standby);
00108     
00109 };
00110 
00111 #endif // __command_terminal_H__
00112