各ピンへのread/writeを提供するサーバサンプル

Dependencies:   NySNICInterface mbed-rtos mbed

Fork of RESTServerSample2 by KDDI Fx0 hackathon

Committer:
komoritan
Date:
Thu Mar 12 12:40:48 2015 +0000
Revision:
1:e5d3bd4af9da
Parent:
0:998e2e00df0c
Bug fix - handle_request

Who changed what in which revision?

UserRevisionLine numberNew contents of line
komoritan 0:998e2e00df0c 1 /* mbed Microcontroller Library
komoritan 0:998e2e00df0c 2 * Copyright (c) 2006-2013 ARM Limited
komoritan 0:998e2e00df0c 3 *
komoritan 0:998e2e00df0c 4 * Licensed under the Apache License, Version 2.0 (the "License");
komoritan 0:998e2e00df0c 5 * you may not use this file except in compliance with the License.
komoritan 0:998e2e00df0c 6 * You may obtain a copy of the License at
komoritan 0:998e2e00df0c 7 *
komoritan 0:998e2e00df0c 8 * http://www.apache.org/licenses/LICENSE-2.0
komoritan 0:998e2e00df0c 9 *
komoritan 0:998e2e00df0c 10 * Unless required by applicable law or agreed to in writing, software
komoritan 0:998e2e00df0c 11 * distributed under the License is distributed on an "AS IS" BASIS,
komoritan 0:998e2e00df0c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
komoritan 0:998e2e00df0c 13 * See the License for the specific language governing permissions and
komoritan 0:998e2e00df0c 14 * limitations under the License.
komoritan 0:998e2e00df0c 15 */
komoritan 0:998e2e00df0c 16 #include "port_api.h"
komoritan 0:998e2e00df0c 17
komoritan 0:998e2e00df0c 18 namespace mbed {
komoritan 0:998e2e00df0c 19
komoritan 0:998e2e00df0c 20 PinName parse_pins(const char *str) {
komoritan 0:998e2e00df0c 21 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
komoritan 0:998e2e00df0c 22 static const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
komoritan 0:998e2e00df0c 23 , p15, p16, p17, p18, p19, p20, p21, p22, p23
komoritan 0:998e2e00df0c 24 , p24, p25, p26, p27, p28, p29, p30};
komoritan 0:998e2e00df0c 25 #endif
komoritan 0:998e2e00df0c 26
komoritan 0:998e2e00df0c 27 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC812) || defined(TARGET_LPC4088)
komoritan 0:998e2e00df0c 28 if (str[0] == 'P') { // Pn_n
komoritan 0:998e2e00df0c 29 uint32_t port = str[1] - '0';
komoritan 0:998e2e00df0c 30 uint32_t pin = str[3] - '0'; // Pn_n
komoritan 0:998e2e00df0c 31 uint32_t pin2 = str[4] - '0'; // Pn_nn
komoritan 0:998e2e00df0c 32 if (pin2 <= 9) {
komoritan 0:998e2e00df0c 33 pin = pin * 10 + pin2;
komoritan 0:998e2e00df0c 34 }
komoritan 0:998e2e00df0c 35 return port_pin((PortName)port, pin);
komoritan 0:998e2e00df0c 36
komoritan 0:998e2e00df0c 37 #elif defined(TARGET_KL25Z)
komoritan 0:998e2e00df0c 38 if (str[0] == 'P' && str[1] == 'T') { // PTx_n
komoritan 0:998e2e00df0c 39 uint32_t port = str[2] - 'A';
komoritan 0:998e2e00df0c 40 uint32_t pin = str[3] - '0'; // PTxn
komoritan 0:998e2e00df0c 41 uint32_t pin2 = str[4] - '0'; // PTxnn
komoritan 0:998e2e00df0c 42
komoritan 0:998e2e00df0c 43 if (pin2 <= 9) {
komoritan 0:998e2e00df0c 44 pin = pin * 10 + pin2;
komoritan 0:998e2e00df0c 45 }
komoritan 0:998e2e00df0c 46 return port_pin((PortName)port, pin);
komoritan 0:998e2e00df0c 47 #endif
komoritan 0:998e2e00df0c 48
komoritan 0:998e2e00df0c 49 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
komoritan 0:998e2e00df0c 50 } else if (str[0] == 'p') { // pn
komoritan 0:998e2e00df0c 51 uint32_t pin = str[1] - '0'; // pn
komoritan 0:998e2e00df0c 52 uint32_t pin2 = str[2] - '0'; // pnn
komoritan 0:998e2e00df0c 53 if (pin2 <= 9) {
komoritan 0:998e2e00df0c 54 pin = pin * 10 + pin2;
komoritan 0:998e2e00df0c 55 }
komoritan 0:998e2e00df0c 56 if (pin < 5 || pin > 30) {
komoritan 0:998e2e00df0c 57 return NC;
komoritan 0:998e2e00df0c 58 }
komoritan 0:998e2e00df0c 59 return pin_names[pin - 5];
komoritan 0:998e2e00df0c 60 #endif
komoritan 0:998e2e00df0c 61
komoritan 0:998e2e00df0c 62 } else if (str[0] == 'L') { // LEDn
komoritan 0:998e2e00df0c 63 switch (str[3]) {
komoritan 0:998e2e00df0c 64 case '1' : return LED1;
komoritan 0:998e2e00df0c 65 case '2' : return LED2;
komoritan 0:998e2e00df0c 66 case '3' : return LED3;
komoritan 0:998e2e00df0c 67 case '4' : return LED4;
komoritan 0:998e2e00df0c 68 }
komoritan 0:998e2e00df0c 69
komoritan 0:998e2e00df0c 70 } else if (str[0] == 'U') { // USB?X
komoritan 0:998e2e00df0c 71 switch (str[3]) {
komoritan 0:998e2e00df0c 72 case 'T' : return USBTX;
komoritan 0:998e2e00df0c 73 case 'R' : return USBRX;
komoritan 0:998e2e00df0c 74 }
komoritan 0:998e2e00df0c 75 }
komoritan 0:998e2e00df0c 76
komoritan 0:998e2e00df0c 77 return NC;
komoritan 0:998e2e00df0c 78 }
komoritan 0:998e2e00df0c 79
komoritan 0:998e2e00df0c 80 }