Einfaches mbed RPC Beispiel

Dependencies:   EthernetInterface HttpServer mbed-rtos mbed

Fork of RPCHTTPServerSimple by th.iotkit2.ch

Remote Procedure Call (RPC - „Aufruf einer fernen Prozedur“) ist eine Technik zur Realisierung von Interprozesskommunikation. Sie ermöglicht den Aufruf von Funktionen in anderen Adressräumen. Im Normalfall werden die aufgerufenen Funktionen auf einem anderen Computer als das aufrufende Programm ausgeführt. Es existieren viele Implementierungen dieser Technik, in der Regel sind sie untereinander nicht kompatibel

Die mbed Plattform beinhaltet eine RPC Library, welche ausgesuchte mbed Objekte (DigitalPin, DigitalOut etc.) mittels Serieller Schnittstelle oder via HTTP Aufrufen, zur Verfügung stellt.

Die mbed RCP Klassen verwenden C++ Templates, siehe Zeilen mit <Argument> und den Namespace RPC, siehe Zeilen mit RPC::.

Client

Committer:
stefan1691
Date:
Wed Apr 08 12:31:41 2015 +0000
Revision:
11:43e28c85fd75
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 11:43e28c85fd75 1 /* mbed Microcontroller Library
stefan1691 11:43e28c85fd75 2 * Copyright (c) 2006-2013 ARM Limited
stefan1691 11:43e28c85fd75 3 *
stefan1691 11:43e28c85fd75 4 * Licensed under the Apache License, Version 2.0 (the "License");
stefan1691 11:43e28c85fd75 5 * you may not use this file except in compliance with the License.
stefan1691 11:43e28c85fd75 6 * You may obtain a copy of the License at
stefan1691 11:43e28c85fd75 7 *
stefan1691 11:43e28c85fd75 8 * http://www.apache.org/licenses/LICENSE-2.0
stefan1691 11:43e28c85fd75 9 *
stefan1691 11:43e28c85fd75 10 * Unless required by applicable law or agreed to in writing, software
stefan1691 11:43e28c85fd75 11 * distributed under the License is distributed on an "AS IS" BASIS,
stefan1691 11:43e28c85fd75 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
stefan1691 11:43e28c85fd75 13 * See the License for the specific language governing permissions and
stefan1691 11:43e28c85fd75 14 * limitations under the License.
stefan1691 11:43e28c85fd75 15 */
stefan1691 11:43e28c85fd75 16 #include "port_api.h"
stefan1691 11:43e28c85fd75 17
stefan1691 11:43e28c85fd75 18 namespace mbed {
stefan1691 11:43e28c85fd75 19
stefan1691 11:43e28c85fd75 20 PinName parse_pins(const char *str) {
stefan1691 11:43e28c85fd75 21 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
stefan1691 11:43e28c85fd75 22 static const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
stefan1691 11:43e28c85fd75 23 , p15, p16, p17, p18, p19, p20, p21, p22, p23
stefan1691 11:43e28c85fd75 24 , p24, p25, p26, p27, p28, p29, p30};
stefan1691 11:43e28c85fd75 25 #elif defined(TARGET_LPC1114)
stefan1691 11:43e28c85fd75 26 static const PinName pin_names[] = {dp1, dp2, dp4, dp5, dp6, dp9, dp10, dp11
stefan1691 11:43e28c85fd75 27 , dp13, dp14, dp15, dp16, dp17, dp18, dp23
stefan1691 11:43e28c85fd75 28 , dp24, dp25, dp26, dp27, dp28};
stefan1691 11:43e28c85fd75 29 #elif defined(TARGET_LPC4088)
stefan1691 11:43e28c85fd75 30 static const PinName pin_names[] = {NC, NC, NC, NC, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
stefan1691 11:43e28c85fd75 31 , p15, p16, p17, p18, p19, p20, NC, NC, p23
stefan1691 11:43e28c85fd75 32 , p24, p25, p26, p27, p28, p29, p30, p31, p32
stefan1691 11:43e28c85fd75 33 , p33, p34, NC, NC, p37, p38, p39, NC, NC, NC, NC, NC, NC, NC};
stefan1691 11:43e28c85fd75 34 #elif defined(TARGET_LPC4088_DM)
stefan1691 11:43e28c85fd75 35 static const PinName pin_names[] = {p1, p2, p3, p4, NC, NC, p7, p8, p9, p10, p11, p12, p13, p14
stefan1691 11:43e28c85fd75 36 , p15, p16, p17, p18, p19, p20, p21, p22, p23
stefan1691 11:43e28c85fd75 37 , p24, p25, p26, NC, NC, p29, p30, NC, NC
stefan1691 11:43e28c85fd75 38 , NC, NC, NC, NC, NC, NC, NC, NC, p41, p42, p43, p44, p45, p46};
stefan1691 11:43e28c85fd75 39 #endif
stefan1691 11:43e28c85fd75 40
stefan1691 11:43e28c85fd75 41 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC812) || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC1114)
stefan1691 11:43e28c85fd75 42 if (str[0] == 'P') { // Pn_n
stefan1691 11:43e28c85fd75 43 uint32_t port = str[1] - '0';
stefan1691 11:43e28c85fd75 44 uint32_t pin = str[3] - '0'; // Pn_n
stefan1691 11:43e28c85fd75 45 uint32_t pin2 = str[4] - '0'; // Pn_nn
stefan1691 11:43e28c85fd75 46 if (pin2 <= 9) {
stefan1691 11:43e28c85fd75 47 pin = pin * 10 + pin2;
stefan1691 11:43e28c85fd75 48 }
stefan1691 11:43e28c85fd75 49 return port_pin((PortName)port, pin);
stefan1691 11:43e28c85fd75 50
stefan1691 11:43e28c85fd75 51 #elif defined(TARGET_KL25Z) || defined(TARGET_KL05Z) || defined(TARGET_KL46Z) || defined(TARGET_K64F)
stefan1691 11:43e28c85fd75 52 if (str[0] == 'P' && str[1] == 'T') { // PTxn
stefan1691 11:43e28c85fd75 53 uint32_t port = str[2] - 'A';
stefan1691 11:43e28c85fd75 54 uint32_t pin = str[3] - '0'; // PTxn
stefan1691 11:43e28c85fd75 55 uint32_t pin2 = str[4] - '0'; // PTxnn
stefan1691 11:43e28c85fd75 56
stefan1691 11:43e28c85fd75 57 if (pin2 <= 9) {
stefan1691 11:43e28c85fd75 58 pin = pin * 10 + pin2;
stefan1691 11:43e28c85fd75 59 }
stefan1691 11:43e28c85fd75 60 return port_pin((PortName)port, pin);
stefan1691 11:43e28c85fd75 61 #endif
stefan1691 11:43e28c85fd75 62
stefan1691 11:43e28c85fd75 63 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
stefan1691 11:43e28c85fd75 64 } else if (str[0] == 'p') { // pn
stefan1691 11:43e28c85fd75 65 uint32_t pin = str[1] - '0'; // pn
stefan1691 11:43e28c85fd75 66 uint32_t pin2 = str[2] - '0'; // pnn
stefan1691 11:43e28c85fd75 67 if (pin2 <= 9) {
stefan1691 11:43e28c85fd75 68 pin = pin * 10 + pin2;
stefan1691 11:43e28c85fd75 69 }
stefan1691 11:43e28c85fd75 70 if (pin < 5 || pin > 30) {
stefan1691 11:43e28c85fd75 71 return NC;
stefan1691 11:43e28c85fd75 72 }
stefan1691 11:43e28c85fd75 73 return pin_names[pin - 5];
stefan1691 11:43e28c85fd75 74 #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
stefan1691 11:43e28c85fd75 75 } else if (str[0] == 'p') { // pn
stefan1691 11:43e28c85fd75 76 uint32_t pin = str[1] - '0'; // pn
stefan1691 11:43e28c85fd75 77 uint32_t pin2 = str[2] - '0'; // pnn
stefan1691 11:43e28c85fd75 78 if (pin2 <= 9) {
stefan1691 11:43e28c85fd75 79 pin = pin * 10 + pin2;
stefan1691 11:43e28c85fd75 80 }
stefan1691 11:43e28c85fd75 81 if (pin < 1 || pin > 46) {
stefan1691 11:43e28c85fd75 82 return NC;
stefan1691 11:43e28c85fd75 83 }
stefan1691 11:43e28c85fd75 84 return pin_names[pin - 1];
stefan1691 11:43e28c85fd75 85 #endif
stefan1691 11:43e28c85fd75 86
stefan1691 11:43e28c85fd75 87 } else if (str[0] == 'L') { // LEDn
stefan1691 11:43e28c85fd75 88 switch (str[3]) {
stefan1691 11:43e28c85fd75 89 case '1' : return LED1;
stefan1691 11:43e28c85fd75 90 case '2' : return LED2;
stefan1691 11:43e28c85fd75 91 case '3' : return LED3;
stefan1691 11:43e28c85fd75 92 case '4' : return LED4;
stefan1691 11:43e28c85fd75 93 }
stefan1691 11:43e28c85fd75 94
stefan1691 11:43e28c85fd75 95 } else if (str[0] == 'U') { // USB?X
stefan1691 11:43e28c85fd75 96 switch (str[3]) {
stefan1691 11:43e28c85fd75 97 case 'T' : return USBTX;
stefan1691 11:43e28c85fd75 98 case 'R' : return USBRX;
stefan1691 11:43e28c85fd75 99 }
stefan1691 11:43e28c85fd75 100 }
stefan1691 11:43e28c85fd75 101
stefan1691 11:43e28c85fd75 102 return NC;
stefan1691 11:43e28c85fd75 103 }
stefan1691 11:43e28c85fd75 104
stefan1691 11:43e28c85fd75 105 }