Remote Sensing demo. This is the code that runs on mbed to interface with the Remote Sensing Applet Demo
Dependencies: EthernetNetIf mbed TMP102 HTTPServer ADJD-S371_ColourSens
main.cpp@2:1cc34c25b99d, 2011-02-04 (annotated)
- Committer:
- MichaelW
- Date:
- Fri Feb 04 11:10:22 2011 +0000
- Revision:
- 2:1cc34c25b99d
- Parent:
- 1:0f7aff70292e
Updated RPCInterface Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MichaelW | 0:3abbad5a358a | 1 | /** |
MichaelW | 0:3abbad5a358a | 2 | Copyright (c) 2010 ARM Ltd |
MichaelW | 0:3abbad5a358a | 3 | |
MichaelW | 0:3abbad5a358a | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
MichaelW | 0:3abbad5a358a | 5 | of this software and associated documentation files (the "Software"), to deal |
MichaelW | 0:3abbad5a358a | 6 | in the Software without restriction, including without limitation the rights |
MichaelW | 0:3abbad5a358a | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
MichaelW | 0:3abbad5a358a | 8 | copies of the Software, and to permit persons to whom the Software is |
MichaelW | 0:3abbad5a358a | 9 | furnished to do so, subject to the following conditions: |
MichaelW | 0:3abbad5a358a | 10 | |
MichaelW | 0:3abbad5a358a | 11 | The above copyright notice and this permission notice shall be included in |
MichaelW | 0:3abbad5a358a | 12 | all copies or substantial portions of the Software. |
MichaelW | 0:3abbad5a358a | 13 | |
MichaelW | 0:3abbad5a358a | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
MichaelW | 0:3abbad5a358a | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
MichaelW | 0:3abbad5a358a | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
MichaelW | 0:3abbad5a358a | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
MichaelW | 0:3abbad5a358a | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MichaelW | 0:3abbad5a358a | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
MichaelW | 0:3abbad5a358a | 20 | THE SOFTWARE. |
MichaelW | 0:3abbad5a358a | 21 | */ |
MichaelW | 0:3abbad5a358a | 22 | #include "mbed.h" |
MichaelW | 0:3abbad5a358a | 23 | #include "EthernetNetIf.h" |
MichaelW | 0:3abbad5a358a | 24 | #include "HTTPServer.h" |
MichaelW | 0:3abbad5a358a | 25 | #include "RPCFunction.h" |
MichaelW | 0:3abbad5a358a | 26 | #include "RPCVariable.h" |
MichaelW | 0:3abbad5a358a | 27 | #include "SerialRPCInterface.h" |
MichaelW | 0:3abbad5a358a | 28 | #include "ADJDColourSensor.h" |
MichaelW | 0:3abbad5a358a | 29 | #include "TMP102.h" |
MichaelW | 0:3abbad5a358a | 30 | #include "scp1000.h" |
MichaelW | 0:3abbad5a358a | 31 | LocalFileSystem fs("webfs"); |
MichaelW | 0:3abbad5a358a | 32 | |
MichaelW | 0:3abbad5a358a | 33 | EthernetNetIf eth; |
MichaelW | 0:3abbad5a358a | 34 | HTTPServer svr; |
MichaelW | 0:3abbad5a358a | 35 | |
MichaelW | 0:3abbad5a358a | 36 | void getColour(char * input, char * Output); |
MichaelW | 0:3abbad5a358a | 37 | void getTemperature(char *input, char * Output); |
MichaelW | 0:3abbad5a358a | 38 | void getPressure(char *input, char * Output); |
MichaelW | 0:3abbad5a358a | 39 | void getSCPTemperature(char *input, char * Output); |
MichaelW | 0:3abbad5a358a | 40 | |
MichaelW | 0:3abbad5a358a | 41 | //Set up sensors |
MichaelW | 0:3abbad5a358a | 42 | TMP102 Temperature(p9, p10, 0x90); |
MichaelW | 0:3abbad5a358a | 43 | ADJDColourSensor Colour(p28,p27, p22); |
MichaelW | 0:3abbad5a358a | 44 | SCP1000 Pressure(p5,p6,p7,p8); |
MichaelW | 0:3abbad5a358a | 45 | DigitalIn PIR(p21, "PIR"); |
MichaelW | 0:3abbad5a358a | 46 | AnalogIn Light(p20, "Light"); |
MichaelW | 0:3abbad5a358a | 47 | |
MichaelW | 0:3abbad5a358a | 48 | //Set up custom RPC |
MichaelW | 0:3abbad5a358a | 49 | RPCFunction GetTemp(&getTemperature, "Temperature"); |
MichaelW | 0:3abbad5a358a | 50 | RPCFunction GetPressure(&getPressure, "Pressure"); |
MichaelW | 0:3abbad5a358a | 51 | RPCFunction GetSCPTemperature(&getSCPTemperature, "SCPtemperature"); |
MichaelW | 0:3abbad5a358a | 52 | RPCFunction GetColour(&getColour, "Colour"); |
MichaelW | 0:3abbad5a358a | 53 | |
MichaelW | 0:3abbad5a358a | 54 | //Serial RPC used for testing |
MichaelW | 0:3abbad5a358a | 55 | //SerialRPCInterface applet(USBTX, USBRX, 115200); |
MichaelW | 0:3abbad5a358a | 56 | |
MichaelW | 0:3abbad5a358a | 57 | |
MichaelW | 0:3abbad5a358a | 58 | int main() { |
MichaelW | 0:3abbad5a358a | 59 | Base::add_rpc_class<AnalogIn>(); |
MichaelW | 0:3abbad5a358a | 60 | Base::add_rpc_class<AnalogOut>(); |
MichaelW | 0:3abbad5a358a | 61 | Base::add_rpc_class<DigitalIn>(); |
MichaelW | 0:3abbad5a358a | 62 | Base::add_rpc_class<DigitalOut>(); |
MichaelW | 0:3abbad5a358a | 63 | Base::add_rpc_class<DigitalInOut>(); |
MichaelW | 0:3abbad5a358a | 64 | Base::add_rpc_class<PwmOut>(); |
MichaelW | 0:3abbad5a358a | 65 | Base::add_rpc_class<Timer>(); |
MichaelW | 0:3abbad5a358a | 66 | Base::add_rpc_class<BusOut>(); |
MichaelW | 0:3abbad5a358a | 67 | Base::add_rpc_class<BusIn>(); |
MichaelW | 0:3abbad5a358a | 68 | Base::add_rpc_class<BusInOut>(); |
MichaelW | 0:3abbad5a358a | 69 | Base::add_rpc_class<Serial>(); |
MichaelW | 0:3abbad5a358a | 70 | |
MichaelW | 0:3abbad5a358a | 71 | printf("Setting up...\n"); |
MichaelW | 0:3abbad5a358a | 72 | EthernetErr ethErr = eth.setup(); |
MichaelW | 0:3abbad5a358a | 73 | if(ethErr) |
MichaelW | 0:3abbad5a358a | 74 | { |
MichaelW | 0:3abbad5a358a | 75 | printf("Error %d in setup.\n", ethErr); |
MichaelW | 0:3abbad5a358a | 76 | return -1; |
MichaelW | 0:3abbad5a358a | 77 | } |
MichaelW | 0:3abbad5a358a | 78 | printf("Setup OK\n"); |
MichaelW | 0:3abbad5a358a | 79 | |
MichaelW | 0:3abbad5a358a | 80 | FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path |
MichaelW | 0:3abbad5a358a | 81 | FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path |
MichaelW | 0:3abbad5a358a | 82 | |
MichaelW | 0:3abbad5a358a | 83 | svr.addHandler<SimpleHandler>("/hello"); |
MichaelW | 0:3abbad5a358a | 84 | svr.addHandler<RPCHandler>("/rpc"); |
MichaelW | 0:3abbad5a358a | 85 | svr.addHandler<FSHandler>("/files"); |
MichaelW | 0:3abbad5a358a | 86 | svr.addHandler<FSHandler>("/"); //Default handler |
MichaelW | 0:3abbad5a358a | 87 | //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
MichaelW | 0:3abbad5a358a | 88 | |
MichaelW | 0:3abbad5a358a | 89 | svr.bind(80); |
MichaelW | 0:3abbad5a358a | 90 | |
MichaelW | 0:3abbad5a358a | 91 | printf("Listening...\n"); |
MichaelW | 0:3abbad5a358a | 92 | //Listen indefinitely |
MichaelW | 0:3abbad5a358a | 93 | while(true){ |
MichaelW | 1:0f7aff70292e | 94 | Net::poll(); |
MichaelW | 1:0f7aff70292e | 95 | //Do own thing here |
MichaelW | 0:3abbad5a358a | 96 | |
MichaelW | 0:3abbad5a358a | 97 | //This could for example be data logging. |
MichaelW | 0:3abbad5a358a | 98 | |
MichaelW | 0:3abbad5a358a | 99 | } |
MichaelW | 0:3abbad5a358a | 100 | |
MichaelW | 0:3abbad5a358a | 101 | } |
MichaelW | 0:3abbad5a358a | 102 | |
MichaelW | 0:3abbad5a358a | 103 | //RPC Functions - these are used to wrap the sensor libraries that other wise would not be acessible over RPC. |
MichaelW | 0:3abbad5a358a | 104 | void getTemperature(char *input, char * Output){ |
MichaelW | 0:3abbad5a358a | 105 | float f = Temperature.read(); |
MichaelW | 0:3abbad5a358a | 106 | sprintf(Output, "%f", f); |
MichaelW | 0:3abbad5a358a | 107 | } |
MichaelW | 0:3abbad5a358a | 108 | void getPressure(char *input, char * Output){ |
MichaelW | 0:3abbad5a358a | 109 | float f = Pressure.read(); |
MichaelW | 0:3abbad5a358a | 110 | sprintf(Output, "%f",f); |
MichaelW | 0:3abbad5a358a | 111 | } |
MichaelW | 0:3abbad5a358a | 112 | void getSCPTemperature(char *input, char * Output){ |
MichaelW | 0:3abbad5a358a | 113 | float f = Pressure.readTemperature(); |
MichaelW | 0:3abbad5a358a | 114 | sprintf(Output, "%f", f); |
MichaelW | 0:3abbad5a358a | 115 | } |
MichaelW | 0:3abbad5a358a | 116 | void getColour(char *input, char * Output){ |
MichaelW | 0:3abbad5a358a | 117 | float clear = Colour.read(); |
MichaelW | 0:3abbad5a358a | 118 | sprintf(Output, "%f,%f,%f,%f,", clear/500, Colour.red/500, Colour.green/500, Colour.blue/500); |
MichaelW | 0:3abbad5a358a | 119 | } |