Add feature ISO TP (multi frames and peer to peer)
[apps/agl-service-can-low-level.git] / low-can-binding / binding / low-can-subscription.cpp
1 /*
2  * Copyright (C) 2015, 2016 "IoT.bzh"
3  * Author "Romain Forlot" <romain.forlot@iot.bzh>
4  * Author "Loic Collignon" <loic.collignon@iot.bzh>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include "low-can-subscription.hpp"
20 #include "application.hpp"
21 #include "canutil/write.h"
22 #include "../utils/socketcan-bcm.hpp"
23 #include "../can/can-encoder.hpp"
24
25 #ifdef USE_FEATURE_ISOTP
26 #include "../utils/socketcan-isotp.hpp"
27 #endif
28
29 #ifdef USE_FEATURE_J1939
30 #include "../utils/socketcan-j1939/socketcan-j1939-data.hpp"
31 #endif
32
33 low_can_subscription_t::low_can_subscription_t()
34         : index_{-1},
35         event_filter_{},
36         event_{},
37         socket_{}
38 {}
39
40 low_can_subscription_t::low_can_subscription_t(struct event_filter_t event_filter)
41         : index_{-1},
42           event_filter_{event_filter},
43           event_{},
44           socket_{}
45  {}
46
47 low_can_subscription_t::low_can_subscription_t( low_can_subscription_t&& s)
48         : index_{s.index_},
49         event_filter_{s.event_filter_},
50         event_{},
51         socket_{std::move(s.socket_)}
52 {}
53
54 low_can_subscription_t& low_can_subscription_t::operator=(const low_can_subscription_t& s)
55 {
56         socket_ = std::move(s.socket_);
57         return *this;
58 }
59
60 low_can_subscription_t::~low_can_subscription_t()
61 {
62         if(socket_)
63                 socket_->close();
64 }
65
66 low_can_subscription_t::operator bool() const
67 {
68         return ((signal_ != nullptr || ! diagnostic_message_.empty()) && ! socket_);
69 }
70 afb_event_t low_can_subscription_t::get_event()
71 {
72         return event_;
73 }
74
75 /**
76  * @brief Set the event calling the afb_daemon_make_event function to
77  * create it and the checks its validity.
78  *
79  * @return int - 0 if OK, -1 if not
80  */
81 int low_can_subscription_t::set_event()
82 {
83         std::string event_name = get_name();
84         event_ = afb_daemon_make_event(event_name.c_str());
85         if (! afb_event_is_valid(event_))
86         {
87                 AFB_ERROR("Can't create an event for %s, something goes wrong.", event_name.c_str());
88                 return -1;
89         }
90
91         return 0;
92 }
93
94 /**
95  * @brief Subscribe to the event member of the object
96  *
97  * @param request the subscribe AFB client request which want to
98  * subscribe
99  *
100  * @return int - 0 if OK, -1 if not
101  */
102 int low_can_subscription_t::subscribe(afb_req_t request)
103 {
104         if(! afb_event_is_valid(event_))
105         {
106                 if(set_event() < 0)
107                 {
108                         return -1;
109                 }
110         }
111         return afb_req_subscribe(request, event_);
112 }
113
114 /**
115  * @brief Unsubscribe to the event member of the object
116  *
117  * @param request the unsubscribe AFB client request which want to
118  * unsubscribe
119  *
120  * @return int - 0 if OK, -1 if not
121  */
122 int low_can_subscription_t::unsubscribe(afb_req_t request)
123 {
124         return afb_req_unsubscribe(request, event_);
125 }
126
127 int low_can_subscription_t::get_index() const
128 {
129         return index_;
130 }
131
132 const std::shared_ptr<signal_t> low_can_subscription_t::get_signal() const
133 {
134         return signal_;
135 }
136
137 bool low_can_subscription_t::is_signal_subscription_corresponding(const std::shared_ptr<signal_t> signal, const struct event_filter_t& event_filter) const
138 {
139         return signal_ == signal && event_filter_ == event_filter;
140 }
141
142 const std::vector<std::shared_ptr<diagnostic_message_t> > low_can_subscription_t::get_diagnostic_message() const
143 {
144         return diagnostic_message_;
145 }
146
147 /// @brief Retrieve a diagnostic_message subscribed from a pid
148 ///
149 /// @param[in] pid - Diagnostic messages PID to search for
150 ///
151 /// @return shared_ptr diagnostic_message_ if found and nullptr if not found
152 const std::shared_ptr<diagnostic_message_t> low_can_subscription_t::get_diagnostic_message(uint32_t pid) const
153 {
154         for(const auto& diag: diagnostic_message_)
155         {
156                 if(diag->get_pid() == pid)
157                 {
158                         return diag;
159                 }
160         }
161         return nullptr;
162 }
163
164 /// @brief Retrieve a diagnostic message search from its name
165 ///
166 /// @return shared_ptr diagnostic_message_ if found and nullptr if not found
167 const std::shared_ptr<diagnostic_message_t> low_can_subscription_t::get_diagnostic_message(const std::string& name) const
168 {
169         for(const auto& diag: diagnostic_message_)
170         {
171                 if(diag->get_name() == name)
172                 {
173                         return diag;
174                 }
175         }
176         return nullptr;
177 }
178
179 /// @brief Return the CAN signal name and empty string if not found
180 /// or no CAN signal subscribed
181 const std::string low_can_subscription_t::get_name() const
182 {
183         if (signal_ != nullptr)
184                 return signal_->get_name();
185         else if (!diagnostic_message_.empty())
186                 return "diagnostic_messages";
187
188         AFB_WARNING("No diagnostics messages nor CAN signals registered in that subscription. Name empty ! It's a bug to be reported.");
189         return "";
190 }
191
192 /// @brief Return name from a diagnostic message from a PID
193 ///
194 /// @param[in] pid - Diagnostic message PID
195 const std::string low_can_subscription_t::get_name(uint32_t pid) const
196 {
197         if (!diagnostic_message_.empty())
198                 return get_diagnostic_message(pid)->get_name() ;
199
200         AFB_WARNING("No diagnostics messages nor CAN signals registered in that subscription. Name empty ! It's a bug to be reported.");
201         return "";
202 }
203
204 float low_can_subscription_t::get_frequency() const
205 {
206         return event_filter_.frequency;
207 }
208
209 float low_can_subscription_t::get_min() const
210 {
211         return event_filter_.min;
212 }
213
214 float low_can_subscription_t::get_max() const
215 {
216         return event_filter_.max;
217 }
218
219 canid_t low_can_subscription_t::get_rx_id() const
220 {
221         return event_filter_.rx_id;
222 }
223
224 canid_t low_can_subscription_t::get_tx_id() const
225 {
226         return event_filter_.tx_id;
227 }
228
229 std::shared_ptr<utils::socketcan_t> low_can_subscription_t::get_socket()
230 {
231         return socket_;
232 }
233
234 void low_can_subscription_t::set_frequency(float freq)
235 {
236         event_filter_.frequency = freq;
237 }
238
239 void low_can_subscription_t::set_min(float min)
240 {
241         event_filter_.min = min;
242 }
243
244 void low_can_subscription_t::set_max(float max)
245 {
246         event_filter_.max = max;
247 }
248
249 void low_can_subscription_t::set_rx_id(canid_t rx_id)
250 {
251         event_filter_.rx_id = rx_id;
252 }
253
254 void low_can_subscription_t::set_tx_id(canid_t tx_id)
255 {
256         event_filter_.tx_id = tx_id;
257 }
258
259 void low_can_subscription_t::set_index(int index)
260 {
261         index_ = index;
262 }
263
264 void low_can_subscription_t::set_signal(std::shared_ptr<signal_t> signal)
265 {
266         signal_ = signal;
267 }
268
269
270 /// @brief Based upon which object is a subscribed CAN signal or diagnostic message
271 /// it will open the socket with the required CAN bus device name.
272 ///
273 /// @return INVALID_SOCKET on failure, else positive integer
274 int low_can_subscription_t::open_socket(low_can_subscription_t &subscription, const std::string& bus_name,  uint32_t flags)
275 {
276         int ret = -1;
277         if(! subscription.socket_)
278         {
279                 if(flags&BCM_PROTOCOL)
280                 {
281                         if( subscription.signal_ != nullptr)
282                         {
283                                         subscription.socket_ = std::make_shared<utils::socketcan_bcm_t>();
284                                         ret = subscription.socket_->open(subscription.signal_->get_message()->get_bus_device_name());
285                         }
286                         else if (! subscription.diagnostic_message_ .empty())
287                         {
288                                         subscription.socket_ = std::make_shared<utils::socketcan_bcm_t>();
289                                         ret = subscription.socket_->open(application_t::instance().get_diagnostic_manager().get_bus_device_name());
290                         }
291                         else if ( !bus_name.empty())
292                         {
293                                         subscription.socket_ = std::make_shared<utils::socketcan_bcm_t>();
294                                         ret = subscription.socket_->open(bus_name);
295                         }
296                         subscription.index_ = (int)subscription.socket_->socket();
297                 }
298 #ifdef USE_FEATURE_ISOTP
299                 else if(flags&ISOTP_PROTOCOL)
300                 {
301                         if(subscription.signal_ != nullptr)
302                         {
303                                 canid_t rx = NO_CAN_ID;
304                                 canid_t tx = NO_CAN_ID;
305                                 if(flags&ISOTP_SEND)
306                                 {
307                                         rx = subscription.get_rx_id();
308                                         tx = subscription.signal_->get_message()->get_id();
309                                 }
310                                 else if(flags&ISOTP_RECEIVE)
311                                 {
312                                         rx = subscription.signal_->get_message()->get_id();
313                                         tx = subscription.get_tx_id();
314                                 }
315                                 std::shared_ptr<utils::socketcan_isotp_t> socket = std::make_shared<utils::socketcan_isotp_t>();
316                                 ret = socket->open(subscription.signal_->get_message()->get_bus_device_name(),rx,tx);
317                                 subscription.socket_ = socket;
318                         }
319                         else if(!bus_name.empty())
320                         {
321                                 std::shared_ptr<utils::socketcan_isotp_t> socket = std::make_shared<utils::socketcan_isotp_t>();
322                                 ret = socket->open(bus_name, subscription.get_rx_id(),subscription.get_tx_id());
323                                 subscription.socket_ = socket;
324                         }
325                         subscription.index_ = (int)subscription.socket_->socket();
326                 }
327 #endif
328 #ifdef USE_FEATURE_J1939
329                 else if(flags&J1939_ADDR_CLAIM_PROTOCOL)
330                 {
331                         pgn_t pgn = J1939_NO_PGN;
332                         if(!bus_name.empty())
333                         {
334                                 std::shared_ptr<utils::socketcan_j1939_addressclaiming_t> socket = std::make_shared<utils::socketcan_j1939_addressclaiming_t>();
335                                 ret = socket->open(bus_name, pgn);
336                                 subscription.socket_ = socket;
337                         }
338                         subscription.index_ = (int)subscription.socket_->socket();
339                 }
340                 else if(flags&J1939_PROTOCOL)
341                 {
342                         pgn_t pgn = J1939_NO_PGN;
343                         if(subscription.signal_ != nullptr)
344                         {
345                                 pgn = subscription.signal_->get_message()->get_id();
346                                 std::shared_ptr<utils::socketcan_j1939_data_t> socket = std::make_shared<utils::socketcan_j1939_data_t>();
347                                 ret = socket->open(subscription.signal_->get_message()->get_bus_device_name(), pgn);
348                                 subscription.socket_ = socket;
349                         }
350                         else if(!bus_name.empty())
351                         {
352                                 std::shared_ptr<utils::socketcan_j1939_data_t> socket = std::make_shared<utils::socketcan_j1939_data_t>();
353                                 ret = socket->open(bus_name, pgn);
354                                 subscription.socket_ = socket;
355                         }
356                         subscription.index_ = (int)subscription.socket_->socket();
357                 }
358 #endif
359                 else
360                 {
361                         AFB_ERROR("Socket format not supported");
362                         return INVALID_SOCKET;
363                 }
364         }
365         else{
366                 ret = subscription.socket_->socket();
367         }
368         return ret;
369 }
370
371
372 /// @brief Builds a BCM message head but doesn't set can_frame.
373 ///
374 /// @returns a bcm_msg with the msg_head parts set and can_frame
375 /// zeroed.
376 struct bcm_msg low_can_subscription_t::make_bcm_head(uint32_t opcode, uint32_t can_id, uint32_t flags, const struct timeval& timeout, const struct timeval& frequency_thinning)
377 {
378         struct bcm_msg bcm_msg;
379         ::memset(&bcm_msg, 0, sizeof(bcm_msg));
380
381         bcm_msg.msg_head.opcode  = opcode;
382         bcm_msg.msg_head.can_id  = can_id;
383         bcm_msg.msg_head.flags = flags;
384         bcm_msg.msg_head.ival1.tv_sec = timeout.tv_sec ;
385         bcm_msg.msg_head.ival1.tv_usec = timeout.tv_usec;
386         bcm_msg.msg_head.ival2.tv_sec = frequency_thinning.tv_sec ;
387         bcm_msg.msg_head.ival2.tv_usec = frequency_thinning.tv_usec;
388
389
390         return bcm_msg;
391 }
392
393 /// @brief Take an existing bcm_msg struct and add a can_frame.
394 /// Currently only 1 uniq can_frame can be added, it's not possible to build
395 /// a multiplexed message with several can_frame.
396 void low_can_subscription_t::add_one_bcm_frame(struct canfd_frame& cfd, struct bcm_msg& bcm_msg)
397 {
398         struct can_frame cf;
399
400         if (bcm_msg.msg_head.flags & CAN_FD_FRAME)
401                 bcm_msg.fd_frames[bcm_msg.msg_head.nframes] = cfd;
402         else
403         {
404                 cf.can_id = cfd.can_id;
405                 cf.can_dlc = cfd.len;
406                 ::memcpy(&cf.data, cfd.data, cfd.len);
407                 bcm_msg.frames[bcm_msg.msg_head.nframes] = cf;
408         }
409         bcm_msg.msg_head.nframes++;
410 }
411
412 /// @brief Take an existing bcm_msg struct and add a can_frame.
413 /// Currently only 1 uniq can_frame can be added, it's not possible to build
414 /// a multiplexed message with several can_frame.
415 void low_can_subscription_t::remove_last_bcm_frame(struct bcm_msg& bcm_msg)
416 {
417         struct canfd_frame cf;
418         memset(&cf,0,sizeof(cf));
419         bcm_msg.fd_frames[bcm_msg.msg_head.nframes] = cf;
420         bcm_msg.msg_head.nframes--;
421 }
422
423 #ifdef USE_FEATURE_J1939
424 int low_can_subscription_t::create_rx_filter_j1939(low_can_subscription_t &subscription, std::shared_ptr<signal_t> sig)
425 {
426         subscription.signal_= sig;
427
428         // Make sure that socket is opened.
429         if(open_socket(subscription,"",J1939_PROTOCOL) < 0)
430         {
431                         return -1;
432         }
433         return 0;
434 }
435 #endif
436
437 int low_can_subscription_t::create_rx_filter_isotp(low_can_subscription_t &subscription, std::shared_ptr<signal_t> sig)
438 {
439         subscription.signal_= sig;
440
441         // Make sure that socket is opened.
442         if(open_socket(subscription,"",ISOTP_PROTOCOL|ISOTP_RECEIVE) < 0)
443         {
444                         return -1;
445         }
446         return 0;
447 }
448
449 /// @brief Create a RX_SETUP receive job to be used by the BCM socket for a CAN signal
450 /// subscription
451 ///
452 /// @return 0 if ok else -1
453 int low_can_subscription_t::create_rx_filter_can(low_can_subscription_t &subscription, std::shared_ptr<signal_t> sig)
454 {
455         uint32_t flags_bcm;
456         float val;
457         struct timeval freq, timeout = {0, 0};
458         struct canfd_frame cfd;
459         subscription.signal_= sig;
460         bool is_fd = sig->get_message()->is_fd();
461
462         std::vector<uint8_t> data;
463         uint32_t length_msg = sig->get_message()->get_length();
464
465         if(length_msg == 0)
466         {
467                 AFB_ERROR("Error in the length of message with id %d",sig->get_message()->get_id());
468                 return -1;
469         }
470
471         for(int i = 0; i<length_msg;i++)
472         {
473                 data.push_back(0);
474         }
475
476         encoder_t::encode_data(subscription.signal_,data,true,false,true);
477
478         can_message_t cm;
479
480         if (is_fd)
481         {
482                 flags_bcm = SETTIMER|RX_NO_AUTOTIMER|CAN_FD_FRAME;
483                 cfd.len = CANFD_MAX_DLEN;
484                 cm = can_message_t( CANFD_MAX_DLEN,
485                                                         sig->get_message()->get_id(),
486                                                         length_msg,
487                                                         false,
488                                                         sig->get_message()->get_flags(),
489                                                         data,
490                                                         0);
491         }
492         else
493         {
494                 flags_bcm = SETTIMER|RX_NO_AUTOTIMER;
495                 cfd.len = CAN_MAX_DLEN;
496                 cm = can_message_t( CAN_MAX_DLEN,
497                                                         sig->get_message()->get_id(),
498                                                         length_msg,
499                                                         false,
500                                                         sig->get_message()->get_flags(),
501                                                         data,
502                                                         0);
503         }
504
505         frequency_clock_t f = subscription.event_filter_.frequency == 0 ? subscription.signal_->get_frequency() : frequency_clock_t(subscription.event_filter_.frequency);
506         freq = f.get_timeval_from_period();
507
508         struct bcm_msg bcm_msg = subscription.make_bcm_head(RX_SETUP, subscription.signal_->get_message()->get_id(), flags_bcm, timeout, freq);
509
510         std::vector<canfd_frame> cfd_vect = cm.convert_to_canfd_frame_vector();
511
512         if(cfd_vect.size() > 1) //multi
513         {
514                 AFB_ERROR("Not implemented yet");
515                 return -1;
516         }
517         else if(cfd_vect.size() == 1)
518         {
519                 canfd_frame cf = cfd_vect[0];
520                 for(int i=0;i<cfd.len;i++)
521                 {
522                         cfd.data[i] = cf.data[i];
523                 }
524                 subscription.add_one_bcm_frame(cfd, bcm_msg);
525         }
526         else
527         {
528                 AFB_ERROR("No data available");
529                 return -1;
530         }
531
532         return create_rx_filter_bcm(subscription, bcm_msg);
533 }
534
535 int low_can_subscription_t::create_rx_filter(std::shared_ptr<signal_t> sig)
536 {
537         if(!sig->get_message()->is_isotp() && !sig->get_message()->is_j1939())
538         {
539                 return low_can_subscription_t::create_rx_filter_can(*this, sig);
540         }
541 #ifdef USE_FEATURE_ISOTP
542         else if(sig->get_message()->is_isotp())
543         {
544                 return low_can_subscription_t::create_rx_filter_isotp(*this,sig);
545         }
546 #endif
547 #ifdef USE_FEATURE_J1939
548         else if(sig->get_message()->is_j1939())
549         {
550                 return low_can_subscription_t::create_rx_filter_j1939(*this, sig);
551         }
552 #endif
553         else
554         {
555                 AFB_ERROR("Signal can't be j1939 and isotp");
556                 return -1;
557         }
558 }
559
560
561 /// @brief Create a RX_SETUP receive job to be used by the BCM socket for a
562 /// diagnostic message subscription.
563 ///
564 /// @return 0 if ok else -1
565 int low_can_subscription_t::create_rx_filter(std::shared_ptr<diagnostic_message_t> sig)
566 {
567         diagnostic_message_.push_back(sig);
568
569         struct timeval freq = frequency_clock_t(event_filter_.frequency).get_timeval_from_period();
570         //struct timeval timeout = frequency_clock_t(10).get_timeval_from_period();
571         struct timeval timeout = {0,0};
572
573         struct bcm_msg bcm_msg =  make_bcm_head(RX_SETUP, OBD2_FUNCTIONAL_BROADCAST_ID, SETTIMER|RX_NO_AUTOTIMER|RX_FILTER_ID, timeout, freq);
574         return create_rx_filter_bcm(*this, bcm_msg);
575 }
576
577 /// @brief Create a RX_SETUP receive job used by the BCM socket directly from
578 /// a bcm_msg. The method should not be used directly but rather through the
579 /// two previous method with signal_t or diagnostic_message_t object.
580 ///
581 /// If the CAN arbitration ID is the OBD2 functional broadcast id the subscribed
582 /// to the 8 classics OBD2 functional response ID
583 ///
584 /// @return 0 if ok else -1
585 int low_can_subscription_t::create_rx_filter_bcm(low_can_subscription_t &subscription, struct bcm_msg& bcm_msg)
586 {
587         // Make sure that socket is opened.
588         if(subscription.open_socket(subscription,"",BCM_PROTOCOL) < 0)
589                 {return -1;}
590
591         // If it's not an OBD2 CAN ID then just add a simple RX_SETUP job
592         // else monitor all standard 8 CAN OBD2 ID response.
593
594         can_message_t msg = can_message_t();
595
596         msg.set_bcm_msg(bcm_msg);
597
598         if(bcm_msg.msg_head.can_id != OBD2_FUNCTIONAL_BROADCAST_ID)
599         {
600                 subscription.socket_->write_message(msg);
601                         if(! subscription.socket_)
602                                 return -1;
603         }
604         else
605         {
606                 for(uint8_t i = 0; i < 8; i++)
607                 {
608                         bcm_msg.msg_head.can_id  =  OBD2_FUNCTIONAL_RESPONSE_START + i;
609                         msg.set_bcm_msg(bcm_msg);
610                         subscription.socket_->write_message(msg);
611                         if(! subscription.socket_)
612                                 return -1;
613                 }
614         }
615         return 0;
616 }
617
618 /// @brief Creates a TX_SEND job that is used by the BCM socket to
619 /// send a message
620 ///
621 /// @return 0 if ok else -1
622 int low_can_subscription_t::tx_send(low_can_subscription_t &subscription, message_t *message, const std::string& bus_name)
623 {
624         can_message_t *cm = static_cast<can_message_t*>(message);
625
626         struct bcm_msg bcm_msg = subscription.make_bcm_head(TX_SEND, cm->get_id(),cm->get_flags()|TX_CP_CAN_ID); // TX_CP_CAN_ID -> copy in cfd the id of bcm
627         cm->set_bcm_msg(bcm_msg);
628
629         std::vector<canfd_frame> cfd_vect = cm->convert_to_canfd_frame_vector();
630
631         if(subscription.open_socket(subscription, bus_name, BCM_PROTOCOL) < 0)
632         {
633                         return -1;
634         }
635
636         struct bcm_msg &bcm_cm = cm->get_bcm_msg();
637
638
639
640         if(cfd_vect.size() > 1)
641         {
642                 AFB_ERROR("Multi frame BCM not implemented");
643                 return -1;
644         }
645         else if(cfd_vect.size() == 1) // raw or fd
646         {
647                 subscription.add_one_bcm_frame(cfd_vect[0], bcm_cm);
648
649                 if(subscription.socket_->write_message(*cm) < 0)
650                 {
651                         AFB_ERROR("Error write message id : %d",cfd_vect[0].can_id);
652                         return -1;
653                 }
654         }
655         else // error
656         {
657                 AFB_ERROR("Error no data available");
658                 return -1;
659         }
660
661         if(! subscription.socket_.get())
662         {
663                         return -1;
664         }
665
666         return 0;
667 }
668
669 #ifdef USE_FEATURE_J1939
670 int low_can_subscription_t::j1939_send(low_can_subscription_t &subscription, message_t *message, const std::string& bus_name)
671 {
672         //struct bcm_msg bcm_msg = subscription.make_bcm_head(TX_SEND, cfd.can_id);
673         //subscription.add_one_bcm_frame(cfd, bcm_msg);
674
675         if(subscription.open_socket(subscription, bus_name, J1939_PROTOCOL) < 0)
676         {
677                 return -1;
678         }
679
680         j1939_message_t *jm = static_cast<j1939_message_t*>(message);
681         jm->set_sockname(jm->get_pgn(),J1939_NO_NAME,J1939_NO_ADDR);
682         if(subscription.socket_->write_message(*jm) < 0)
683         {
684                 AFB_ERROR("Error write j1939 message");
685                 return -1;
686         }
687
688         return 0;
689 }
690 #endif
691
692
693 int low_can_subscription_t::isotp_send(low_can_subscription_t &subscription, message_t *message, const std::string& bus_name)
694 {
695         //struct bcm_msg bcm_msg = subscription.make_bcm_head(TX_SEND, cfd.can_id);
696         //subscription.add_one_bcm_frame(cfd, bcm_msg);
697
698         if(subscription.open_socket(subscription, bus_name, ISOTP_PROTOCOL|ISOTP_SEND) < 0)
699         {
700                 return -1;
701         }
702
703         can_message_t *cm = static_cast<can_message_t*>(message);
704         if(subscription.socket_->write_message(*cm) < 0)
705         {
706                 AFB_ERROR("Error write iso tp message");
707                 return -1;
708         }
709
710         return 0;
711 }