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