Jonathan Jones
/
Radios
Radio Structures in OOP
utils/FirmwareCheck/FirmwareCheck.cpp@2:7d523bdd2f50, 2014-12-28 (annotated)
- Committer:
- jjones646
- Date:
- Sun Dec 28 06:05:17 2014 +0000
- Revision:
- 2:7d523bdd2f50
- Child:
- 3:dc7e9c6bc26c
outlining communication implementations
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jjones646 | 2:7d523bdd2f50 | 1 | #include "FirmwareCheck.h" |
jjones646 | 2:7d523bdd2f50 | 2 | |
jjones646 | 2:7d523bdd2f50 | 3 | std::string firmware_version(void) |
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 | 2:7d523bdd2f50 | 7 | std::string firmware; |
jjones646 | 2:7d523bdd2f50 | 8 | while( fgets(temp_buf, 300, fwp) != NULL ) { |
jjones646 | 2:7d523bdd2f50 | 9 | std::string temp_string(temp_buf); |
jjones646 | 2:7d523bdd2f50 | 10 | |
jjones646 | 2:7d523bdd2f50 | 11 | if( temp_string.find("<meta ") != std::string::npos ) { |
jjones646 | 2:7d523bdd2f50 | 12 | |
jjones646 | 2:7d523bdd2f50 | 13 | // the word that we need to find the position of |
jjones646 | 2:7d523bdd2f50 | 14 | std::string search_word( "&firmware=" ); |
jjones646 | 2:7d523bdd2f50 | 15 | |
jjones646 | 2:7d523bdd2f50 | 16 | // find the initial position from the keyword we're looking for |
jjones646 | 2:7d523bdd2f50 | 17 | std::size_t pos1 = temp_string.find(search_word) + search_word.length(); |
jjones646 | 2:7d523bdd2f50 | 18 | |
jjones646 | 2:7d523bdd2f50 | 19 | // create substring starting AFTER `&firmware=` and going to the end of the line |
jjones646 | 2:7d523bdd2f50 | 20 | std::string sub_str( temp_string.substr(pos1) ); |
jjones646 | 2:7d523bdd2f50 | 21 | |
jjones646 | 2:7d523bdd2f50 | 22 | // now find the position of the next `&` character from the sub string |
jjones646 | 2:7d523bdd2f50 | 23 | std::size_t pos2 = sub_str.find("&"); |
jjones646 | 2:7d523bdd2f50 | 24 | |
jjones646 | 2:7d523bdd2f50 | 25 | // parse out the firmware's version number |
jjones646 | 2:7d523bdd2f50 | 26 | firmware = sub_str.substr(0, pos2); |
jjones646 | 2:7d523bdd2f50 | 27 | break; |
jjones646 | 2:7d523bdd2f50 | 28 | } |
jjones646 | 2:7d523bdd2f50 | 29 | } |
jjones646 | 2:7d523bdd2f50 | 30 | // close the file handle |
jjones646 | 2:7d523bdd2f50 | 31 | fclose(fwp); |
jjones646 | 2:7d523bdd2f50 | 32 | |
jjones646 | 2:7d523bdd2f50 | 33 | return firmware; |
jjones646 | 2:7d523bdd2f50 | 34 | } |