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.
Dependencies: FatFileSystemCpp mbed PowerControl USBHostLite
Diff: wifi.cpp
- Revision:
- 4:030c7726c7dc
- Child:
- 6:c16e8b17092a
diff -r 851eef47c66b -r 030c7726c7dc wifi.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wifi.cpp Sun Apr 19 18:16:51 2015 +0000 @@ -0,0 +1,74 @@ +#include "wifi.h" +#include "utils.h" + +#define BAUDR 921600 +#define BUFFER_SIZE 32 + +Wifi::Wifi (PinName tx, PinName rx, PinName reset, PinName status, + const char * ssid, const char * phrase) : + wifi_(tx, rx, reset, status, ssid, phrase, WPA) { + //wifi_.baudr(9600); //default baudrate, will be changed asap + wifi_.init(); // use DHCP + while (!wifi_.connect()); // join the network + printf("IP Address is %s\n\r", wifi_.getIPAddress()); + wifi_.setProtocol(TCP); + wifi_.baudr(BAUDR); +} + +/* +* Format: (int) -1 (int) -1 (int) swimmer_id +* many times (int) count 3*(int) acc 3*(float)gyro +* (int) -1 (int) -1 +*/ +int Wifi::sendFile(const char *fname, int i) +{ + char buffer[BUFFER_SIZE]; + int temp; + int bytes; + + FILE *f = fopen(fname, "rb"); + if (f == NULL) + return -1; + + //send swimmer id + temp = -1; + toBytes(buffer, &temp, sizeof(int)); + toBytes(buffer+sizeof(int), &temp, sizeof(int)); + temp = i; + toBytes(buffer+sizeof(int)*2, &temp, sizeof(int)); + bufferSend(buffer, 3*sizeof(int)); + + while ((bytes = fread(buffer, 1, BUFFER_SIZE, f)) != 0) + bufferSend(buffer, bytes); + + //end of transmission + temp = -1; + toBytes(buffer, &temp, sizeof(int)); + toBytes(buffer+sizeof(int), &temp, sizeof(int)); + bufferSend(buffer, 2*sizeof(int)); + + fclose(f); + return 0; +} + +/* + * Returns 0 if no command was recieved + * or the command + */ +char Wifi::getCmd(void) +{ + while (!wifi_.readable() || wifi_.getc() != '#') + ; + + return wifi_.getc(); +} + +/* ******************************** + * private + * *******************************/ +void Wifi::bufferSend(char *buffer, size_t size) +{ + int i; + for (i = 0; i < size; i++) + wifi_.putc(buffer[i]); +} \ No newline at end of file