Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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