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-06-08
- Revision:
- 11:137108e3403e
- Parent:
- 10:fdf9ca254549
- Child:
- 12:e3cb430ec051
File content as of revision 11:137108e3403e:
#include "wifi.h" #include "utils.h" #define BAUDR 115200 #define SEND_SIZE 1024 Wifi::Wifi (PinName tx, PinName rx, PinName cts, 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_.flowCTS(cts); 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[SEND_SIZE+1]; int temp; int bytes; FILE *f = fopen(fname, "rb"); if (f == NULL) { printf("Unable to open %s\n\r", fname); 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, sizeof(char), SEND_SIZE, f)) != 0) { //buffer[0] = 0xAA; //sync byte 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]); }