74b625e03606f1de21ba7dce76a543e0e5ca9ae6
[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 #include <linux/can.h>
20 #include <linux/can/j1939.h>
21 #include "./message.hpp"
22
23 #define J1939_MAX_MULTIPACKETS 255
24 #define J1939_MAX_DLEN J1939_MAX_MULTIPACKETS * CAN_MAX_DLEN
25
26 class j1939_message_t : public message_t
27 {
28     private:
29         /* J1939 NAME
30         *
31         * bit 0-20      : Identity Number
32         * bit 21-31     : Manufacturer Code
33         * bit 32-34     : ECU Instance
34         * bit 35-39     : Function Instance
35         * bit 40-47     : Function
36         * bit 48        : Reserved
37         * bit 49-55     : Vehicle System
38         * bit 56-59     : Vehicle System Instance
39         * bit 60-62     : Industry Group
40         * bit 63        : Arbitrary Address Capable
41         */
42         name_t name_;
43
44         /* J1939 Parameter Group Number
45         *
46         * bit 0-7       : PDU Specific (PS)
47         * bit 8-15      : PDU Format (PF)
48         * bit 16        : Data Page (DP)
49         * bit 17        : Reserved (R)
50         * bit 19-31     : set to zero
51         */
52         pgn_t pgn_;
53
54
55         /* J1939 Address
56          */
57         uint8_t addr_;
58
59     public:
60         j1939_message_t();
61         j1939_message_t(uint8_t length, can_message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp, name_t name, pgn_t pgn, uint8_t addr);
62         uint64_t get_name() const;
63         uint32_t get_pgn() const;
64         uint8_t get_addr() const;
65         static std::shared_ptr<j1939_message_t> convert_from_addr(struct sockaddr_can& addr, uint8_t (&data)[128], size_t nbytes, uint64_t timestamp);
66         bool is_set();
67         std::string get_debug_message();
68         uint32_t get_id() const;
69         struct bcm_msg get_bcm_msg();
70                 void set_bcm_msg(struct bcm_msg bcm_msg);
71 };
72
73