Lab 1 Program C
Fork of mbed by
rpc.h@28:667d61c9177b, 2011-12-08 (annotated)
- Committer:
- emilmont
- Date:
- Thu Dec 08 12:04:01 2011 +0000
- Revision:
- 28:667d61c9177b
- Parent:
- 27:7110ebee3484
- Child:
- 43:aff670d0d510
Add additional M0 peripherals implementations, fix GCC stdio/uart
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rolf.meyer@arm.com | 11:1c1ebd0324fa | 1 | /* mbed Microcontroller Library - RPC |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 2 | * Copyright (c) 2008-2009 ARM Limited. All rights reserved. |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 3 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 4 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 5 | #ifndef MBED_RPC_H |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 6 | #define MBED_RPC_H |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 7 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 8 | /* Section rpc |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 9 | * Helpers for rpc handling. |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 10 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 11 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 12 | #include <stdlib.h> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 13 | #include <stdio.h> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 14 | #include <string.h> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 15 | #include <ctype.h> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 16 | #include "Base.h" |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 17 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 18 | #include "PinNames.h" |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 19 | #include <stdint.h> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 20 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 21 | namespace mbed { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 22 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 23 | /* Function parse_arg |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 24 | * Parses and returns a value from a string. |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 25 | * |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 26 | * Variable |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 27 | * arg - The string to pase |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 28 | * next - If not NULL a pointer to after the last |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 29 | * character parsed is written here |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 30 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 31 | template<typename T> T parse_arg(const char *arg, const char **next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 32 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 33 | inline char parse_char(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 34 | char c = *arg++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 35 | if(c == '\\') { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 36 | c = *arg++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 37 | switch(c) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 38 | case 'a': c = '\a'; break; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 39 | case 'b': c = '\b'; break; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 40 | case 't': c = '\t'; break; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 41 | case 'n': c = '\n'; break; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 42 | case 'v': c = '\v'; break; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 43 | case 'f': c = '\f'; break; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 44 | case 'r': c = '\r'; break; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 45 | case 'x': |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 46 | { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 47 | /* two-character hexadecimal */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 48 | char buf[3]; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 49 | buf[0] = *arg++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 50 | buf[1] = *arg++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 51 | buf[2] = 0; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 52 | c = strtol(buf, NULL, 16); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 53 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 54 | break; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 55 | default: |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 56 | if(isdigit(c)) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 57 | /* three-character octal */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 58 | char buf[4]; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 59 | buf[0] = c; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 60 | buf[1] = *arg++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 61 | buf[2] = *arg++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 62 | buf[3] = 0; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 63 | c = strtol(buf, NULL, 8); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 64 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 65 | break; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 66 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 67 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 68 | *next = arg; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 69 | return c; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 70 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 71 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 72 | /* signed integer types */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 73 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 74 | template<> inline int parse_arg<int>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 75 | if(arg[0] == '\'') { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 76 | char c = parse_char(arg+1, &arg); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 77 | if(next != NULL) *next = arg+1; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 78 | return c; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 79 | } else { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 80 | return strtol(arg, const_cast<char**>(next), 0); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 81 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 82 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 83 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 84 | template<> inline char parse_arg<char>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 85 | return parse_arg<int>(arg,next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 86 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 87 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 88 | template<> inline short int parse_arg<short int>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 89 | return parse_arg<int>(arg,next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 90 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 91 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 92 | template<> inline long int parse_arg<long int>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 93 | return parse_arg<int>(arg,next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 94 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 95 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 96 | template<> inline long long parse_arg<long long>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 97 | return strtoll(arg, const_cast<char**>(next), 0); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 98 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 99 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 100 | /* unsigned integer types */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 101 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 102 | template<> inline unsigned int parse_arg<unsigned int>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 103 | if(arg[0] == '\'') { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 104 | char c = parse_char(arg+1, &arg); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 105 | if(next != NULL) *next = arg+1; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 106 | return c; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 107 | } else { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 108 | return strtoul(arg, const_cast<char**>(next), 0); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 109 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 110 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 111 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 112 | template<> inline unsigned char parse_arg<unsigned char>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 113 | return parse_arg<unsigned int>(arg,next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 114 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 115 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 116 | template<> inline unsigned short int parse_arg<unsigned short int>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 117 | return parse_arg<unsigned int>(arg,next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 118 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 119 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 120 | template<> inline unsigned long int parse_arg<unsigned long int>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 121 | return parse_arg<unsigned int>(arg,next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 122 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 123 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 124 | template<> inline unsigned long long parse_arg<unsigned long long>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 125 | return strtoull(arg, const_cast<char**>(next), 0); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 126 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 127 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 128 | /* floating types */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 129 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 130 | template<> inline float parse_arg<float>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 131 | #if !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 410000 |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 132 | return strtof(arg,const_cast<char**>(next)); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 133 | #elif __ARMCC_VERSION >= 310000 |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 134 | /* bug in header means no using declaration for strtof */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 135 | return std::strtof(arg,const_cast<char**>(next)); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 136 | #else |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 137 | /* strtof not supported */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 138 | return strtod(arg,const_cast<char**>(next)); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 139 | #endif |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 140 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 141 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 142 | template<> inline double parse_arg<double>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 143 | return strtod(arg,const_cast<char**>(next)); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 144 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 145 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 146 | template<> inline long double parse_arg<long double>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 147 | return strtod(arg,const_cast<char**>(next)); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 148 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 149 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 150 | /* string */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 151 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 152 | template<> inline char *parse_arg<char*>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 153 | const char *ptr = arg; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 154 | char *res = NULL; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 155 | if(*arg == '"') { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 156 | /* quoted string */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 157 | ptr = ++arg; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 158 | int len = 0; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 159 | /* find the end (and length) of the quoted string */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 160 | for(char c = *ptr; c != 0 && c != '"'; c = *++ptr) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 161 | len++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 162 | if(c == '\\') { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 163 | ptr++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 164 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 165 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 166 | /* copy the quoted string, and unescape characters */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 167 | if(len != 0) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 168 | res = new char[len+1]; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 169 | char *resptr = res; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 170 | while(arg != ptr) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 171 | *resptr++ = parse_char(arg, &arg); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 172 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 173 | *resptr = 0; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 174 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 175 | } else { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 176 | /* unquoted string */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 177 | while(isalnum(*ptr) || *ptr=='_') { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 178 | ptr++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 179 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 180 | int len = ptr-arg; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 181 | if(len!=0) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 182 | res = new char[len+1]; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 183 | memcpy(res, arg, len); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 184 | res[len] = 0; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 185 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 186 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 187 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 188 | if(next != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 189 | *next = ptr; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 190 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 191 | return res; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 192 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 193 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 194 | template<> inline const char *parse_arg<const char*>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 195 | return parse_arg<char*>(arg,next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 196 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 197 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 198 | /* Pins */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 199 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 200 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 201 | inline PinName parse_pins(const char *str) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 202 | const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14 |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 203 | , p15, p16, p17, p18, p19, p20, p21, p22, p23 |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 204 | , p24, p25, p26, p27, p28, p29, p30}; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 205 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 206 | if(str[0] == 'P') { // Pn_n |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 207 | uint32_t port = str[1] - '0'; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 208 | uint32_t pin = str[3] - '0'; // Pn_n |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 209 | uint32_t pin2 = str[4] - '0'; // Pn_nn |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 210 | if(pin2 <= 9) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 211 | pin = pin * 10 + pin2; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 212 | } |
emilmont | 28:667d61c9177b | 213 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 214 | return (PinName)(LPC_GPIO0_BASE + port * 32 + pin); |
emilmont | 28:667d61c9177b | 215 | #elif defined(TARGET_LPC11U24) |
emilmont | 28:667d61c9177b | 216 | return (PinName)(port * 32 + pin); |
emilmont | 28:667d61c9177b | 217 | #endif |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 218 | } else if(str[0] == 'p') { // pn |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 219 | uint32_t pin = str[1] - '0'; // pn |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 220 | uint32_t pin2 = str[2] - '0'; // pnn |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 221 | if(pin2 <= 9) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 222 | pin = pin * 10 + pin2; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 223 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 224 | if(pin < 5 || pin > 30) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 225 | return NC; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 226 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 227 | return pin_names[pin - 5]; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 228 | } else if(str[0] == 'L') { // LEDn |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 229 | switch(str[3]) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 230 | case '1' : return LED1; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 231 | case '2' : return LED2; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 232 | case '3' : return LED3; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 233 | case '4' : return LED4; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 234 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 235 | } else if(str[0] == 'U') { // USB?X |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 236 | switch(str[3]) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 237 | case 'T' : return USBTX; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 238 | case 'R' : return USBRX; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 239 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 240 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 241 | return NC; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 242 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 243 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 244 | template<> inline PinName parse_arg<PinName>(const char *arg, const char **next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 245 | const char *ptr = arg; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 246 | PinName pinname = NC; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 247 | while(isalnum(*ptr) || *ptr=='_') { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 248 | ptr++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 249 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 250 | int len = ptr-arg; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 251 | if(len!=0) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 252 | pinname = parse_pins(arg); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 253 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 254 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 255 | if(next != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 256 | *next = ptr; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 257 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 258 | return pinname; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 259 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 260 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 261 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 262 | /* Function write_result |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 263 | * Writes a value in to a result string in an appropriate manner |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 264 | * |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 265 | * Variable |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 266 | * val - The value to write |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 267 | * result - A pointer to the array to write the value into |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 268 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 269 | template<typename T> void write_result(T val, char *result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 270 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 271 | /* signed integer types */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 272 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 273 | template<> inline void write_result<char>(char val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 274 | result[0] = val; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 275 | result[1] = '\0'; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 276 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 277 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 278 | template<> inline void write_result<short int>(short int val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 279 | sprintf(result, "%hi", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 280 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 281 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 282 | template<> inline void write_result<int>(int val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 283 | sprintf(result, "%i", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 284 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 285 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 286 | template<> inline void write_result<long int>(long int val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 287 | sprintf(result, "%li", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 288 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 289 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 290 | template<> inline void write_result<long long int>(long long int val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 291 | sprintf(result, "%lli", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 292 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 293 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 294 | /* unsigned integer types */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 295 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 296 | template<> inline void write_result<unsigned char>(unsigned char val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 297 | result[0] = val; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 298 | result[1] = '\0'; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 299 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 300 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 301 | template<> inline void write_result<unsigned short int>(unsigned short int val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 302 | sprintf(result, "%hu", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 303 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 304 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 305 | template<> inline void write_result<unsigned int>(unsigned int val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 306 | sprintf(result, "%u", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 307 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 308 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 309 | template<> inline void write_result<unsigned long int>(unsigned long int val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 310 | sprintf(result, "%lu", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 311 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 312 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 313 | template<> inline void write_result<unsigned long long int>(unsigned long long int val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 314 | sprintf(result, "%llu", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 315 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 316 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 317 | /* floating types */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 318 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 319 | template<> inline void write_result<float>(float val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 320 | sprintf(result, "%.17g", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 321 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 322 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 323 | template<> inline void write_result<double>(double val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 324 | sprintf(result, "%.17g", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 325 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 326 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 327 | template<> inline void write_result<long double>(long double val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 328 | sprintf(result, "%.17Lg", val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 329 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 330 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 331 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 332 | /* string */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 333 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 334 | template<> inline void write_result<char*>(char *val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 335 | if(val==NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 336 | result[0] = 0; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 337 | } else { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 338 | strcpy(result, val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 339 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 340 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 341 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 342 | template<> inline void write_result<const char*>(const char *val, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 343 | if(val==NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 344 | result[0] = 0; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 345 | } else { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 346 | strcpy(result, val); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 347 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 348 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 349 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 350 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 351 | inline const char *next_arg(const char* next) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 352 | while(*next == ' ') next++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 353 | if(*next == ',' || *next == '?') next++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 354 | while(*next == ' ') next++; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 355 | return next; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 356 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 357 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 358 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 359 | /* Function rpc_method_caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 360 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 361 | template<class T, void (T::*member)(const char *,char *)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 362 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 363 | (static_cast<T*>(this_ptr)->*member)(arguments,result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 364 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 365 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 366 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 367 | /* Function rpc_method_caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 368 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 369 | template<class T, void (T::*member)()> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 370 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 371 | (static_cast<T*>(this_ptr)->*member)(); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 372 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 373 | result[0] = '\0'; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 374 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 375 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 376 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 377 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 378 | /* Function rpc_method_caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 379 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 380 | template<class T, typename A1, void (T::*member)(A1)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 381 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 382 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 383 | const char *next = arguments; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 384 | A1 arg1 = parse_arg<A1>(next_arg(next),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 385 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 386 | (static_cast<T*>(this_ptr)->*member)(arg1); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 387 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 388 | result[0] = '\0'; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 389 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 390 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 391 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 392 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 393 | /* Function rpc_method_caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 394 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 395 | template<class T, typename A1, typename A2, void (T::*member)(A1,A2)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 396 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 397 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 398 | const char *next = arguments; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 399 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 400 | A2 arg2 = parse_arg<A2>(next_arg(next),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 401 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 402 | (static_cast<T*>(this_ptr)->*member)(arg1,arg2); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 403 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 404 | result[0] = '\0'; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 405 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 406 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 407 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 408 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 409 | /* Function rpc_method_caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 410 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 411 | template<class T, typename A1, typename A2, typename A3, void (T::*member)(A1,A2,A3)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 412 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 413 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 414 | const char *next = arguments; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 415 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 416 | A2 arg2 = parse_arg<A2>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 417 | A3 arg3 = parse_arg<A3>(next_arg(next),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 418 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 419 | (static_cast<T*>(this_ptr)->*member)(arg1,arg2,arg3); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 420 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 421 | result[0] = '\0'; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 422 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 423 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 424 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 425 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 426 | /* Function rpc_method_caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 427 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 428 | template<typename R, class T, R (T::*member)()> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 429 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 430 | R res = (static_cast<T*>(this_ptr)->*member)(); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 431 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 432 | write_result<R>(res, result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 433 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 434 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 435 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 436 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 437 | /* Function rpc_method_caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 438 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 439 | template<typename R, class T, typename A1, R (T::*member)(A1)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 440 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 441 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 442 | const char *next = arguments; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 443 | A1 arg1 = parse_arg<A1>(next_arg(next),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 444 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 445 | R res = (static_cast<T*>(this_ptr)->*member)(arg1); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 446 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 447 | write_result<R>(res, result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 448 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 449 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 450 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 451 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 452 | /* Function rpc_method_caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 453 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 454 | template<typename R, class T, typename A1, typename A2, R (T::*member)(A1,A2)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 455 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 456 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 457 | const char *next = arguments; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 458 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 459 | A2 arg2 = parse_arg<A2>(next_arg(next),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 460 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 461 | R res = (static_cast<T*>(this_ptr)->*member)(arg1,arg2); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 462 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 463 | write_result<R>(res, result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 464 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 465 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 466 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 467 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 468 | /* Function rpc_method_caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 469 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 470 | template<typename R, class T, typename A1, typename A2, typename A3, R (T::*member)(A1,A2,A3)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 471 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 472 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 473 | const char *next = arguments; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 474 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 475 | A2 arg2 = parse_arg<A2>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 476 | A3 arg3 = parse_arg<A3>(next_arg(next),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 477 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 478 | R res = (static_cast<T*>(this_ptr)->*member)(arg1,arg2,arg3); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 479 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 480 | write_result<R>(res, result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 481 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 482 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 483 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 484 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 485 | /* Function rpc_function caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 486 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 487 | template<typename R, R (*func)()> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 488 | void rpc_function_caller(const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 489 | R res = (*func)(); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 490 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 491 | write_result<R>(res, result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 492 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 493 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 494 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 495 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 496 | /* Function rpc_function caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 497 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 498 | template<typename R, typename A1, R (*func)(A1)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 499 | void rpc_function_caller(const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 500 | A1 arg1 = parse_arg<A1>(next_arg(arguments),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 501 | R res = (*func)(arg1); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 502 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 503 | write_result<R>(res, result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 504 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 505 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 506 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 507 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 508 | /* Function rpc_function caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 509 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 510 | template<typename R, typename A1, typename A2, R (*func)(A1,A2)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 511 | void rpc_function_caller(const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 512 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 513 | const char *next = arguments; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 514 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 515 | A2 arg2 = parse_arg<A2>(next_arg(next),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 516 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 517 | R res = (*func)(arg1,arg2); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 518 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 519 | write_result<R>(res, result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 520 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 521 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 522 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 523 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 524 | /* Function rpc_function caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 525 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 526 | template<typename R, typename A1, typename A2, typename A3, R (*func)(A1,A2,A3)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 527 | void rpc_function_caller(const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 528 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 529 | const char *next = arguments; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 530 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 531 | A2 arg2 = parse_arg<A2>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 532 | A3 arg3 = parse_arg<A3>(next_arg(next),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 533 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 534 | R res = (*func)(arg1,arg2,arg3); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 535 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 536 | write_result<R>(res, result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 537 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 538 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 539 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 540 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 541 | /* Function rpc_function caller |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 542 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 543 | template<typename R, typename A1, typename A2, typename A3, typename A4, R (*func)(A1,A2,A3,A4)> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 544 | void rpc_function_caller(const char *arguments, char *result) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 545 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 546 | const char *next = arguments; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 547 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 548 | A2 arg2 = parse_arg<A2>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 549 | A3 arg3 = parse_arg<A3>(next_arg(next),&next); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 550 | A4 arg4 = parse_arg<A4>(next_arg(next),NULL); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 551 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 552 | R res = (*func)(arg1,arg2,arg3,arg4); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 553 | if(result != NULL) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 554 | write_result<R>(res, result); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 555 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 556 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 557 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 558 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 559 | struct rpc_method { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 560 | const char *name; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 561 | typedef void (*caller_t)(Base*, const char*, char*); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 562 | typedef const struct rpc_method *(*super_t)(Base*); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 563 | union { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 564 | caller_t caller; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 565 | super_t super; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 566 | }; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 567 | }; |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 568 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 569 | template<class C> |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 570 | const struct rpc_method *rpc_super(Base *this_ptr) { |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 571 | return static_cast<C*>(this_ptr)->C::get_rpc_methods(); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 572 | } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 573 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 574 | #define RPC_METHOD_END { NULL, NULL } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 575 | #define RPC_METHOD_SUPER(C) { NULL, (rpc_method::caller_t)(rpc_method::super_t)rpc_super<C> } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 576 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 577 | /* Function rpc |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 578 | * Parse a string describing a call and then do it |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 579 | * |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 580 | * Variables |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 581 | * call - A pointer to a string describing the call, which has |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 582 | * the form /object/method arg ... argn. Arguments are |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 583 | * delimited by space characters, and the string is terminated |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 584 | * by a null character. |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 585 | * result - A pointer to an array to write the result into. |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 586 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 587 | bool rpc(const char *buf, char *result = 0); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 588 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 589 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 590 | } // namespace mbed |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 591 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 592 | #endif |