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.
Dependents: NerfUS-Coord NerfUSTarget
Fork of APP3_xbee by
Diff: xbee.cpp
- Revision:
- 10:612739c6d27d
- Parent:
- 8:b9c096965c00
--- a/xbee.cpp Tue Feb 14 02:38:18 2017 +0000
+++ b/xbee.cpp Tue Feb 14 07:55:15 2017 +0000
@@ -297,4 +297,96 @@
const uint8_t y = parsed_frame[3];
const uint8_t z = parsed_frame[4];
sprintf(readable_string_output, "Accelerometer state: x=0x%X, y=0x%X, z=0x%X", x, y, z);
+}
+
+vector<string> read_file(string path)
+{
+ LocalFileSystem local("local");
+ vector<string> result;
+ char buffer[128] = "";
+ FILE *fp = fopen(path.c_str(), "r");
+ bool ret = (fgets(buffer, 64, fp)) ;
+
+ string value(buffer);
+ string first_value = "";
+ string second_value = "";
+ bool which_value = true;
+
+ for(int i=0; i<value.size(); i++)
+ {
+ if(buffer[i] == ';')
+ {
+ which_value = false;
+ }
+ else
+ {
+ if(which_value)
+ {
+ first_value += buffer[i];
+ }
+ else
+ {
+ second_value += buffer[i];
+ }
+ }
+ }
+ result.push_back(first_value);
+ result.push_back(second_value);
+ return result;
+}
+
+char hexa_char_to_dec(char hexa_char)
+{
+ if('0' <= hexa_char && hexa_char <= '9')
+ {
+ return hexa_char - 48;
+ }
+ if('A' <= hexa_char && hexa_char <= 'F')
+ {
+ return hexa_char - 55;
+ }
+ if('a' <= hexa_char && hexa_char <= 'f')
+ {
+ return hexa_char - 87;
+ }
+ assert(false && "Wtf");
+ return hexa_char;
+}
+
+vector<char> string_to_data(string pan_id)
+{
+ vector<char> result;
+
+ for(int i=0; i < pan_id.size(); i += 2)
+ {
+ const char dec_val = ( hexa_char_to_dec(pan_id[i]) ) * 16 + hexa_char_to_dec(pan_id[i]);
+ result.push_back(dec_val);
+ }
+
+ return result;
+}
+
+void set_pan_id(string pan_id)
+{
+ const int pan_id_beginning[7] = {0x7E, 0x00, 0x06, 0x08, 0x01, 0x49, 0x44};
+ unsigned char checksum = 0xFF;
+
+ xbee.putc(pan_id_beginning[0]);
+ xbee.putc(pan_id_beginning[1]);
+ xbee.putc(pan_id_beginning[2]);
+
+ for(int i=3; i<7; i++)
+ {
+ checksum -= pan_id_beginning[i];
+ xbee.putc(pan_id_beginning[i]);
+ }
+
+ vector<char> pan_id_char = string_to_data(pan_id);
+ for(int i=0; i<pan_id_char.size(); i++)
+ {
+ checksum -= pan_id_char.at(i);
+ xbee.putc(pan_id_char.at(i));
+ }
+
+ xbee.putc(checksum);
}
\ No newline at end of file
