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
wifi.cpp
- Committer:
- jkaderka
- Date:
- 2015-04-29
- Revision:
- 9:8839ecc02e0e
- Parent:
- 8:ae5319de2c33
- Child:
- 10:fdf9ca254549
File content as of revision 9:8839ecc02e0e:
#include "wifi.h" #include "utils.h" #define BAUDR 921600 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_.init(); // use DHCP while (!wifi_.connect()) ; printf("IP Address is %s\n\r", wifi_.getIPAddress()); wifi_.setProtocol(TCP); /* set different baudrate, higher values tends to be unstable */ wifi_.baudr(BAUDR); } /* * Format: (int) -1 (int) -1 (int) swimmer_id * many times (char) 0xAA (int) count 3*(short) acc 3*(float)gyro * (int) -1 (int) -1 */ int Wifi::sendFile(const char *fname, int swimmer_id) { char buffer[BUFFER_SIZE+1]; 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 = swimmer_id; toBytes(buffer+sizeof(int)*2, &temp, sizeof(int)); bufferSend(buffer, 3*sizeof(int)); while ((bytes = fread(buffer+1, 1, BUFFER_SIZE, f)) != 0) buffer[0] = 0xAA; //sync packet bufferSend(buffer, bytes+1); //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() != '#') ; wifi_.putc('#'); wifi_.putc('A'); return wifi_.getc(); } /* ******************************** * private * *******************************/ void Wifi::bufferSend(char *buffer, size_t size) { int i; for (i = 0; i < size; i++) wifi_.putc(buffer[i]); }