Benjamin Hepp / ait_link
Committer:
bhepp
Date:
Wed Apr 06 08:27:25 2016 +0000
Revision:
3:bfc4928cd279
Parent:
2:502d1a5f79a0
Updated license

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bhepp 3:bfc4928cd279 1 //
bhepp 3:bfc4928cd279 2 // Simple message protocol for UWB.
bhepp 3:bfc4928cd279 3 //
bhepp 3:bfc4928cd279 4 // Created by Benjamin Hepp on 02.04.16.
bhepp 3:bfc4928cd279 5 // Copyright (c) 2016 Benjamin Hepp. All rights reserved.
bhepp 3:bfc4928cd279 6 //
bhepp 3:bfc4928cd279 7
bhepp 2:502d1a5f79a0 8 #pragma once
bhepp 2:502d1a5f79a0 9
bhepp 2:502d1a5f79a0 10 #include <ait_link/ait_link_impl.h>
bhepp 2:502d1a5f79a0 11 #include "uwb_link.h"
bhepp 2:502d1a5f79a0 12
bhepp 2:502d1a5f79a0 13 #include <iostream>
bhepp 2:502d1a5f79a0 14
bhepp 2:502d1a5f79a0 15 #ifdef __MBED__
bhepp 2:502d1a5f79a0 16
bhepp 2:502d1a5f79a0 17 #include "uwb_link_mbed.h"
bhepp 2:502d1a5f79a0 18
bhepp 2:502d1a5f79a0 19 #else
bhepp 2:502d1a5f79a0 20
bhepp 2:502d1a5f79a0 21 namespace ait {
bhepp 1:9f8c0dbb0fc7 22
bhepp 2:502d1a5f79a0 23 // We need this extra base-class to ensure initialization of AITLinkImpl when initializing UWBLink in UWBLinkImpl
bhepp 2:502d1a5f79a0 24 class UWBLinkImplBase {
bhepp 2:502d1a5f79a0 25 public:
bhepp 2:502d1a5f79a0 26 UWBLinkImplBase()
bhepp 2:502d1a5f79a0 27 : _ait_link(&serial_) {
bhepp 2:502d1a5f79a0 28 }
bhepp 2:502d1a5f79a0 29 protected:
bhepp 2:502d1a5f79a0 30 Serial serial_;
bhepp 2:502d1a5f79a0 31 AITLinkImpl _ait_link;
bhepp 2:502d1a5f79a0 32 };
bhepp 2:502d1a5f79a0 33
bhepp 2:502d1a5f79a0 34 class UWBLinkImpl : public UWBLinkImplBase, public UWBLink {
bhepp 2:502d1a5f79a0 35 public:
bhepp 2:502d1a5f79a0 36 UWBLinkImpl(int buffer_size = 1024)
bhepp 2:502d1a5f79a0 37 : UWBLink(&_ait_link, buffer_size) {
bhepp 2:502d1a5f79a0 38 serial_.setReadCallback(boost::bind(std::mem_fun(&UWBLink::inputReceivedChar), this, _1));
bhepp 2:502d1a5f79a0 39 }
bhepp 2:502d1a5f79a0 40
bhepp 2:502d1a5f79a0 41 UWBLinkImpl(const std::string& device, unsigned int baud_rate, int buffer_size = 1024)
bhepp 2:502d1a5f79a0 42 : UWBLink(&_ait_link, buffer_size) {
bhepp 2:502d1a5f79a0 43 serial_.setReadCallback(boost::bind(std::mem_fun(&UWBLink::inputReceivedChar), this, _1));
bhepp 2:502d1a5f79a0 44 start(device, baud_rate);
bhepp 2:502d1a5f79a0 45 }
bhepp 2:502d1a5f79a0 46
bhepp 2:502d1a5f79a0 47 void start(const std::string& device, unsigned int baud_rate) {
bhepp 2:502d1a5f79a0 48 serial_.open(device, baud_rate);
bhepp 2:502d1a5f79a0 49 serial_.start();
bhepp 2:502d1a5f79a0 50 }
bhepp 2:502d1a5f79a0 51 };
bhepp 2:502d1a5f79a0 52
bhepp 2:502d1a5f79a0 53 }
bhepp 2:502d1a5f79a0 54
bhepp 2:502d1a5f79a0 55 #endif // __MBED__