Leest de waarde van een sensor binnen een maakt deze beschikbaar via internet

Dependencies:   NTPClient_NetServices mbed

Committer:
hendrikvincent
Date:
Mon Dec 02 09:01:23 2013 +0000
Revision:
0:05ccbd4f84f1
eerste programma;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hendrikvincent 0:05ccbd4f84f1 1
hendrikvincent 0:05ccbd4f84f1 2 /*
hendrikvincent 0:05ccbd4f84f1 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
hendrikvincent 0:05ccbd4f84f1 4
hendrikvincent 0:05ccbd4f84f1 5 Permission is hereby granted, free of charge, to any person obtaining a copy
hendrikvincent 0:05ccbd4f84f1 6 of this software and associated documentation files (the "Software"), to deal
hendrikvincent 0:05ccbd4f84f1 7 in the Software without restriction, including without limitation the rights
hendrikvincent 0:05ccbd4f84f1 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hendrikvincent 0:05ccbd4f84f1 9 copies of the Software, and to permit persons to whom the Software is
hendrikvincent 0:05ccbd4f84f1 10 furnished to do so, subject to the following conditions:
hendrikvincent 0:05ccbd4f84f1 11
hendrikvincent 0:05ccbd4f84f1 12 The above copyright notice and this permission notice shall be included in
hendrikvincent 0:05ccbd4f84f1 13 all copies or substantial portions of the Software.
hendrikvincent 0:05ccbd4f84f1 14
hendrikvincent 0:05ccbd4f84f1 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hendrikvincent 0:05ccbd4f84f1 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hendrikvincent 0:05ccbd4f84f1 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hendrikvincent 0:05ccbd4f84f1 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hendrikvincent 0:05ccbd4f84f1 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hendrikvincent 0:05ccbd4f84f1 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hendrikvincent 0:05ccbd4f84f1 21 THE SOFTWARE.
hendrikvincent 0:05ccbd4f84f1 22 */
hendrikvincent 0:05ccbd4f84f1 23
hendrikvincent 0:05ccbd4f84f1 24 #ifndef SERIALBUF_H
hendrikvincent 0:05ccbd4f84f1 25 #define SERIALBUF_H
hendrikvincent 0:05ccbd4f84f1 26
hendrikvincent 0:05ccbd4f84f1 27 #include "mbed.h"
hendrikvincent 0:05ccbd4f84f1 28 #include "netCfg.h"
hendrikvincent 0:05ccbd4f84f1 29 #if NET_USB_SERIAL
hendrikvincent 0:05ccbd4f84f1 30 #include "drv/serial/usb/UsbSerial.h"
hendrikvincent 0:05ccbd4f84f1 31 #endif
hendrikvincent 0:05ccbd4f84f1 32
hendrikvincent 0:05ccbd4f84f1 33 class SerialCircularBuf
hendrikvincent 0:05ccbd4f84f1 34 {
hendrikvincent 0:05ccbd4f84f1 35 public:
hendrikvincent 0:05ccbd4f84f1 36 SerialCircularBuf(int len);
hendrikvincent 0:05ccbd4f84f1 37 ~SerialCircularBuf();
hendrikvincent 0:05ccbd4f84f1 38
hendrikvincent 0:05ccbd4f84f1 39 int room();
hendrikvincent 0:05ccbd4f84f1 40 int len();
hendrikvincent 0:05ccbd4f84f1 41
hendrikvincent 0:05ccbd4f84f1 42 void write(char c);
hendrikvincent 0:05ccbd4f84f1 43 char read();
hendrikvincent 0:05ccbd4f84f1 44
hendrikvincent 0:05ccbd4f84f1 45 void setReadMode(bool readMode); //If true, keeps chars in buf when read, false by default
hendrikvincent 0:05ccbd4f84f1 46 void flushRead(); //Delete chars that have been read & return chars len (only useful with readMode = true)
hendrikvincent 0:05ccbd4f84f1 47 void resetRead(); //Go back to initial read position & return chars len (only useful with readMode = true)
hendrikvincent 0:05ccbd4f84f1 48
hendrikvincent 0:05ccbd4f84f1 49 private:
hendrikvincent 0:05ccbd4f84f1 50 char* m_buf;
hendrikvincent 0:05ccbd4f84f1 51 int m_len;
hendrikvincent 0:05ccbd4f84f1 52
hendrikvincent 0:05ccbd4f84f1 53 volatile char* m_pReadStart;
hendrikvincent 0:05ccbd4f84f1 54 volatile char* m_pRead;
hendrikvincent 0:05ccbd4f84f1 55 volatile char* m_pWrite;
hendrikvincent 0:05ccbd4f84f1 56 volatile bool m_readMode;
hendrikvincent 0:05ccbd4f84f1 57 };
hendrikvincent 0:05ccbd4f84f1 58
hendrikvincent 0:05ccbd4f84f1 59 class SerialBuf
hendrikvincent 0:05ccbd4f84f1 60 {
hendrikvincent 0:05ccbd4f84f1 61 public:
hendrikvincent 0:05ccbd4f84f1 62 SerialBuf(int len); //Buffer length
hendrikvincent 0:05ccbd4f84f1 63 virtual ~SerialBuf();
hendrikvincent 0:05ccbd4f84f1 64
hendrikvincent 0:05ccbd4f84f1 65 void attach(Serial* pSerial);
hendrikvincent 0:05ccbd4f84f1 66 void detach();
hendrikvincent 0:05ccbd4f84f1 67
hendrikvincent 0:05ccbd4f84f1 68 #if NET_USB_SERIAL
hendrikvincent 0:05ccbd4f84f1 69 void attach(UsbSerial* pUsbSerial);
hendrikvincent 0:05ccbd4f84f1 70 #endif
hendrikvincent 0:05ccbd4f84f1 71
hendrikvincent 0:05ccbd4f84f1 72 //Really useful for debugging
hendrikvincent 0:05ccbd4f84f1 73 char getc();
hendrikvincent 0:05ccbd4f84f1 74 void putc(char c);
hendrikvincent 0:05ccbd4f84f1 75 bool readable();
hendrikvincent 0:05ccbd4f84f1 76 bool writeable();
hendrikvincent 0:05ccbd4f84f1 77 /*protected:*/
hendrikvincent 0:05ccbd4f84f1 78 void setReadMode(bool readMode); //If true, keeps chars in buf when read, false by default
hendrikvincent 0:05ccbd4f84f1 79 void flushRead(); //Delete chars that have been read & return chars len (only useful with readMode = true)
hendrikvincent 0:05ccbd4f84f1 80 void resetRead(); //Go back to initial read position & return chars len (only useful with readMode = true)
hendrikvincent 0:05ccbd4f84f1 81
hendrikvincent 0:05ccbd4f84f1 82 private:
hendrikvincent 0:05ccbd4f84f1 83 void onRxInterrupt(); //Callback from m_pSerial
hendrikvincent 0:05ccbd4f84f1 84 void onTxInterrupt(); //Callback from m_pSerial
hendrikvincent 0:05ccbd4f84f1 85
hendrikvincent 0:05ccbd4f84f1 86 SerialCircularBuf m_rxBuf;
hendrikvincent 0:05ccbd4f84f1 87 SerialCircularBuf m_txBuf;
hendrikvincent 0:05ccbd4f84f1 88
hendrikvincent 0:05ccbd4f84f1 89 Serial* m_pSerial; //Not owned
hendrikvincent 0:05ccbd4f84f1 90
hendrikvincent 0:05ccbd4f84f1 91 #if NET_USB_SERIAL
hendrikvincent 0:05ccbd4f84f1 92 //USB Serial Impl
hendrikvincent 0:05ccbd4f84f1 93 UsbSerial* m_pUsbSerial; //Not owned
hendrikvincent 0:05ccbd4f84f1 94 //Ticker m_usbTick;
hendrikvincent 0:05ccbd4f84f1 95 #endif
hendrikvincent 0:05ccbd4f84f1 96 };
hendrikvincent 0:05ccbd4f84f1 97
hendrikvincent 0:05ccbd4f84f1 98
hendrikvincent 0:05ccbd4f84f1 99 #endif