+///******************************************************************************
+///
+/// low_can_subscription_t object
+///
+///*******************************************************************************/
+
+low_can_subscription_t::low_can_subscription_t()
+ : index_{-1},
+ sig_name_{},
+ bus_name_{""},
+ can_id_{0},
+ bit_position_{0},
+ bit_size_{0},
+ factor_{-1.0},
+ offset_{-1},
+ socket_{}
+{}
+
+low_can_subscription_t::low_can_subscription_t(struct event_filter_t event_filter)
+ : event_filter_{event_filter}
+{}
+
+low_can_subscription_t::low_can_subscription_t( low_can_subscription_t&& s)
+ : index_{s.index_},
+ sig_name_{s.sig_name_},
+ bus_name_{s.bus_name_},
+ can_id_{s.can_id_},
+ bit_position_{s.bit_position_},
+ bit_size_{s.bit_size_},
+ factor_{s.factor_},
+ offset_{s.offset_},
+ event_filter_{s.event_filter_},
+ socket_{std::move(s.socket_)}
+{}
+
+ low_can_subscription_t& low_can_subscription_t::operator=(const low_can_subscription_t& s)
+{
+ socket_ = std::move(s.socket_);
+ return *this;
+}
+
+low_can_subscription_t::operator bool() const
+{
+ return socket_.socket() != INVALID_SOCKET;
+}
+
+int low_can_subscription_t::get_index() const
+{
+ return index_;
+}
+
+const std::string low_can_subscription_t::get_sig_name() const
+{
+ return sig_name_;
+}
+
+float low_can_subscription_t::get_frequency() const
+{
+ return event_filter_.frequency;
+}
+
+float low_can_subscription_t::get_min() const
+{
+ return event_filter_.min;
+}
+
+float low_can_subscription_t::get_max() const
+{
+ return event_filter_.max;
+}
+
+utils::socketcan_bcm_t& low_can_subscription_t::get_socket()
+{
+ return socket_;
+}
+
+void low_can_subscription_t::set_frequency(float freq)
+{
+ event_filter_.frequency = freq;
+}
+
+void low_can_subscription_t::set_min(float min)
+{
+ event_filter_.min = min;
+}
+
+void low_can_subscription_t::set_max(float max)
+{
+ event_filter_.max = max;
+}
+
+/// @brief Create a RX_SETUP receive job used by the BCM socket.
+///
+/// @return 0 if ok else -1
+int low_can_subscription_t::create_rx_filter(const std::string& bus_name, const std::string& sig_name, uint32_t can_id, uint8_t bit_position, uint8_t bit_size, float factor, float offset)
+{
+ // Make sure that socket has been opened.
+ if(! socket_)
+ {
+ socket_.open(bus_name);
+ index_ = (int)socket_.socket();
+ }
+
+ sig_name_ = sig_name;
+ bus_name_ = bus_name;
+ can_id_ = can_id;
+ bit_position_ = bit_position;
+ bit_size_ = bit_size;
+ factor_ = factor;
+ offset_ = offset;
+
+ struct utils::simple_bcm_msg bcm_msg;
+ struct can_frame cfd;
+
+ memset(&cfd, 0, sizeof(cfd));
+ memset(&bcm_msg.msg_head, 0, sizeof(bcm_msg.msg_head));
+ float val = (float)(1 << bit_size_) - 1;
+
+ struct timeval freq;
+ frequency_clock_t f(event_filter_.frequency);
+ freq = f.get_timeval_from_period();
+
+ bcm_msg.msg_head.opcode = RX_SETUP;
+ bcm_msg.msg_head.can_id = can_id_;
+ bcm_msg.msg_head.flags = SETTIMER|RX_NO_AUTOTIMER;
+ bcm_msg.msg_head.ival2.tv_sec = freq.tv_sec ;
+ bcm_msg.msg_head.ival2.tv_usec = freq.tv_usec;
+ bcm_msg.msg_head.nframes = 1;
+ bitfield_encode_float(val,
+ bit_position_,
+ bit_size_,
+ factor_,
+ offset_,
+ cfd.data,
+ CAN_MAX_DLEN);
+
+ bcm_msg.frames = cfd;
+
+ if(socket_ << bcm_msg)
+ return 0;
+ return -1;
+}
+
+/// @brief Create a RX_SETUP receive job used by the BCM socket.
+///
+/// @return 0 if ok else -1
+int low_can_subscription_t::create_rx_filter()
+{
+ // Make sure that socket has been opened.
+ if(! socket_)
+ {
+ socket_.open(bus_name_);
+ index_ = (int)socket_.socket();
+ }
+
+ struct utils::simple_bcm_msg bcm_msg;
+ struct can_frame cfd;
+
+ memset(&cfd, 0, sizeof(cfd));
+ memset(&bcm_msg.msg_head, 0, sizeof(bcm_msg.msg_head));
+ float val = (float)(1 << bit_size_) - 1;
+
+ struct timeval freq;
+ frequency_clock_t f(event_filter_.frequency);
+ freq = f.get_timeval_from_period();
+
+ bcm_msg.msg_head.opcode = RX_SETUP;
+ bcm_msg.msg_head.can_id = can_id_;
+ bcm_msg.msg_head.flags = SETTIMER|RX_NO_AUTOTIMER;
+ bcm_msg.msg_head.ival2.tv_sec = freq.tv_sec ;
+ bcm_msg.msg_head.ival2.tv_usec = freq.tv_usec;
+ bcm_msg.msg_head.nframes = 1;
+ bitfield_encode_float(val,
+ bit_position_,
+ bit_size_,
+ factor_,
+ offset_,
+ cfd.data,
+ CAN_MAX_DLEN);
+
+ bcm_msg.frames = cfd;
+
+ if(socket_ << bcm_msg)
+ return 0;
+ return -1;
+}
+
+///******************************************************************************
+///
+/// SystemD event loop Callbacks
+///
+///*******************************************************************************/
+
+void on_no_clients(const std::string& message)