Radio Structures in OOP

Dependencies:   mbed mbed-rtos

Committer:
jjones646
Date:
Thu Jan 15 07:15:33 2015 +0000
Revision:
6:4a3dbfbc30f1
Parent:
3:dc7e9c6bc26c
socket interface confirmed working.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jjones646 2:7d523bdd2f50 1 #include "FirmwareCheck.h"
jjones646 2:7d523bdd2f50 2
jjones646 3:dc7e9c6bc26c 3 void firmware_version(std::string& version)
jjones646 2:7d523bdd2f50 4 {
jjones646 2:7d523bdd2f50 5 FILE *fwp = fopen("/local/MBED.HTM", "r"); // open the mbed's default file to determine the mbed firmware version
jjones646 2:7d523bdd2f50 6 char temp_buf[300];
jjones646 3:dc7e9c6bc26c 7
jjones646 3:dc7e9c6bc26c 8 version.clear(); // clear the passed string to ensure it's empty
jjones646 3:dc7e9c6bc26c 9
jjones646 2:7d523bdd2f50 10 while( fgets(temp_buf, 300, fwp) != NULL ) {
jjones646 2:7d523bdd2f50 11 std::string temp_string(temp_buf);
jjones646 2:7d523bdd2f50 12
jjones646 2:7d523bdd2f50 13 if( temp_string.find("<meta ") != std::string::npos ) {
jjones646 2:7d523bdd2f50 14
jjones646 2:7d523bdd2f50 15 // the word that we need to find the position of
jjones646 2:7d523bdd2f50 16 std::string search_word( "&firmware=" );
jjones646 2:7d523bdd2f50 17
jjones646 2:7d523bdd2f50 18 // find the initial position from the keyword we're looking for
jjones646 2:7d523bdd2f50 19 std::size_t pos1 = temp_string.find(search_word) + search_word.length();
jjones646 2:7d523bdd2f50 20
jjones646 2:7d523bdd2f50 21 // create substring starting AFTER `&firmware=` and going to the end of the line
jjones646 2:7d523bdd2f50 22 std::string sub_str( temp_string.substr(pos1) );
jjones646 2:7d523bdd2f50 23
jjones646 2:7d523bdd2f50 24 // now find the position of the next `&` character from the sub string
jjones646 2:7d523bdd2f50 25 std::size_t pos2 = sub_str.find("&");
jjones646 2:7d523bdd2f50 26
jjones646 2:7d523bdd2f50 27 // parse out the firmware's version number
jjones646 3:dc7e9c6bc26c 28 version = sub_str.substr(0, pos2);
jjones646 2:7d523bdd2f50 29 break;
jjones646 2:7d523bdd2f50 30 }
jjones646 2:7d523bdd2f50 31 }
jjones646 2:7d523bdd2f50 32 // close the file handle
jjones646 2:7d523bdd2f50 33 fclose(fwp);
jjones646 2:7d523bdd2f50 34 }