Add feature ISO TP (multi frames and peer to peer)
[apps/agl-service-can-low-level.git] / low-can-binding / can / message / j1939-message.hpp
1 /*
2  * Copyright (C) 2018, 2019 "IoT.bzh"
3  * Author "Arthur Guyader" <arthur.guyader@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #pragma once
19
20 #include <linux/can/j1939.h>
21 #include "message.hpp"
22
23
24 #define J1939_MAX_MULTIPACKETS 255
25 #define J1939_MAX_DLEN J1939_MAX_MULTIPACKETS * CAN_MAX_DLEN
26
27
28 class j1939_message_t : public message_t
29 {
30         private:
31                 /* J1939 NAME
32                 *
33                 * bit 0-20      : Identity Number
34                 * bit 21-31     : Manufacturer Code
35                 * bit 32-34     : ECU Instance
36                 * bit 35-39     : Function Instance
37                 * bit 40-47     : Function
38                 * bit 48        : Reserved
39                 * bit 49-55     : Vehicle System
40                 * bit 56-59     : Vehicle System Instance
41                 * bit 60-62     : Industry Group
42                 * bit 63        : Arbitrary Address Capable
43                 */
44                 name_t name_;
45
46                 /* J1939 Parameter Group Number
47                 *
48                 * bit 0-7       : PDU Specific (PS)
49                 * bit 8-15      : PDU Format (PF)
50                 * bit 16        : Data Page (DP)
51                 * bit 17        : Reserved (R)
52                 * bit 19-31     : set to zero
53                 */
54                 pgn_t pgn_;
55
56
57                 /* J1939 Address
58                         0-255
59                  */
60                 uint8_t addr_;
61
62                 /**
63                  * @brief The sockanme to send a message to
64                  * an other ECU
65                  */
66                 struct sockaddr_can sockname_;
67
68         public:
69                 j1939_message_t();
70                 j1939_message_t(uint32_t length, std::vector<uint8_t>& data, uint64_t timestamp, name_t name, pgn_t pgn, uint8_t addr);
71                 uint64_t get_name() const;
72                 uint32_t get_pgn() const;
73                 uint8_t get_addr() const;
74                 static std::shared_ptr<j1939_message_t> convert_from_addr(struct sockaddr_can& addr, uint8_t (&data)[128], size_t nbytes, uint64_t timestamp);
75                 bool is_set();
76                 std::string get_debug_message();
77                 uint32_t get_id() const;
78                 void set_id(const canid_t id);
79                 struct sockaddr_can get_sockname();
80                 void set_sockname(struct sockaddr_can sockname);
81                 void set_sockname(pgn_t pgn, name_t name, uint8_t addr);
82 };