Vishal Kotcherlakota / BGLib
Revision:
1:3336b2391c80
Child:
2:3ce9a31a6a7e
diff -r b696d6f71174 -r 3336b2391c80 BGLib.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BGLib.cpp	Sun May 17 23:24:26 2015 +0000
@@ -0,0 +1,28 @@
+#include "BGLib.h"
+
+BGLib::BGLib(PinName tx, PinName rx, PinName rts, PinName cts) :
+    mSerial(tx, rx) {
+    mSerial.set_flow_control(SerialBase::RTSCTS, rts, cts);
+    mSerial.baud(57600);
+    mSerial.attach(this, &BGLib::parse);
+}
+
+void BGLib::set_hello_callback(hello_callback_t pCallback) {
+    mHelloCallback = pCallback;
+}
+
+void BGLib::send_hello() {
+    uint8_t bytes[] = {0x00, 0x00, 0x00, 0x01};
+    send_bytes(bytes, 4);
+}
+
+void BGLib::parse() {
+    mSerial.getc();
+    mHelloCallback();
+}
+
+void BGLib::send_bytes(uint8_t bytes[], int length) {
+    for (int i = 0; i < length; i++) {
+        mSerial.putc(bytes[i]);
+    }
+}
\ No newline at end of file