MoteIF.h
1 /********************************************************************
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  ********************************************************************/
18 /*********************************************************************
19  * TinyOS data structures.
20  * Portions borrowed from the TinyOS project (http://www.tinyos.net),
21  * distributed according to the Intel Open Source License.
22  *********************************************************************/
23 /***************************************************************************
24  * Desc: Library for generic Crossbow WSN nodes communication
25  * Author: Jose Manuel Sanchez Matamoros, Adrian Jimenez Gonzalez
26  * Date: 15 Aug 2011
27  **************************************************************************/
28 
29 #ifndef MOTEIF_H
30 #define MOTEIF_H
31 
32 #include <SerialStream.h>
33 #include <iostream>
34 #include <iomanip>
35 
36 #include "MoteProtocol.h"
37 
38 namespace mote {
39 
40 using namespace LibSerial;
41 
42 
64 class MoteIF {
65 
66 public:
67  ~MoteIF();
68 
69  void open( const char *tty = "/dev/ttyUSB0", SerialStreamBuf::BaudRateEnum baud_rate = SerialStreamBuf::BAUD_115200 );
70  void close();
71 
72  void getMessage( TOSMessage& message );
73  void sendMessage( TOSMessage& message, uint8_t type = 0 );
74 
75  bool setTiming( short vmin, short vtime );
76 
77  void setOS(int v);
78  int getOS();
79 protected:
80  int os;
81 
82  MoteProtocol protocol;
83  SerialStream serial;
84 // std::ifstream *ifs;
85 
86 };
87 
88 
89 inline void MoteIF::getMessage( TOSMessage& message ) {
90 
91  protocol.getMessage( message );
92 }
93 
99 inline void MoteIF::sendMessage( TOSMessage& message, uint8_t type ) {
100 
101  if(type == 0){
102  if(os == TOS1)
103  type = P_TOS1_PACKET_NO_ACK;
104  else if(os == TOS2)
105  type = P_TOS2_PACKET_NO_ACK;
106  } else {
107  if(os == TOS1)
108  type = P_TOS1_PACKET_ACK;
109  else if(os == TOS2)
110  type = P_TOS2_PACKET_ACK;
111  }
112 
113  protocol.sendMessage( message, type );
114 };
115 
116 }
117 
118 #endif
Implements the basic sending and receiving capabilities on iostreams.
Definition: MoteProtocol.h:147
Definition: generic_xbow_structdef.cc:34
TinyOS generic message.
Definition: MoteProtocol.h:205
void sendMessage(TOSMessage &message, uint8_t type=0)
Encapsulates a TinyOS message in a packet and sends it to the mote.
Definition: MoteIF.h:99
This class provides serial-port-ready access to the mote.
Definition: MoteIF.h:64