Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of dgps by
Diff: packet.h
- Revision:
- 18:e72ee7aed088
- Parent:
- 16:4f5d20b87dc3
- Child:
- 19:8c1f2a2204fb
--- a/packet.h Sat Apr 19 14:39:19 2014 +0000 +++ b/packet.h Sun Apr 20 08:04:37 2014 +0000 @@ -1,3 +1,5 @@ +#include <InterruptIn.h> + #define PACKETSIZE 256 // Example @@ -36,11 +38,17 @@ #else USB::getSerial() #endif + ),setTCPConStatus( + XBEE::getTCPConOut() + ),getTCPConStatus( + XBEE::getTCPConIn() ),next(NULL){ //outputDevice.attach(this,&PacketSender::handleUpdate,Serial::RxIrq); lastValid=NULL; } Serial& outputDevice; + DigitalOut& setTCPConStatus; + DigitalIn& getTCPConStatus; void sendPacket(PacketStruct& output){ for(int a=0;a<sizeof(PacketStruct);a++){ while(!outputDevice.writeable()){} @@ -50,6 +58,117 @@ } //wait_ms(100); } + + void wait_for_egg(){ + char response[40]; + while(1){ + while(!outputDevice.readable()){} + outputDevice.scanf("%s",response); + if(strcmp(response,"DHCP:") == 0){ + USB::getSerial().printf("Egg Connected!\r\n"); + for(int a=0;a<100000000;a++); + while(outputDevice.readable()){ + outputDevice.getc(); + } + return; + } + } + } + + void openConnection(char close_conn = 0){ + __disable_irq(); + while(!getTCPConStatus){ + setTCPConStatus = 0; + wait_us(500000); + setTCPConStatus = 1; + wait_us(500000); + } + __enable_irq(); + //for(int a=0;a<10000000;a++); +// char connected = 0; +// char in_cmd_mode = 0; +// char response[80]; +// int charcount; +// +// while(in_cmd_mode == 0){ +// //get into command mode +// while(!outputDevice.writeable()){} +// outputDevice.putc('$'); +// while(!outputDevice.writeable()){} +// outputDevice.putc('$'); +// while(!outputDevice.writeable()){} +// outputDevice.putc('$'); +// while(!outputDevice.writeable()){} +// while(!outputDevice.readable()){} +// //outputDevice.scanf("%s",response); +// charcount = 0; +// while(outputDevice.readable()){ +// response[charcount] = outputDevice.getc(); +// charcount++; +// for(int a=0;a<10000;a++); +// } +// response[charcount] = 0; +// USB::getSerial().printf("%s",response); +// if(strcmp(response+strlen(response)-5,"CMD\r\n") == 0){ +// in_cmd_mode = 1; +// }else{ +// while(1); +// } +// USB::getSerial().printf("in cmd mode: %d\r\n",in_cmd_mode); +// } +// //open the connection! +// while(connected == 0){ +// for(int a=0;a<10000000;a++); +// while(!outputDevice.writeable()){} +// if(close_conn){ +// outputDevice.printf("close"); +// while(!outputDevice.writeable()){} +// outputDevice.putc(0); +// while(!outputDevice.writeable()){} +// outputDevice.printf("exit"); +// }else{ +// outputDevice.printf("open 1.2.3.14 7000"); +// } +// while(!outputDevice.writeable()){} +// outputDevice.putc(0); +// while(!outputDevice.writeable()){} +// if(0 && !close_conn){ +// for(int a=0;a<5;a++){ +// while(!outputDevice.readable()){} +// outputDevice.scanf("%s",response); +// USB::getSerial().printf("%s ",response); +// } +// } +// while(!outputDevice.readable()){} +// for(int a=0;a<10000000;a++); +// charcount = 0; +// while(outputDevice.readable()){ +// response[charcount] = outputDevice.getc(); +// USB::getSerial().putc(response[charcount]); +// charcount++; +// for(int a=0;a<10000;a++); +// } +// response[charcount] = 0; +// USB::getSerial().printf("RESPONSE: %s\r\n",response); +// if(close_conn){ +// connected = 1; +// }else{ +// if(strcmp(response+strlen(response)-6,"*OPEN*") == 0){ +// connected = 1; +// } +// } +// USB::getSerial().printf("connected: %d\r\n",connected); +// } +// for(int a=0;a<1000000;a++); + } + void closeConnection(){ + wait_us(100000); + __disable_irq(); + while(getTCPConStatus){ + setTCPConStatus = 0; + wait_us(50000); + } + } unsigned int min(unsigned int a,unsigned int b){ return a<b ? a : b; }