MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
mip_parser.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_packet.hpp"
4 
5 #include <mip/mip_parser.h>
6 
7 
8 namespace mip
9 {
13 
19 class Parser : public C::mip_parser
20 {
21 public:
23  Parser(C::mip_packet_callback callback, void* callbackObject, Timeout timeout) { C::mip_parser_init(this, callback, callbackObject, timeout); }
25  Parser(void (*callback)(void*,const PacketView*,Timestamp), void* callbackObject, Timeout timeout) { C::mip_parser_init(this, (C::mip_packet_callback)callback, callbackObject, timeout); }
26 
27  Parser(Timeout timeout) { C::mip_parser_init(this, nullptr, nullptr, timeout); }
28 
29  template<class T, bool (T::*Callback)(const PacketView&, Timestamp)>
30  void setCallback(T& object);
31 
33  void reset() { C::mip_parser_reset(this); }
34 
36  void parse(const uint8_t* inputBuffer, size_t inputCount, Timestamp timestamp) { return C::mip_parser_parse(this, inputBuffer, inputCount, timestamp); }
37 
40  void parse(microstrain::Span<const uint8_t> data, Timestamp timestamp) { return parse(data.data(), data.size(), timestamp); }
41 
43  Timeout timeout() const { return C::mip_parser_timeout(this); }
46 };
47 
48 
70 template<class T, bool (T::*Callback)(const PacketView&, Timestamp)>
71 void Parser::setCallback(T& object)
72 {
73  C::mip_packet_callback callback = [](void* obj, const C::mip_packet_view* pkt, Timestamp timestamp)->bool
74  {
75  return (static_cast<T*>(obj)->*Callback)(PacketView(pkt), timestamp);
76  };
77 
78  C::mip_parser_set_callback(this, callback, &object);
79 }
80 
83 } // namespace mip
microstrain::Span::data
constexpr pointer data() const noexcept
Definition: span.hpp:63
mip
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
mip_parser.h
mip::C::mip_parser_set_callback
void mip_parser_set_callback(mip_parser *parser, mip_packet_callback callback, void *callback_object)
mip_parser_set_callback
Definition: mip_parser.c:440
mip::C::mip_parser_timeout
mip_timeout mip_parser_timeout(const mip_parser *parser)
Returns the packet timeout of the parser.
Definition: mip_parser.c:416
mip::Parser::setCallback
void setCallback(T &object)
Initializes the MIP Parser.
Definition: mip_parser.hpp:71
mip::C::mip_parser_set_timeout
void mip_parser_set_timeout(mip_parser *parser, mip_timeout timeout)
Changes the timeout of the MIP parser.
Definition: mip_parser.c:428
microstrain::Span::size
constexpr size_t size() const noexcept
Definition: span.hpp:65
microstrain::Span
Implementation of std::span from C++20.
Definition: span.hpp:40
mip::C::mip_parser_parse
void mip_parser_parse(mip_parser *parser, const uint8_t *input_buffer, size_t input_length, mip_timestamp timestamp)
Parse packets from a buffer.
Definition: mip_parser.c:183
mip::C::mip_packet_view
Structure representing a MIP Packet.
Definition: mip_packet.h:50
mip::C::mip_parser
MIP Parser state.
Definition: mip_parser.h:53
mip::C::mip_parser_init
void mip_parser_init(mip_parser *parser, mip_packet_callback callback, void *callback_object, mip_timeout timeout)
Initializes the MIP parser.
Definition: mip_parser.c:32
mip::C::mip_parser_reset
void mip_parser_reset(mip_parser *parser)
Resets the MIP parser.
Definition: mip_parser.c:51
mip::Parser::parse
void parse(microstrain::Span< const uint8_t > data, Timestamp timestamp)
Parse packets from a buffer (span version).
Definition: mip_parser.hpp:40
mip::Parser::Parser
Parser(Timeout timeout)
Definition: mip_parser.hpp:27
mip::Timestamp
microstrain::EmbeddedTimestamp Timestamp
Definition: mip_types.h:50
mip::Parser::Parser
Parser(void(*callback)(void *, const PacketView *, Timestamp), void *callbackObject, Timeout timeout)
Initializes the MIP parser.
Definition: mip_parser.hpp:25
mip::Parser::Parser
Parser(C::mip_packet_callback callback, void *callbackObject, Timeout timeout)
Initializes the MIP parser.
Definition: mip_parser.hpp:23
mip::Timeout
microstrain::EmbeddedTimeout Timeout
Definition: mip_types.h:51
mip::Parser::reset
void reset()
Resets the MIP parser.
Definition: mip_parser.hpp:33
mip::Parser::timeout
Timeout timeout() const
Returns the packet timeout of the parser.
Definition: mip_parser.hpp:43
mip::C::mip_packet_callback
void(* mip_packet_callback)(void *user, const mip_packet_view *packet, mip_timestamp timestamp)
Callback function which receives parsed MIP packets.
Definition: mip_parser.h:43
mip_packet.hpp
mip::PacketView
C++ class representing a view of a MIP packet.
Definition: mip_packet.hpp:35
mip::Parser
C++ class representing a MIP parser.
Definition: mip_parser.hpp:19
mip::Parser::parse
void parse(const uint8_t *inputBuffer, size_t inputCount, Timestamp timestamp)
Parse packets from a buffer.
Definition: mip_parser.hpp:36
mip::Parser::setTimeout
void setTimeout(Timeout timeout)
Changes the timeout of the MIP parser.
Definition: mip_parser.hpp:45