A web server for monitoring and controlling a MakerBot Replicator over the USB host and ethernet.
Dependencies: IAP NTPClient RTC mbed-rtos mbed Socket lwip-sys lwip BurstSPI
Fork of LPC1768_Mini-DK by
readline.cpp
00001 // Copyright (c) 2013, jake (at) allaboutjake (dot) com 00002 // All rights reserved. 00003 // 00004 // Redistribution and use in source and binary forms, with or without 00005 // modification, are permitted provided that the following conditions are met: 00006 // * Redistributions of source code must retain the above copyright 00007 // notice, this list of conditions and the following disclaimer. 00008 // * Redistributions in binary form must reproduce the above copyright 00009 // notice, this list of conditions and the following disclaimer in the 00010 // documentation and/or other materials provided with the distribution. 00011 // * The name of the author and/or copyright holder nor the 00012 // names of its contributors may be used to endorse or promote products 00013 // derived from this software without specific prior written permission. 00014 // 00015 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00016 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00017 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00018 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, AUTHOR, OR ANY CONTRIBUTORS 00019 // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00020 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00021 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00022 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00023 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00024 // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 00026 // DESCRIPTION OF FILE: 00027 // 00028 // This file contains a very simple readline function used by the http and telnet 00029 // server threads. 00030 // 00031 00032 #include "SimpleSocket.h" 00033 #include "mbed.h" 00034 #include "rtos.h" 00035 00036 //Simple readline routine for use in the command prompt. 00037 int readline(ClientSocket* socket, char* buffer, int max_length) { 00038 int curPos = 0; 00039 00040 while (1) { 00041 int c; 00042 00043 //Wait for a character 00044 while ((c=socket->read()) < 0) { 00045 if (!socket->connected()) return -1; 00046 Thread::yield(); 00047 } 00048 00049 switch (c) { 00050 case '\r': 00051 continue; 00052 00053 case '\b': 00054 if (curPos > 0) curPos--; 00055 break; 00056 00057 default: 00058 buffer[curPos]= (char)(c & 0xFF); 00059 curPos++; 00060 if (curPos < max_length) 00061 break; 00062 00063 //FALLTHROUGH 00064 case '\n': 00065 buffer[curPos]=0x00; //string terminator 00066 return curPos; 00067 } 00068 } 00069 } 00070
Generated on Tue Jul 12 2022 17:52:03 by 1.7.2