Integrate the J1939 features : address claiming and write.
[apps/agl-service-can-low-level.git] / low-can-binding / utils / socketcan-j1939 / socketcan-j1939-addressclaiming.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 <afb-timer.h>
20
21 #include "./socketcan-j1939.hpp"
22
23 namespace utils
24 {
25         class socketcan_j1939_addressclaiming_t : public socketcan_j1939_t
26         {
27         public:
28             socketcan_j1939_addressclaiming_t();
29             virtual std::shared_ptr<message_t> read_message();
30             virtual int open(std::string device_name, pgn_t pgn);
31             virtual claiming_state get_state();
32             TimerHandleT *timer_handle_;
33             std::pair<uint64_t, bool> table_j1939_address_[J1939_IDLE_ADDR];
34
35         private:
36             int claim_address(bool first_claim,bool new_address);
37             int pgn_request();
38             void initialize_table_j1939_address();
39             int save_addr_name(uint8_t addr,name_t name);
40             uint8_t choose_new_address();
41             uint8_t get_addr_table(name_t name);
42             void change_state(claiming_state new_state);
43             void launch_timer();
44             static int no_response_claiming(TimerHandleT *timerhandle);
45             static int free_timer_handle(void *timer_context);
46
47             uint8_t current_address_;
48             bool signal_stop_;
49             claiming_state claiming_state_;
50             std::string device_name_;
51         };
52 }