![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
1st Released
Dependencies: MbedJSONValue WIZnetInterface mbed
Fork of WIZwiki-REST by
Revision 1:728e5b5c8dae, committed 2016-04-05
- Comitter:
- MidnightCow
- Date:
- Tue Apr 05 11:40:33 2016 +0000
- Parent:
- 0:5886f525a4ad
- Commit message:
- 1st Released
Changed in this revision
--- a/HTTPServer.h Wed Mar 02 03:28:08 2016 +0000 +++ b/HTTPServer.h Tue Apr 05 11:40:33 2016 +0000 @@ -17,8 +17,8 @@ }HTTP_RESULT; -static char HTTPBUF[1024] ={0,}; -static char rest_result[1024] = {0,}; +static char HTTPBUF[512] ={0,}; +static char rest_result[512] = {0,}; class HTTPServer {
--- a/MbedJSONValue.lib Wed Mar 02 03:28:08 2016 +0000 +++ b/MbedJSONValue.lib Tue Apr 05 11:40:33 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/joon874/code/MbedJSONValue/#e15fd7be9e74 +https://developer.mbed.org/users/MidnightCow/code/MbedJSONValue/#f8bec9cada34
--- a/RequestHandler.cpp Wed Mar 02 03:28:08 2016 +0000 +++ b/RequestHandler.cpp Tue Apr 05 11:40:33 2016 +0000 @@ -23,26 +23,75 @@ tok = strtok_r(rest_uri+1, "/", &last); // 20160226 tmpJson = &WIZwikiREST; + char depth = 0; + char* name = 0; while(tok) { - printf("tok = %s \r\n", tok); // Name - if(tmpJson->size() > 0) tmpJson = &((*tmpJson)[tok]); - else - { - tmpJson = 0; - break; - } - tok = strtok_r(0, "/", &last); // 20160226 - } - if(tmpJson && tmpJson->size() > 0) + printf("tok = %s \r\n", tok); // Name + if(tmpJson->hasMember(tok)) { - strcpy(reply, (*tmpJson).serialize().c_str()); - } + tmpJson = &((*tmpJson)[tok]); + name = tok; + tok = strtok_r(0, "/", &last); + depth++; + } else { - strcpy(reply, "{\"Result\" : \"No defined Resource\"}"); + printf("No Member\r\n"); + break; } + } + /* + if(tmpJson && tmpJson->size() > 0) + { + strcpy(reply, (*tmpJson).serialize().c_str()); + } + else + { + strcpy(reply, "{\"Result\" : \"No defined Resource\"}"); + } + */ + /* + if(name) + { + printf("name=%s, tok=%s\r\n",name,tok); + if(tok) + { + if(depth == 2) + { + if(!strcmp(name, "MAC")) + strcpy(reply, "{\"Result\" : \"No Accessible\"}"); + else + { + if(tmpJson->size() > 0) *tmpJson = std::string(tok); + else *tmpJson = atoi(tok); + strcpy(reply, (*tmpJson).serialize().c_str()); + } + } + else if(depth == 1) strcpy(reply, "{\"Result : No Accessible\"}"); + } + else strcpy(reply, (*tmpJson).serialize().c_str()); return; + } + strcpy(reply, "{\"Result\" : \"No defined Resource\"}"); + */ + if(name) + { + if(tok) + { + if(tmpJson->accessible) + { + printf("accessible : tmpJson->size()=%d\r\n",tmpJson->size()); + if(tmpJson->size() > 0) {*tmpJson = std::string(tok); tmpJson->cb_action((void*)tok); printf("set string:%s\r\n",tok);} + else {*tmpJson = atoi(tok); tmpJson->cb_action(&tmpJson->_value); printf("set int:%d\r\n",atoi(tok));} + strcpy(reply, (*tmpJson).serialize().c_str()); + } + else strcpy(reply, "{\"Result : No Accessible\"}"); + } + else strcpy(reply, (*tmpJson).serialize().c_str()); + } + else strcpy(reply, "{\"Result\" : \"No defined Resource\"}"); + return; } void PutRequestHandler::handle(char* rest_uri, char *reply)
--- a/main.cpp Wed Mar 02 03:28:08 2016 +0000 +++ b/main.cpp Tue Apr 05 11:40:33 2016 +0000 @@ -20,27 +20,236 @@ DigitalOut LED_1(PA_1); DigitalOut LED_2(PA_2); -DigitalInOut P05(P5); -DigitalInOut P06(P6); +DigitalInOut GP05(P5); +DigitalInOut GP06(P6); +DigitalInOut GP07(P7); +DigitalInOut GP08(P8); +DigitalInOut GP09(P9); +DigitalInOut GP10(P10); +DigitalInOut GP11(P11); +DigitalInOut GP12(P12); +DigitalInOut GP13(P13); +DigitalInOut GP14(P14); +DigitalInOut GP15(P15); +DigitalInOut GP16(P16); +DigitalInOut GP17(P17); +DigitalInOut GP18(P18); +DigitalInOut GP19(P19); +DigitalInOut GP20(P20); +DigitalInOut GP21(P21); +DigitalInOut GP22(P22); +DigitalInOut GP23(P23); +DigitalInOut GP24(P24); +DigitalInOut GP25(P25); +DigitalInOut GP26(P26); +DigitalInOut GP27(P27); +DigitalInOut GP28(P28); +DigitalInOut GP29(P29); +DigitalInOut GP30(P30); +DigitalInOut GP31(P31); +DigitalInOut GP32(P32); +bool p5_set(void* param) +{ + if(!param) return false; + GP05.write(*(int*)param); + return true; +} +bool p6_set(void* param) +{ + if(!param) return false; + GP06.write(*(int*)param); + return true; +} +bool p7_set(void* param) +{ + if(!param) return false; + GP07.write(*(int*)param); + return true; +} +bool p8_set(void* param) +{ + if(!param) return false; + GP08.write(*(int*)param); + return true; +} +bool p9_set(void* param) +{ + if(!param) return false; + GP09.write(*(int*)param); + return true; +} +bool p10_set(void* param) +{ + if(!param) return false; + GP10.write(*(int*)param); + return true; +} +bool p11_set(void* param) +{ + if(!param) return false; + GP11.write(*(int*)param); + return true; +} +bool p12_set(void* param) +{ + if(!param) return false; + GP12.write(*(int*)param); + return true; +} +bool p13_set(void* param) +{ + if(!param) return false; + GP13.write(*(int*)param); + return true; +} +bool p14_set(void* param) +{ + if(!param) return false; + GP14.write(*(int*)param); + return true; +} +bool p15_set(void* param) +{ + if(!param) return false; + GP15.write(*(int*)param); + return true; +} +bool p16_set(void* param) +{ + if(!param) return false; + GP16.write(*(int*)param); + return true; +} +bool p17_set(void* param) +{ + if(!param) return false; + GP17.write(*(int*)param); + return true; +} +bool p18_set(void* param) +{ + if(!param) return false; + GP18.write(*(int*)param); + return true; +} +bool p19_set(void* param) +{ + if(!param) return false; + GP19.write(*(int*)param); + return true; +} +bool p20_set(void* param) +{ + if(!param) return false; + GP20.write(*(int*)param); + return true; +} +bool p21_set(void* param) +{ + if(!param) return false; + GP21.write(*(int*)param); + return true; +} +bool p22_set(void* param) +{ + if(!param) return false; + GP22.write(*(int*)param); + return true; +} +bool p23_set(void* param) +{ + if(!param) return false; + GP23.write(*(int*)param); + return true; +} +bool p24_set(void* param) +{ + if(!param) return false; + GP24.write(*(int*)param); + return true; +} +bool p25_set(void* param) +{ + if(!param) return false; + GP25.write(*(int*)param); + return true; +} +bool p26_set(void* param) +{ + if(!param) return false; + GP26.write(*(int*)param); + return true; +} +bool p27_set(void* param) +{ + if(!param) return false; + GP27.write(*(int*)param); + return true; +} +bool p28_set(void* param) +{ + if(!param) return false; + GP28.write(*(int*)param); + return true; +} +bool p29_set(void* param) +{ + if(!param) return false; + GP29.write(*(int*)param); + return true; +} +bool p30_set(void* param) +{ + if(!param) return false; + GP30.write(*(int*)param); + return true; +} +bool p31_set(void* param) +{ + if(!param) return false; + GP31.write(*(int*)param); + return true; +} +bool p32_set(void* param) +{ + if(!param) return false; + GP32.write(*(int*)param); + return true; +} + +void debug_info() +{ + printf("SP:0x%X\r\n",__current_sp()); + __heapstats((__heapprt)fprintf,stderr); + printf("\r\n"); +} void WIZwiki_REST_init(); int main(void) { + sprintf(mac_str, "%02X:%02X:%02X:%02X:%02X:%02X",mac_addr[0],mac_addr[1], mac_addr[2],mac_addr[3], mac_addr[4],mac_addr[5]); //GPIO Set - P05.output(); - P05.write(1); - P06.input(); - + GP05.output(); + GP05.write(0); + GP06.input(); + //LED Setbit LED_1.write(0); // LED On LED_2.write(1); // LED Off + printf("START \r\n"); + printf("sizeof(MbedJSONValue)=%d\r\n",sizeof(MbedJSONValue)); + printf("sizeof(vector)=%d\r\n",sizeof(std::vector<string*>)); + printf("sizeof(string)=%d\r\n",sizeof(std::string)); + debug_info(); WIZwiki_REST_init(); - + + debug_info(); + // Serialize it into a JSON string printf("\r\n"); printf("-------------------------WIZwikiREST--------------------------- \r\n"); @@ -83,71 +292,117 @@ void WIZwiki_REST_init(void) { //Fill the object - WIZwikiREST["Name"] = "WIZwiki-REST-01"; + WIZwikiREST["Name"] = "WIZwiki-RESTful-01"; + WIZwikiREST["Name"].accessible = false; + debug_info(); + //Network + WIZwikiREST["Network"]["MAC"] = mac_str; + debug_info(); WIZwikiREST["Network"]["IP"] = ip_addr; + WIZwikiREST["Network"]["IP"].accessible = true; + debug_info(); WIZwikiREST["Network"]["SN"] = subnet_mask; + WIZwikiREST["Network"]["SN"].accessible = true; + debug_info(); WIZwikiREST["Network"]["GW"] = gateway_addr; + WIZwikiREST["Network"]["GW"].accessible = true; + debug_info(); + //LEDs - WIZwikiREST["LEDs"]["LED_1"]["Value"] = (LED_1.read() ? "Off" : "On"); - WIZwikiREST["LEDs"]["LED_2"]["Value"] = (LED_2.read() ? "Off" : "On"); - + WIZwikiREST["LED1"] = (LED_1.read() ? "Off" : "On"); + WIZwikiREST["LED1"].accessible = true; + debug_info(); + WIZwikiREST["LED2"] = (LED_2.read() ? "Off" : "On"); + WIZwikiREST["LED2"].accessible = true; + debug_info(); // GPIOs - WIZwikiREST["GPIOs"]["P05"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_5) ? "Output" : "Input"); - WIZwikiREST["GPIOs"]["P05"]["Value"] = (P05.read() ? "1" : "0"); - WIZwikiREST["GPIOs"]["P06"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_6) ? "Output" : "Input"); - WIZwikiREST["GPIOs"]["P06"]["Value"] = (P06.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P07"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_7) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P07"]["Value"] = (P07.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P08"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_8) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P08"]["Value"] = (P08.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P09"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_9) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P09"]["Value"] = (P09.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P10"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_10) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P10"]["Value"] = (P10.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P11"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_11) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P11"]["Value"] = (P11.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P12"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_12) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P12"]["Value"] = (P12.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P13"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_13) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P13"]["Value"] = (P13.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P14"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_14) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P14"]["Value"] = (P14.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P15"]["Mode"] = ((GPIOB->OUTENSET&GPIO_Pin_0) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P15"]["Value"] = (P15.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P16"]["Mode"] = ((GPIOB->OUTENSET&GPIO_Pin_1) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P16"]["Value"] = (P16.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P17"]["Mode"] = ((GPIOB->OUTENSET&GPIO_Pin_2) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P17"]["Value"] = (P17.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P18"]["Mode"] = ((GPIOB->OUTENSET&GPIO_Pin_3) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P18"]["Value"] = (P18.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P19"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_8) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P19"]["Value"] = (P19.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P20"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_4) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P20"]["Value"] = (P20.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P21"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_0) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P21"]["Value"] = (P21.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P22"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_1) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P22"]["Value"] = (P22.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P23"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_2) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P23"]["Value"] = (P23.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P24"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_3) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P24"]["Value"] = (P24.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P25"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_9) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P25"]["Value"] = (P25.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P26"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_5) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P26"]["Value"] = (P26.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P27"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_12) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P27"]["Value"] = (P27.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P28"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_13) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P28"]["Value"] = (P28.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P29"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_14) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P29"]["Value"] = (P29.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P30"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_15) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P30"]["Value"] = (P30.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P31"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_6) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P31"]["Value"] = (P31.read() ? "1" : "0"); -// WIZwikiREST["GPIOs"]["P32"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_7) ? "Output" : "Input"); -// WIZwikiREST["GPIOs"]["P32"]["Value"] = (P32.read() ? "1" : "0"); + WIZwikiREST["GPIOs"]["P05"] = GP05.read(); + WIZwikiREST["GPIOs"]["P05"].accessible = true; + WIZwikiREST["GPIOs"]["P05"].cb_action = p5_set; + WIZwikiREST["GPIOs"]["P06"] = GP06.read(); + WIZwikiREST["GPIOs"]["P06"].accessible = true; + WIZwikiREST["GPIOs"]["P06"].cb_action = p6_set; + WIZwikiREST["GPIOs"]["P07"] = GP07.read(); + WIZwikiREST["GPIOs"]["P07"].accessible = true; + WIZwikiREST["GPIOs"]["P07"].cb_action = p7_set; + WIZwikiREST["GPIOs"]["P08"] = GP08.read(); + WIZwikiREST["GPIOs"]["P08"].accessible = true; + WIZwikiREST["GPIOs"]["P08"].cb_action = p8_set; + WIZwikiREST["GPIOs"]["P09"] = GP09.read(); + WIZwikiREST["GPIOs"]["P09"].accessible = true; + WIZwikiREST["GPIOs"]["P09"].cb_action = p9_set; + WIZwikiREST["GPIOs"]["P10"] = GP10.read(); + WIZwikiREST["GPIOs"]["P10"].accessible = true; + WIZwikiREST["GPIOs"]["P10"].cb_action = p10_set; + WIZwikiREST["GPIOs"]["P11"] = GP11.read(); + WIZwikiREST["GPIOs"]["P11"].accessible = true; + WIZwikiREST["GPIOs"]["P11"].cb_action = p11_set; + WIZwikiREST["GPIOs"]["P12"] = GP12.read(); + WIZwikiREST["GPIOs"]["P12"].accessible = true; + WIZwikiREST["GPIOs"]["P12"].cb_action = p12_set; + WIZwikiREST["GPIOs"]["P13"] = GP13.read(); + WIZwikiREST["GPIOs"]["P13"].accessible = true; + WIZwikiREST["GPIOs"]["P13"].cb_action = p13_set; + WIZwikiREST["GPIOs"]["P14"] = GP14.read(); + WIZwikiREST["GPIOs"]["P14"].accessible = true; + WIZwikiREST["GPIOs"]["P14"].cb_action = p14_set; + WIZwikiREST["GPIOs"]["P15"] = GP15.read(); + WIZwikiREST["GPIOs"]["P15"].accessible = true; + WIZwikiREST["GPIOs"]["P15"].cb_action = p15_set; + WIZwikiREST["GPIOs"]["P16"] = GP16.read(); + WIZwikiREST["GPIOs"]["P16"].accessible = true; + WIZwikiREST["GPIOs"]["P16"].cb_action = p16_set; + WIZwikiREST["GPIOs"]["P17"] = GP17.read(); + WIZwikiREST["GPIOs"]["P17"].accessible = true; + WIZwikiREST["GPIOs"]["P17"].cb_action = p17_set; + WIZwikiREST["GPIOs"]["P18"] = GP18.read(); + WIZwikiREST["GPIOs"]["P18"].accessible = true; + WIZwikiREST["GPIOs"]["P18"].cb_action = p18_set; + WIZwikiREST["GPIOs"]["P19"] = GP19.read(); + WIZwikiREST["GPIOs"]["P19"].accessible = true; + WIZwikiREST["GPIOs"]["P19"].cb_action = p19_set; + WIZwikiREST["GPIOs"]["P20"] = GP20.read(); + WIZwikiREST["GPIOs"]["P20"].accessible = true; + WIZwikiREST["GPIOs"]["P20"].cb_action = p20_set; + WIZwikiREST["GPIOs"]["P21"] = GP21.read(); + WIZwikiREST["GPIOs"]["P21"].accessible = true; + WIZwikiREST["GPIOs"]["P21"].cb_action = p21_set; + WIZwikiREST["GPIOs"]["P22"] = GP22.read(); + WIZwikiREST["GPIOs"]["P22"].accessible = true; + WIZwikiREST["GPIOs"]["P22"].cb_action = p22_set; + + WIZwikiREST["GPIOs"]["P23"] = GP23.read(); + WIZwikiREST["GPIOs"]["P23"].accessible = true; + WIZwikiREST["GPIOs"]["P23"].cb_action = p23_set; + WIZwikiREST["GPIOs"]["P24"] = GP24.read(); + WIZwikiREST["GPIOs"]["P24"].accessible = true; + WIZwikiREST["GPIOs"]["P24"].cb_action = p24_set; + WIZwikiREST["GPIOs"]["P25"] = GP25.read(); + WIZwikiREST["GPIOs"]["P25"].accessible = true; + WIZwikiREST["GPIOs"]["P25"].cb_action = p25_set; + WIZwikiREST["GPIOs"]["P26"] = GP26.read(); + WIZwikiREST["GPIOs"]["P26"].accessible = true; + WIZwikiREST["GPIOs"]["P26"].cb_action = p26_set; + WIZwikiREST["GPIOs"]["P27"] = GP27.read(); + WIZwikiREST["GPIOs"]["P27"].accessible = true; + WIZwikiREST["GPIOs"]["P27"].cb_action = p27_set; + WIZwikiREST["GPIOs"]["P28"] = GP28.read(); + WIZwikiREST["GPIOs"]["P28"].accessible = true; + WIZwikiREST["GPIOs"]["P28"].cb_action = p28_set; + WIZwikiREST["GPIOs"]["P29"] = GP29.read(); + WIZwikiREST["GPIOs"]["P29"].accessible = true; + WIZwikiREST["GPIOs"]["P29"].cb_action = p29_set; + WIZwikiREST["GPIOs"]["P30"] = GP30.read(); + WIZwikiREST["GPIOs"]["P30"].accessible = true; + WIZwikiREST["GPIOs"]["P30"].cb_action = p30_set; + WIZwikiREST["GPIOs"]["P31"] = GP31.read(); + WIZwikiREST["GPIOs"]["P31"].accessible = true; + WIZwikiREST["GPIOs"]["P31"].cb_action = p31_set; + WIZwikiREST["GPIOs"]["P32"] = GP32.read(); + WIZwikiREST["GPIOs"]["P32"].accessible = true; + WIZwikiREST["GPIOs"]["P32"].cb_action = p32_set; + + debug_info(); }