Ergänzt das jQueryMobile Beispiel um die Fehlenden Aktoren wie LED 3 und Servo 2.

Fork of RPCHTTPServerVariable by smd.iotkit2.ch

Committer:
stefan1691
Date:
Wed Apr 08 12:31:28 2015 +0000
Revision:
14:3835863bc412
Korrektur AnalogIn laut . https://developer.mbed.org/questions/3897/AnalogIn-not-working-in-rpc/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stefan1691 14:3835863bc412 1 /* mbed Microcontroller Library
stefan1691 14:3835863bc412 2 * Copyright (c) 2006-2013 ARM Limited
stefan1691 14:3835863bc412 3 *
stefan1691 14:3835863bc412 4 * Licensed under the Apache License, Version 2.0 (the "License");
stefan1691 14:3835863bc412 5 * you may not use this file except in compliance with the License.
stefan1691 14:3835863bc412 6 * You may obtain a copy of the License at
stefan1691 14:3835863bc412 7 *
stefan1691 14:3835863bc412 8 * http://www.apache.org/licenses/LICENSE-2.0
stefan1691 14:3835863bc412 9 *
stefan1691 14:3835863bc412 10 * Unless required by applicable law or agreed to in writing, software
stefan1691 14:3835863bc412 11 * distributed under the License is distributed on an "AS IS" BASIS,
stefan1691 14:3835863bc412 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
stefan1691 14:3835863bc412 13 * See the License for the specific language governing permissions and
stefan1691 14:3835863bc412 14 * limitations under the License.
stefan1691 14:3835863bc412 15 */
stefan1691 14:3835863bc412 16 #include "Arguments.h"
stefan1691 14:3835863bc412 17 #include "pinmap.h"
stefan1691 14:3835863bc412 18
stefan1691 14:3835863bc412 19 using namespace std;
stefan1691 14:3835863bc412 20
stefan1691 14:3835863bc412 21 namespace mbed {
stefan1691 14:3835863bc412 22
stefan1691 14:3835863bc412 23 Arguments::Arguments(const char* rqs) {
stefan1691 14:3835863bc412 24 obj_name = NULL;
stefan1691 14:3835863bc412 25 method_name = NULL;
stefan1691 14:3835863bc412 26 argc = 0;
stefan1691 14:3835863bc412 27
stefan1691 14:3835863bc412 28 // This copy can be removed if we can assume the request string is
stefan1691 14:3835863bc412 29 // persistent and writable for the duration of the call
stefan1691 14:3835863bc412 30 strcpy(request, rqs);
stefan1691 14:3835863bc412 31
stefan1691 14:3835863bc412 32 // Initial '/'
stefan1691 14:3835863bc412 33 char* p = request;
stefan1691 14:3835863bc412 34 if (*p != '/') return;
stefan1691 14:3835863bc412 35 p++;
stefan1691 14:3835863bc412 36
stefan1691 14:3835863bc412 37 // Object Name
stefan1691 14:3835863bc412 38 p = search_arg(&obj_name, p, '/');
stefan1691 14:3835863bc412 39 if (p == NULL) return;
stefan1691 14:3835863bc412 40
stefan1691 14:3835863bc412 41 // Method Name
stefan1691 14:3835863bc412 42 p = search_arg(&method_name, p, ' ');
stefan1691 14:3835863bc412 43 if (p == NULL) return;
stefan1691 14:3835863bc412 44
stefan1691 14:3835863bc412 45 // Arguments
stefan1691 14:3835863bc412 46 while (true) {
stefan1691 14:3835863bc412 47 argv[argc] = NULL;
stefan1691 14:3835863bc412 48 p = search_arg(&argv[argc], p, ' ');
stefan1691 14:3835863bc412 49 if (argv[argc] != NULL) argc++;
stefan1691 14:3835863bc412 50 if (p == NULL) break;
stefan1691 14:3835863bc412 51 }
stefan1691 14:3835863bc412 52
stefan1691 14:3835863bc412 53 index = -1;
stefan1691 14:3835863bc412 54 }
stefan1691 14:3835863bc412 55
stefan1691 14:3835863bc412 56 char* Arguments::search_arg(char **arg, char *p, char next_sep) {
stefan1691 14:3835863bc412 57 char *s = p;
stefan1691 14:3835863bc412 58 while (true) {
stefan1691 14:3835863bc412 59 if ((*p == '/') || (*p == ' ') || (*p == '\n') || (*p == '\0')) break;
stefan1691 14:3835863bc412 60 p++;
stefan1691 14:3835863bc412 61 }
stefan1691 14:3835863bc412 62 if (p == s) return NULL;
stefan1691 14:3835863bc412 63 *arg = s;
stefan1691 14:3835863bc412 64 char separator = *p;
stefan1691 14:3835863bc412 65 *p = '\0';
stefan1691 14:3835863bc412 66 p++;
stefan1691 14:3835863bc412 67 return (separator == next_sep) ? (p) : (NULL);
stefan1691 14:3835863bc412 68 }
stefan1691 14:3835863bc412 69
stefan1691 14:3835863bc412 70 template<> PinName Arguments::getArg<PinName>(void) {
stefan1691 14:3835863bc412 71 index++;
stefan1691 14:3835863bc412 72 return parse_pins(argv[index]);
stefan1691 14:3835863bc412 73 }
stefan1691 14:3835863bc412 74
stefan1691 14:3835863bc412 75 template<> int Arguments::getArg<int>(void) {
stefan1691 14:3835863bc412 76 index++;
stefan1691 14:3835863bc412 77 char *pEnd;
stefan1691 14:3835863bc412 78 return strtol(argv[index], &pEnd, 10);
stefan1691 14:3835863bc412 79 }
stefan1691 14:3835863bc412 80
stefan1691 14:3835863bc412 81 template<> const char* Arguments::getArg<const char*>(void) {
stefan1691 14:3835863bc412 82 index++;
stefan1691 14:3835863bc412 83 return argv[index];
stefan1691 14:3835863bc412 84 }
stefan1691 14:3835863bc412 85
stefan1691 14:3835863bc412 86 template<> char Arguments::getArg<char>(void) {
stefan1691 14:3835863bc412 87 index++;
stefan1691 14:3835863bc412 88 return *argv[index];
stefan1691 14:3835863bc412 89 }
stefan1691 14:3835863bc412 90
stefan1691 14:3835863bc412 91 template<> double Arguments::getArg<double>(void) {
stefan1691 14:3835863bc412 92 index++;
stefan1691 14:3835863bc412 93 return atof(argv[index]);
stefan1691 14:3835863bc412 94 }
stefan1691 14:3835863bc412 95
stefan1691 14:3835863bc412 96 template<> float Arguments::getArg<float>(void) {
stefan1691 14:3835863bc412 97 index++;
stefan1691 14:3835863bc412 98 return atof(argv[index]);
stefan1691 14:3835863bc412 99 }
stefan1691 14:3835863bc412 100
stefan1691 14:3835863bc412 101 Reply::Reply(char* r) {
stefan1691 14:3835863bc412 102 first = true;
stefan1691 14:3835863bc412 103 *r = '\0';
stefan1691 14:3835863bc412 104 reply = r;
stefan1691 14:3835863bc412 105 }
stefan1691 14:3835863bc412 106
stefan1691 14:3835863bc412 107 void Reply::separator(void) {
stefan1691 14:3835863bc412 108 if (first) {
stefan1691 14:3835863bc412 109 first = false;
stefan1691 14:3835863bc412 110 } else {
stefan1691 14:3835863bc412 111 *reply = ' '; reply++;
stefan1691 14:3835863bc412 112 }
stefan1691 14:3835863bc412 113 }
stefan1691 14:3835863bc412 114
stefan1691 14:3835863bc412 115 template<> void Reply::putData<const char*>(const char* s) {
stefan1691 14:3835863bc412 116 separator();
stefan1691 14:3835863bc412 117 reply += sprintf(reply, "%s", s);
stefan1691 14:3835863bc412 118 }
stefan1691 14:3835863bc412 119
stefan1691 14:3835863bc412 120 template<> void Reply::putData<char*>(char* s) {
stefan1691 14:3835863bc412 121 separator();
stefan1691 14:3835863bc412 122 reply += sprintf(reply, "%s", s);
stefan1691 14:3835863bc412 123 }
stefan1691 14:3835863bc412 124
stefan1691 14:3835863bc412 125 template<> void Reply::putData<char>(char c) {
stefan1691 14:3835863bc412 126 separator();
stefan1691 14:3835863bc412 127 reply += sprintf(reply, "%c", c);
stefan1691 14:3835863bc412 128 }
stefan1691 14:3835863bc412 129
stefan1691 14:3835863bc412 130 template<> void Reply::putData<int>(int v) {
stefan1691 14:3835863bc412 131 separator();
stefan1691 14:3835863bc412 132 reply += sprintf(reply, "%d", v);
stefan1691 14:3835863bc412 133 }
stefan1691 14:3835863bc412 134
stefan1691 14:3835863bc412 135 template<> void Reply::putData<float>(float f) {
stefan1691 14:3835863bc412 136 separator();
stefan1691 14:3835863bc412 137 reply += sprintf(reply, "%.17g", f);
stefan1691 14:3835863bc412 138 }
stefan1691 14:3835863bc412 139
stefan1691 14:3835863bc412 140 // put by me to accomodate read_u16() of AnalogIn
stefan1691 14:3835863bc412 141 template<> void Reply::putData<unsigned short>(unsigned short uint16) {
stefan1691 14:3835863bc412 142 separator();
stefan1691 14:3835863bc412 143 reply += sprintf(reply, "%u", uint16);
stefan1691 14:3835863bc412 144 }
stefan1691 14:3835863bc412 145
stefan1691 14:3835863bc412 146 } // namespace mbed