Benjamin Hepp / ait_link
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uwb_link_impl.h Source File

uwb_link_impl.h

00001 //
00002 // Simple message protocol for UWB.
00003 //
00004 // Created by Benjamin Hepp on 02.04.16.
00005 // Copyright (c) 2016 Benjamin Hepp. All rights reserved.
00006 //
00007 
00008 #pragma once
00009 
00010 #include <ait_link/ait_link_impl.h>
00011 #include "uwb_link.h"
00012 
00013 #include <iostream>
00014 
00015 #ifdef __MBED__
00016 
00017 #include "uwb_link_mbed.h"
00018 
00019 #else
00020 
00021 namespace ait {
00022 
00023   // We need this extra base-class to ensure initialization of AITLinkImpl when initializing UWBLink in UWBLinkImpl
00024   class UWBLinkImplBase {
00025   public:
00026     UWBLinkImplBase()
00027             : _ait_link(&serial_) {
00028     }
00029   protected:
00030     Serial serial_;
00031     AITLinkImpl _ait_link;
00032   };
00033 
00034   class UWBLinkImpl : public UWBLinkImplBase, public UWBLink {
00035   public:
00036     UWBLinkImpl(int buffer_size = 1024)
00037             : UWBLink(&_ait_link, buffer_size) {
00038       serial_.setReadCallback(boost::bind(std::mem_fun(&UWBLink::inputReceivedChar), this, _1));
00039     }
00040 
00041     UWBLinkImpl(const std::string& device, unsigned int baud_rate, int buffer_size = 1024)
00042         : UWBLink(&_ait_link, buffer_size) {
00043       serial_.setReadCallback(boost::bind(std::mem_fun(&UWBLink::inputReceivedChar), this, _1));
00044       start(device, baud_rate);
00045     }
00046 
00047     void start(const std::string& device, unsigned int baud_rate) {
00048       serial_.open(device, baud_rate);
00049       serial_.start();
00050     }
00051   };
00052 
00053 }
00054 
00055 #endif // __MBED__