oem7_message_decoder_lib.cpp
Go to the documentation of this file.
1 //
3 // Copyright (c) 2020 NovAtel Inc.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 //
24 
26 
27 
28 #include <boost/shared_ptr.hpp>
29 #include <boost/make_shared.hpp>
30 #include <decoders/novatel/framer.hpp>
31 
32 #include <memory>
33 
34 #include <iostream>
35 
36 
37 
38 namespace
39 {
40  // Versioning: reflects underlying EDIE version
41  static const novatel_oem7::version_element_t VERSION_MAJOR = 10;
42  static const novatel_oem7::version_element_t VERSION_MINOR = 2;
43  static const novatel_oem7::version_element_t VERSION_SPECIAL= 0;
44 }
45 
46 
47 namespace novatel_oem7
48 {
54  {
56 
57 
58  public:
59  Oem7RawMessage(BaseMessageData* raw_bmd):
60  bmd_(raw_bmd)
61  {
62  }
63 
68  {
69  if(bmd_->getMessageType())
70  {
71  return OEM7MSGTYPE_RSP;
72  }
73  else
74  {
75  return OEM7MSGTYPE_LOG;
76  }
77  }
78 
83  {
84  switch(bmd_->getMessageFormat())
85  {
86  case MESSAGE_BINARY: return OEM7MSGFMT_BINARY;
87  case MESSAGE_SHORT_HEADER_BINARY: return OEM7MSGFMT_SHORTBINARY;
88  case MESSAGE_ASCII: return OEM7MSGFMT_ASCII;
89  case MESSAGE_ABB_ASCII: return OEM7MSGFMT_ABASCII;
90  default: return OEM7MSGFMT_UNKNOWN;
91  }
92  }
93 
97  int getMessageId() const
98  {
99  return bmd_->getMessageID();
100  }
101 
105  const uint8_t* getMessageData(size_t offset) const
106  {
107  return reinterpret_cast<uint8_t*>(&bmd_->getMessageData()[offset]);
108  }
109 
113  size_t getMessageDataLength() const
114  {
115  return bmd_->getMessageLength();
116  }
117 
118  };
119 
120 
121 /***
122  * Adapter between Decoder user, and the 'Stream' interface required by EDIE's standard decoder.
123  */
124 class InputStream: public InputStreamInterface
125 {
127 
128  public:
130  user_(user)
131  {
132  }
133 
134  /***
135  * Called by EDIE to read bytes; refer to EDIE documentation
136  */
137  StreamReadStatus
138  ReadData(ReadDataStructure& read_data)
139  {
140  size_t rlen = 0;
141  bool ok = user_->read(boost::asio::buffer(read_data.cData, read_data.uiDataSize), rlen);
142 
143  StreamReadStatus st;
144  st.bEOS = !ok;
145  st.uiCurrentStreamRead = rlen;
146 
147  return st;
148  }
149 
150 
151  // Default empty implementation
152  virtual StreamReadStatus ReadLine(std::string&) { return StreamReadStatus(); };
153 
154  virtual std::string GetFileExtension(){return NULL;};
155  virtual void RegisterCallBack(NovatelParser*){};
156  virtual void SetTimeOut(DOUBLE){};
157  virtual void EnableCallBack(BOOL){};
158  virtual void Reset(std::streamoff, std::ios_base::seekdir){};
159  virtual BOOL IsCallBackEnable(){return FALSE;};
160  };
161 
162 
163 
168 {
170 
173 
174 public:
176  user_(user)
177  {
178  input_stream_ = boost::make_shared<InputStream>(user);
179  framer_ = boost::make_shared<Framer>(input_stream_.get());
180 
181  framer_->EnableUnknownData(TRUE);
182  framer_->SetBMDOutput(FLATTEN);
183  }
184 
189  {
190  BaseMessageData* raw_bmd = NULL;
191  StreamReadStatus status = framer_->ReadMessage(&raw_bmd);
192  if(raw_bmd)
193  {
194  msg = boost::make_shared<Oem7RawMessage>(raw_bmd);
195  }
196 
197  // EOS: No more data is available from EDIE, e.g. EOF reached when reading from file, socket connection broken, etc.
198  return !status.bEOS;
199  // Presumably, when no message is reported, EOS is signaled. We can't handle this reliably here, let the User deal with this.
200  }
201 
202 };
203 
209 {
211  return dec;
212 }
213 
214 void
216 {
217  major = VERSION_MAJOR;
218  minor = VERSION_MINOR;
219  spec = VERSION_SPECIAL;
220 }
221 
222 }
Oem7RawMessage(BaseMessageData *raw_bmd)
boost::shared_ptr< InputStream > input_stream_
EDIE input stream; refer to EDIE documentation.
virtual bool readMessage(boost::shared_ptr< Oem7RawMessageIf > &msg)
Oem7MessageFormat getMessageFormat() const
virtual void RegisterCallBack(NovatelParser *)
boost::shared_ptr< BaseMessageData > bmd_
binary message obtained from receiver
boost::shared_ptr< Framer > framer_
EDIE standard framer.
virtual bool read(boost::asio::mutable_buffer, size_t &)=0
virtual StreamReadStatus ReadLine(std::string &)
ROSCPP_DECL bool ok()
virtual std::string GetFileExtension()
const uint8_t * getMessageData(size_t offset) const
virtual void Reset(std::streamoff, std::ios_base::seekdir)
Oem7MessageDecoderLibUserIf * user_
Decoder&#39;s user.
Oem7MessageType getMessageType() const
void GetOem7MessageDecoderLibVersion(version_element_t &major, version_element_t &minor, version_element_t &spec)
InputStream(Oem7MessageDecoderLibUserIf *user)
boost::shared_ptr< Oem7MessageDecoderLibIf > GetOem7MessageDecoder(Oem7MessageDecoderLibUserIf *user)
Oem7MessageDecoderLib(Oem7MessageDecoderLibUserIf *user)
StreamReadStatus ReadData(ReadDataStructure &read_data)


novatel_oem7_driver
Author(s):
autogenerated on Sun Mar 19 2023 02:17:37