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 * @section LICENSE
hendrikvincent 0:05ccbd4f84f1 3 *Copyright (c) 2010 ARM Ltd.
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 * @section DESCRIPTION
hendrikvincent 0:05ccbd4f84f1 25 *
hendrikvincent 0:05ccbd4f84f1 26 *This class sets up RPC communication. This allows objects on mbed to be controlled. Objects can be created or existing objects can be used
hendrikvincent 0:05ccbd4f84f1 27 */
hendrikvincent 0:05ccbd4f84f1 28 #include "SerialRPCInterface.h"
hendrikvincent 0:05ccbd4f84f1 29
hendrikvincent 0:05ccbd4f84f1 30 using namespace mbed;
hendrikvincent 0:05ccbd4f84f1 31
hendrikvincent 0:05ccbd4f84f1 32 //Requires multiple contstructors for each type, serial to set different pin numbers, TCP for port.
hendrikvincent 0:05ccbd4f84f1 33 SerialRPCInterface::SerialRPCInterface(PinName tx, PinName rx, int baud):pc(tx, rx) {
hendrikvincent 0:05ccbd4f84f1 34 _RegClasses();
hendrikvincent 0:05ccbd4f84f1 35 _enabled = true;
hendrikvincent 0:05ccbd4f84f1 36 pc.attach(this, &SerialRPCInterface::_RPCSerial, Serial::RxIrq);
hendrikvincent 0:05ccbd4f84f1 37 if(baud != 9600)pc.baud(baud);
hendrikvincent 0:05ccbd4f84f1 38 }
hendrikvincent 0:05ccbd4f84f1 39
hendrikvincent 0:05ccbd4f84f1 40 void SerialRPCInterface::_RegClasses(void){
hendrikvincent 0:05ccbd4f84f1 41 //Register classes with base
hendrikvincent 0:05ccbd4f84f1 42 Base::add_rpc_class<AnalogIn>();
hendrikvincent 0:05ccbd4f84f1 43 Base::add_rpc_class<AnalogOut>();
hendrikvincent 0:05ccbd4f84f1 44 Base::add_rpc_class<DigitalIn>();
hendrikvincent 0:05ccbd4f84f1 45 Base::add_rpc_class<DigitalOut>();
hendrikvincent 0:05ccbd4f84f1 46 Base::add_rpc_class<DigitalInOut>();
hendrikvincent 0:05ccbd4f84f1 47 Base::add_rpc_class<PwmOut>();
hendrikvincent 0:05ccbd4f84f1 48 Base::add_rpc_class<Timer>();
hendrikvincent 0:05ccbd4f84f1 49 Base::add_rpc_class<BusOut>();
hendrikvincent 0:05ccbd4f84f1 50 Base::add_rpc_class<BusIn>();
hendrikvincent 0:05ccbd4f84f1 51 Base::add_rpc_class<BusInOut>();
hendrikvincent 0:05ccbd4f84f1 52 Base::add_rpc_class<Serial>();
hendrikvincent 0:05ccbd4f84f1 53 }
hendrikvincent 0:05ccbd4f84f1 54
hendrikvincent 0:05ccbd4f84f1 55 void SerialRPCInterface::Disable(void){
hendrikvincent 0:05ccbd4f84f1 56 _enabled = false;
hendrikvincent 0:05ccbd4f84f1 57 }
hendrikvincent 0:05ccbd4f84f1 58 void SerialRPCInterface::Enable(void){
hendrikvincent 0:05ccbd4f84f1 59 _enabled = true;
hendrikvincent 0:05ccbd4f84f1 60 }
hendrikvincent 0:05ccbd4f84f1 61 void SerialRPCInterface::_MsgProcess(void) {
hendrikvincent 0:05ccbd4f84f1 62 if(_enabled == true){
hendrikvincent 0:05ccbd4f84f1 63 rpc(_command, _response);
hendrikvincent 0:05ccbd4f84f1 64 }
hendrikvincent 0:05ccbd4f84f1 65 }
hendrikvincent 0:05ccbd4f84f1 66
hendrikvincent 0:05ccbd4f84f1 67 void SerialRPCInterface::_RPCSerial() {
hendrikvincent 0:05ccbd4f84f1 68 _RPCflag = true;
hendrikvincent 0:05ccbd4f84f1 69 if(_enabled == true){
hendrikvincent 0:05ccbd4f84f1 70 pc.gets(_command, 256);
hendrikvincent 0:05ccbd4f84f1 71 _MsgProcess();
hendrikvincent 0:05ccbd4f84f1 72 pc.printf("%s\n", _response);
hendrikvincent 0:05ccbd4f84f1 73 }
hendrikvincent 0:05ccbd4f84f1 74 _RPCflag = false;
hendrikvincent 0:05ccbd4f84f1 75 }