Add a space after a comma
Change some aligments
Bug-AGL: SPEC-2988
Change-Id: I5069120f4bbb33742bb4990e2e1f391ec8d5eeb6
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
21 files changed:
active_message_set_ = id;
}
active_message_set_ = id;
}
-bool application_t::isEngineOn()
+bool application_t::is_engine_on()
{
struct utils::signals_found sf;
openxc_DynamicField search_key = build_DynamicField("engine.speed");
{
struct utils::signals_found sf;
openxc_DynamicField search_key = build_DynamicField("engine.speed");
subscription_address_claiming_ = new_subscription;
}
subscription_address_claiming_ = new_subscription;
}
-#endif
\ No newline at end of file
uint32_t get_signal_id(signal_t& sig) const;
uint32_t get_signal_id(signal_t& sig) const;
void set_active_message_set(uint8_t id);
void set_active_message_set(uint8_t id);
// poll a PID for nothing.
if(sig->get_supported() && subscribe)
{
// poll a PID for nothing.
if(sig->get_supported() && subscribe)
{
+ if (!app.is_engine_on())
AFB_WARNING("signal: Engine is off, %s won't received responses until it's on", sig->get_name().c_str());
diag_m.add_recurring_request(diag_req, sig->get_name().c_str(), false, sig->get_decoder(), sig->get_callback(), event_filter.frequency, perm_rec_diag_req);
AFB_WARNING("signal: Engine is off, %s won't received responses until it's on", sig->get_name().c_str());
diag_m.add_recurring_request(diag_req, sig->get_name().c_str(), false, sig->get_decoder(), sig->get_callback(), event_filter.frequency, perm_rec_diag_req);
-static int one_subscribe_unsubscribe_id(afb_req_t request, bool subscribe, const uint32_t& id ,json_object *args)
+static int one_subscribe_unsubscribe_id(afb_req_t request, bool subscribe, const uint32_t& id, json_object *args)
{
int ret = 0;
std::shared_ptr<message_definition_t> message_definition = application_t::instance().get_message_definition(id);
struct utils::signals_found sf;
if(message_definition)
{
int ret = 0;
std::shared_ptr<message_definition_t> message_definition = application_t::instance().get_message_definition(id);
struct utils::signals_found sf;
if(message_definition)
- sf.signals = list_ptr_signal_t(message_definition->get_signals().begin(),message_definition->get_signals().end());
+ sf.signals = list_ptr_signal_t(message_definition->get_signals().begin(), message_definition->get_signals().end());
static void write_raw_frame(afb_req_t request, const std::string& bus_name, message_t *message,
static void write_raw_frame(afb_req_t request, const std::string& bus_name, message_t *message,
- struct json_object *can_data, uint32_t flags, event_filter_t &event_filter)
+ struct json_object *can_data, uint32_t flags, event_filter_t &event_filter)
{
struct utils::signals_found sf;
{
struct utils::signals_found sf;
if( !sf.signals.empty() )
{
if( !sf.signals.empty() )
{
- AFB_DEBUG("ID WRITE RAW : %d",sf.signals.front()->get_message()->get_id());
+ AFB_DEBUG("ID WRITE RAW : %d", sf.signals.front()->get_message()->get_id());
if(flags & BCM_PROTOCOL)
{
if(sf.signals.front()->get_message()->is_fd())
if(flags & BCM_PROTOCOL)
{
if(sf.signals.front()->get_message()->is_fd())
static void write_frame(afb_req_t request, const std::string& bus_name, json_object *json_value, event_filter_t &event_filter)
{
message_t *message;
static void write_frame(afb_req_t request, const std::string& bus_name, json_object *json_value, event_filter_t &event_filter)
{
message_t *message;
+ uint32_t id;
+ uint32_t length;
struct json_object *can_data = nullptr;
std::vector<uint8_t> data;
struct json_object *can_data = nullptr;
std::vector<uint8_t> data;
- AFB_DEBUG("JSON content %s",json_object_get_string(json_value));
+ AFB_DEBUG("JSON content %s", json_object_get_string(json_value));
if(!wrap_json_unpack(json_value, "{si, si, so !}",
"can_id", &id,
"can_dlc", &length,
"can_data", &can_data))
{
if(!wrap_json_unpack(json_value, "{si, si, so !}",
"can_id", &id,
"can_dlc", &length,
"can_data", &can_data))
{
- message = new can_message_t(0,(uint32_t)id,(uint32_t)length,false,0,data,0);
- write_raw_frame(request,bus_name,message,can_data,BCM_PROTOCOL,event_filter);
+ message = new can_message_t(0, id, length, false, 0, data, 0);
+ write_raw_frame(request, bus_name, message, can_data, BCM_PROTOCOL, event_filter);
}
#ifdef USE_FEATURE_J1939
else if(!wrap_json_unpack(json_value, "{si, si, so !}",
}
#ifdef USE_FEATURE_J1939
else if(!wrap_json_unpack(json_value, "{si, si, so !}",
"length", &length,
"data", &can_data))
{
"length", &length,
"data", &can_data))
{
- message = new j1939_message_t((uint32_t)length,data,0,J1939_NO_NAME,(pgn_t)id,J1939_NO_ADDR);
- write_raw_frame(request,bus_name,message,can_data,J1939_PROTOCOL, event_filter);
+ message = new j1939_message_t(length, data, 0, J1939_NO_NAME, (pgn_t)id, J1939_NO_ADDR);
+ write_raw_frame(request, bus_name, message, can_data, J1939_PROTOCOL, event_filter);
flags = BCM_PROTOCOL;
// cfd = encoder_t::build_frame(sig, value);
flags = BCM_PROTOCOL;
// cfd = encoder_t::build_frame(sig, value);
- message_t *message = encoder_t::build_message(sig,value,false,false);
+ message_t *message = encoder_t::build_message(sig, value, false, false);
if(! send_message(message, sig->get_message()->get_bus_device_name(), flags, event_filter, sig) && send)
afb_req_success(request, nullptr, "Message correctly sent");
if(! send_message(message, sig->get_message()->get_bus_device_name(), flags, event_filter, sig) && send)
afb_req_success(request, nullptr, "Message correctly sent");
application.set_subscription_address_claiming(low_can_j1939);
ret = low_can_subscription_t::open_socket(*low_can_j1939,
application.set_subscription_address_claiming(low_can_j1939);
ret = low_can_subscription_t::open_socket(*low_can_j1939,
- j1939_bus,
- J1939_ADDR_CLAIM_PROTOCOL);
+ j1939_bus,
+ J1939_ADDR_CLAIM_PROTOCOL);
rx = subscription.signal_->get_message()->get_id();
tx = subscription.get_tx_id();
}
rx = subscription.signal_->get_message()->get_id();
tx = subscription.get_tx_id();
}
- ret = socket->open(subscription.signal_->get_message()->get_bus_device_name(),rx,tx);
+ ret = socket->open(subscription.signal_->get_message()->get_bus_device_name(), rx, tx);
subscription.socket_ = socket;
}
else if(! bus_name.empty())
{
subscription.socket_ = socket;
}
else if(! bus_name.empty())
{
- ret = socket->open(bus_name, subscription.get_rx_id(),subscription.get_tx_id());
+ ret = socket->open(bus_name, subscription.get_rx_id(), subscription.get_tx_id());
subscription.socket_ = socket;
}
subscription.index_ = (int)subscription.socket_->socket();
subscription.socket_ = socket;
}
subscription.index_ = (int)subscription.socket_->socket();
void low_can_subscription_t::remove_last_bcm_frame(struct bcm_msg& bcm_msg)
{
struct canfd_frame cf;
void low_can_subscription_t::remove_last_bcm_frame(struct bcm_msg& bcm_msg)
{
struct canfd_frame cf;
- memset(&cf,0,sizeof(cf));
+ memset(&cf, 0, sizeof(cf));
bcm_msg.fd_frames[bcm_msg.msg_head.nframes] = cf;
bcm_msg.msg_head.nframes--;
}
bcm_msg.fd_frames[bcm_msg.msg_head.nframes] = cf;
bcm_msg.msg_head.nframes--;
}
{
can_message_t *cm = static_cast<can_message_t*>(message);
{
can_message_t *cm = static_cast<can_message_t*>(message);
- 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
+ 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
cm->set_bcm_msg(bcm_msg);
std::vector<canfd_frame> cfd_vect = cm->convert_to_canfd_frame_vector();
cm->set_bcm_msg(bcm_msg);
std::vector<canfd_frame> cfd_vect = cm->convert_to_canfd_frame_vector();
void set_tx_id(canid_t tx_id);
void set_signal(std::shared_ptr<signal_t> signal);
void set_tx_id(canid_t tx_id);
void set_signal(std::shared_ptr<signal_t> signal);
- static struct bcm_msg make_bcm_head(uint32_t opcode, uint32_t can_id = 0, uint32_t flags = 0, const struct timeval& timeout = {0,0}, const struct timeval& frequency_thinning = {0,0});
+ static struct bcm_msg make_bcm_head(uint32_t opcode, uint32_t can_id = 0, uint32_t flags = 0, const struct timeval& timeout = {0, 0}, const struct timeval& frequency_thinning = {0, 0});
static void add_one_bcm_frame(struct canfd_frame& cfd, struct bcm_msg& bcm_msg);
static void remove_last_bcm_frame(struct bcm_msg& bcm_msg);
static void add_one_bcm_frame(struct canfd_frame& cfd, struct bcm_msg& bcm_msg);
static void remove_last_bcm_frame(struct bcm_msg& bcm_msg);
data_signal.push_back(data[i]);
// if(bit_size > 255)
data_signal.push_back(data[i]);
// if(bit_size > 255)
-// AFB_ERROR("Error signal %s to long bit size",signal.get_name().c_str());
+// AFB_ERROR("Error signal %s to long bit size", signal.get_name().c_str());
// if(new_start_bit > 255)
// AFB_ERROR("Too long signal offset %d", new_start_bit);
if(data_signal.size() > 65535)
// if(new_start_bit > 255)
// AFB_ERROR("Too long signal offset %d", new_start_bit);
if(data_signal.size() > 65535)
- AFB_ERROR("Too long data signal %s",signal.get_name().c_str());
+ AFB_ERROR("Too long data signal %s", signal.get_name().c_str());
return bitfield_parse_float(data_signal.data(), (uint16_t) data_signal.size(),
new_start_bit, bit_size, signal.get_factor(),
return bitfield_parse_float(data_signal.data(), (uint16_t) data_signal.size(),
new_start_bit, bit_size, signal.get_factor(),
uint8_t len_signal_bytes = 0;
if(len_signal_bytes_tmp > 255)
{
uint8_t len_signal_bytes = 0;
if(len_signal_bytes_tmp > 255)
{
- AFB_ERROR("Error signal %s too long",sig->get_name().c_str());
+ AFB_ERROR("Error signal %s too long", sig->get_name().c_str());
/*
if(new_start_bit > 255)
{
/*
if(new_start_bit > 255)
{
- AFB_ERROR("Error signal %s too long",sig->get_name().c_str());
+ AFB_ERROR("Error signal %s too long", sig->get_name().c_str());
}
*/
uint8_t new_bit_size = 0;
if(bit_size > 255)
{
}
*/
uint8_t new_bit_size = 0;
if(bit_size > 255)
{
- AFB_ERROR("Error signal %s to long bit size",sig->get_name().c_str());
+ AFB_ERROR("Error signal %s to long bit size", sig->get_name().c_str());
for(const auto& sig: signal->get_message()->get_signals())
{
for(const auto& sig: signal->get_message()->get_signals())
{
- encode_data(sig,data,false,factor,offset);
+ encode_data(sig, data, false, factor, offset);
}
message->set_data(data);
return message;
}
message->set_data(data);
return message;
- return build_frame(signal,value,message, factor, offset);
+ return build_frame(signal, value, message, factor, offset);
}
#ifdef USE_FEATURE_J1939
else if(signal->get_message()->is_j1939())
}
#ifdef USE_FEATURE_J1939
else if(signal->get_message()->is_j1939())
J1939_NO_NAME,
signal->get_message()->get_id(),
J1939_NO_ADDR);
J1939_NO_NAME,
signal->get_message()->get_id(),
J1939_NO_ADDR);
- return build_frame(signal,value,message, factor, offset);
+ return build_frame(signal, value, message, factor, offset);
std::vector<uint8_t> data = get_data_vector((i*64),(i*64)+63);
if(data.size()<64)
{
std::vector<uint8_t> data = get_data_vector((i*64),(i*64)+63);
if(data.size()<64)
{
- ::memset(frame.data,0,sizeof(frame.data));
- ::memcpy(frame.data,data.data(),data.size());
+ ::memset(frame.data, 0, sizeof(frame.data));
+ ::memcpy(frame.data, data.data(), data.size());
- ::memcpy(frame.data,data.data(),64);
+ ::memcpy(frame.data, data.data(), 64);
}
ret.push_back(frame);
i++;
}
ret.push_back(frame);
i++;
std::vector<uint8_t> data = get_data_vector(i*8,(i*8)+7);
if(data.size()<8)
{
std::vector<uint8_t> data = get_data_vector(i*8,(i*8)+7);
if(data.size()<8)
{
- ::memset(frame.data,0,sizeof(frame.data));
- ::memcpy(frame.data,data.data(),data.size());
+ ::memset(frame.data, 0, sizeof(frame.data));
+ ::memcpy(frame.data, data.data(), data.size());
- ::memset(frame.data,0,sizeof(frame.data));
- ::memcpy(frame.data,data.data(),8);
+ ::memset(frame.data, 0, sizeof(frame.data));
+ ::memcpy(frame.data, data.data(), 8);
}
ret.push_back(frame);
i++;
}
ret.push_back(frame);
i++;
public:
can_message_t();
can_message_t( uint32_t maxdlen,
public:
can_message_t();
can_message_t( uint32_t maxdlen,
- uint32_t id,
- uint32_t length,
- bool rtr_flag_,
- uint32_t flags,
- std::vector<uint8_t>& data,
- uint64_t timestamp);
+ uint32_t id,
+ uint32_t length,
+ bool rtr_flag_,
+ uint32_t flags,
+ std::vector<uint8_t>& data,
+ uint64_t timestamp);
uint32_t get_id() const;
void set_id(const canid_t id);
uint32_t get_id() const;
void set_id(const canid_t id);
/// @param[in] timestamp - timestamp of the message
///
/// @return A j1939_message_t object fully initialized with sockaddr_can and data values.
/// @param[in] timestamp - timestamp of the message
///
/// @return A j1939_message_t object fully initialized with sockaddr_can and data values.
-std::shared_ptr<j1939_message_t> j1939_message_t::convert_from_addr(struct sockaddr_can& addr, uint8_t (&data)[128],size_t nbytes, uint64_t timestamp)
+std::shared_ptr<j1939_message_t> j1939_message_t::convert_from_addr(struct sockaddr_can& addr, uint8_t (&data)[128], size_t nbytes, uint64_t timestamp)
{
int i;
uint32_t length = 0;
{
int i;
uint32_t length = 0;
data_vector.clear();
std::string data_string;
data_vector.clear();
std::string data_string;
- data_string = converter_t::to_hex(data,length);
+ data_string = converter_t::to_hex(data, length);
AFB_DEBUG("Found pgn: %X, length: %X, data %s",
addr.can_addr.j1939.pgn, length, data_string.c_str());
AFB_DEBUG("Found pgn: %X, length: %X, data %s",
addr.can_addr.j1939.pgn, length, data_string.c_str());
- return std::make_shared<j1939_message_t>(j1939_message_t(length, data_vector, timestamp,addr.can_addr.j1939.name,addr.can_addr.j1939.pgn,addr.can_addr.j1939.addr));
+ return std::make_shared<j1939_message_t>(j1939_message_t(length, data_vector, timestamp, addr.can_addr.j1939.name, addr.can_addr.j1939.pgn, addr.can_addr.j1939.addr));
}
/// @brief Test if members pgn_ and length are set.
}
/// @brief Test if members pgn_ and length are set.
/// @return pointer to the first element
/// of class member data_
///
/// @return pointer to the first element
/// of class member data_
///
-const std::vector<uint8_t> message_t::get_data_vector(int start,int end) const
+const std::vector<uint8_t> message_t::get_data_vector(int start, int end) const
{
std::vector<uint8_t> ret;
if(start >= 0)
{
std::vector<uint8_t> ret;
if(start >= 0)
- AFB_ERROR("Error index to get data vector, [%d-%d] - for length %d",start,end,length_);
+ AFB_ERROR("Error index to get data vector, [%d-%d] - for length %d", start, end, length_);
int get_sub_id() const;
const uint8_t* get_data() const;
const std::vector<uint8_t> get_data_vector() const;
int get_sub_id() const;
const uint8_t* get_data() const;
const std::vector<uint8_t> get_data_vector() const;
- const std::vector<uint8_t> get_data_vector(int start,int end) const;
+ const std::vector<uint8_t> get_data_vector(int start, int end) const;
uint32_t get_length() const;
uint64_t get_timestamp() const;
uint32_t get_length() const;
uint64_t get_timestamp() const;
signal_decoder decoder,
signal_encoder encoder,
bool received,
signal_decoder decoder,
signal_encoder encoder,
bool received,
- std::pair<bool,int> multiplex,
+ std::pair<bool, int> multiplex,
bool is_big_endian,
bool is_signed,
std::string unit)
bool is_big_endian,
bool is_signed,
std::string unit)
frequency_.tick(timestamp);
}
frequency_.tick(timestamp);
}
-std::pair<bool,int> signal_t::get_multiplex() const
+std::pair<bool, int> signal_t::get_multiplex() const
bool received_; /*!< received_ - True if this signal has ever been received.*/
float last_value_; /*!< lastValue_ - The last received value of the signal. If 'received' is false,
* this value is undefined. */
bool received_; /*!< received_ - True if this signal has ever been received.*/
float last_value_; /*!< lastValue_ - The last received value of the signal. If 'received' is false,
* this value is undefined. */
- std::pair<bool,int> multiplex_; /*!< multiplex_ - If bool is false and int is 0 is not a multiplex signal
+ std::pair<bool, int> multiplex_; /*!< multiplex_ - If bool is false and int is 0 is not a multiplex signal
If bool is true, that indicate that is a multiplexor
If int is different of 0, that indicate the link with a multiplexor */
bool is_big_endian_; /*!< is_big_endian - True if the signal's data are meant to be read as a big_endian */
If bool is true, that indicate that is a multiplexor
If int is different of 0, that indicate the link with a multiplexor */
bool is_big_endian_; /*!< is_big_endian - True if the signal's data are meant to be read as a big_endian */
signal_decoder decoder,
signal_encoder encoder,
bool received,
signal_decoder decoder,
signal_encoder encoder,
bool received,
- std::pair<bool,int> multiplex,
+ std::pair<bool, int> multiplex,
bool is_big_endian,
bool is_signed,
std::string unit);
bool is_big_endian,
bool is_signed,
std::string unit);
bool get_received() const;
float get_last_value() const;
std::pair<float, uint64_t> get_last_value_with_timestamp() const;
bool get_received() const;
float get_last_value() const;
std::pair<float, uint64_t> get_last_value_with_timestamp() const;
- std::pair<bool,int> get_multiplex() const;
+ std::pair<bool, int> get_multiplex() const;
bool get_is_big_endian() const;
bool get_is_signed() const;
const std::string get_unit() const;
bool get_is_big_endian() const;
bool get_is_signed() const;
const std::string get_unit() const;
}
else if(field.has_bytes_value)
{
}
else if(field.has_bytes_value)
{
- std::string s = converter_t::to_hex(field.bytes_value,field.length_array);
+ std::string s = converter_t::to_hex(field.bytes_value, field.length_array);
json_object_object_add(value, "value", json_object_new_string(s.c_str()));
}
json_object_object_add(value, "value", json_object_new_string(s.c_str()));
}
int socketcan_isotp_t::open(std::string device_name)
{
AFB_WARNING("NOT USE THIS FUNCTION !");
int socketcan_isotp_t::open(std::string device_name)
{
AFB_WARNING("NOT USE THIS FUNCTION !");
- return open(device_name,NO_CAN_ID,NO_CAN_ID);
+ return open(device_name, NO_CAN_ID, NO_CAN_ID);
- if(define_tx_address(device_name,rx_id,tx_id) < 0)
+ if(define_tx_address(device_name, rx_id, tx_id) < 0)
return -1;
struct can_isotp_options opts;
return -1;
struct can_isotp_options opts;
- memset(&opts,0,sizeof(opts));
+ memset(&opts, 0, sizeof(opts));
setopt(SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts));
if(bind((struct sockaddr *)&tx_address_, sizeof(tx_address_)) < 0)
setopt(SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts));
if(bind((struct sockaddr *)&tx_address_, sizeof(tx_address_)) < 0)
std::shared_ptr<can_message_t> cm = std::make_shared<can_message_t>();
uint8_t msg[MAX_ISOTP_FRAMES];
std::shared_ptr<can_message_t> cm = std::make_shared<can_message_t>();
uint8_t msg[MAX_ISOTP_FRAMES];
- ssize_t nbytes = read(socket(),msg,MAX_ISOTP_FRAMES);
+ ssize_t nbytes = read(socket(), msg, MAX_ISOTP_FRAMES);
cm->set_id(tx_address_.can_addr.tp.rx_id);
cm->set_id(tx_address_.can_addr.tp.rx_id);
data.push_back(msg[i]);
std::string data_string;
data.push_back(msg[i]);
std::string data_string;
- data_string = converter_t::to_hex(msg,nbytes);
- AFB_DEBUG("DATA ISO TP for id : %x = %s",cm->get_id(),data_string.c_str());
+ data_string = converter_t::to_hex(msg, nbytes);
+ AFB_DEBUG("DATA ISO TP for id : %x = %s", cm->get_id(), data_string.c_str());
size_t size = m.get_length();
if(size < MAX_ISOTP_FRAMES)
{
size_t size = m.get_length();
if(size < MAX_ISOTP_FRAMES)
{
- ssize_t ret = write(socket(),m.get_data(),size);
+ ssize_t ret = write(socket(), m.get_data(), size);
if(ret < 0)
{
AFB_ERROR("Error sending : %i %s", errno, ::strerror(errno));
if(ret < 0)
{
AFB_ERROR("Error sending : %i %s", errno, ::strerror(errno));
- AFB_WARNING("ISOTP wrote only %zd byte",ret);
+ AFB_WARNING("ISOTP wrote only %zd byte", ret);
*/
socketcan_j1939_addressclaiming_t::socketcan_j1939_addressclaiming_t():
socketcan_j1939_t(),
*/
socketcan_j1939_addressclaiming_t::socketcan_j1939_addressclaiming_t():
socketcan_j1939_t(),
- table_j1939_address_{{std::make_pair(0,false)}},
+ table_j1939_address_{{std::make_pair(0, false)}},
signal_stop_{false},
claiming_state_{claiming_state::INITIAL}
{}
signal_stop_{false},
claiming_state_{claiming_state::INITIAL}
{}
if(jm->get_addr() != current_address_)
{
if(jm->get_addr() != current_address_)
{
- save_addr_name(jm->get_addr(),jm->get_name());
+ save_addr_name(jm->get_addr(), jm->get_name());
return invalid_message;
}
return invalid_message;
}
return invalid_message;
}
return invalid_message;
}
- save_addr_name(jm->get_addr(),jm->get_name());
+ save_addr_name(jm->get_addr(), jm->get_name());
if(timer_handle_->evtSource)
if(timer_handle_->evtSource)
AFB_DEBUG("Address colision");
if(jm->get_name() > htole64(J1939_NAME_ECU))
{
AFB_DEBUG("Address colision");
if(jm->get_name() > htole64(J1939_NAME_ECU))
{
- if(claim_address(false,false) < 0)
+ if(claim_address(false, false) < 0)
{
AFB_ERROR("Claim address failed");
change_state(claiming_state::INVALID);
{
AFB_ERROR("Claim address failed");
change_state(claiming_state::INVALID);
return invalid_message;
}
return invalid_message;
}
- save_addr_name(jm->get_addr(),jm->get_name());
+ save_addr_name(jm->get_addr(), jm->get_name());
- if(claim_address(false,true) < 0)
+ if(claim_address(false, true) < 0)
{
AFB_ERROR("Claim address failed");
change_state(claiming_state::INVALID);
{
AFB_ERROR("Claim address failed");
change_state(claiming_state::INVALID);
else
{
for (int i = start_addr; i <= end_addr; i++)
else
{
for (int i = start_addr; i <= end_addr; i++)
- table_j1939_address_[i] = std::make_pair(0,true);
+ table_j1939_address_[i] = std::make_pair(0, true);
* @param name The name of the ECU that is in the address
* @return int 0 if save is ok
*/
* @param name The name of the ECU that is in the address
* @return int 0 if save is ok
*/
- int socketcan_j1939_addressclaiming_t::save_addr_name(uint8_t addr,name_t name)
+ int socketcan_j1939_addressclaiming_t::save_addr_name(uint8_t addr, name_t name)
{
if(addr < J1939_IDLE_ADDR)
{
if(table_j1939_address_[addr].first < name)
{
table_j1939_address_[addr].first = name;
{
if(addr < J1939_IDLE_ADDR)
{
if(table_j1939_address_[addr].first < name)
{
table_j1939_address_[addr].first = name;
- AFB_DEBUG("[socketcan-j1939-addressclaiming][save_addr_name] NAME : %x <--> ADDR : %d",(unsigned int)name,addr);
+ AFB_DEBUG("[socketcan-j1939-addressclaiming][save_addr_name] NAME : %x <--> ADDR : %d",(unsigned int)name, addr);
}
else if(table_j1939_address_[addr].first == name)
{
}
else if(table_j1939_address_[addr].first == name)
{
- AFB_WARNING("Name %x has already adress %d",(unsigned int)name,addr);
+ AFB_WARNING("Name %x has already adress %d",(unsigned int)name, addr);
socketcan_j1939_addressclaiming_t *addressclaiming_socket = (socketcan_j1939_addressclaiming_t*) timerhandle->context;
// If the cache is cleared :
addressclaiming_socket->change_state(claiming_state::OPERATIONAL);
socketcan_j1939_addressclaiming_t *addressclaiming_socket = (socketcan_j1939_addressclaiming_t*) timerhandle->context;
// If the cache is cleared :
addressclaiming_socket->change_state(claiming_state::OPERATIONAL);
- addressclaiming_socket->save_addr_name(addressclaiming_socket->current_address_,htole64(J1939_NAME_ECU));
+ addressclaiming_socket->save_addr_name(addressclaiming_socket->current_address_, htole64(J1939_NAME_ECU));
AFB_DEBUG("Get address %d for this ecu", addressclaiming_socket->current_address_);
/*Else :
uint8_t data[3]= { 0, 0, 0, };
AFB_DEBUG("Get address %d for this ecu", addressclaiming_socket->current_address_);
/*Else :
uint8_t data[3]= { 0, 0, 0, };
- std::vector<uint8_t> data_v(data,data+3);
- int res = addressclaiming_socket->write_j1939_message(J1939_PGN_REQUEST,data_v,3);
+ std::vector<uint8_t> data_v(data, data+3);
+ int res = addressclaiming_socket->write_j1939_message(J1939_PGN_REQUEST, data_v, 3);
if(res < 0)
{
if(res == -99)
{
if(res < 0)
{
if(res == -99)
{
- addressclaiming_socket->save_addr_name(addressclaiming_socket->current_address_,htole64(1));
+ addressclaiming_socket->save_addr_name(addressclaiming_socket->current_address_, htole64(1));
AFB_DEBUG("Address busy but no claming request from other ECU");
AFB_DEBUG("Address busy but no claming request from other ECU");
- addressclaiming_socket->claim_address(false,true);
+ addressclaiming_socket->claim_address(false, true);
else
{
addressclaiming_socket->change_state(claiming_state::OPERATIONAL);
else
{
addressclaiming_socket->change_state(claiming_state::OPERATIONAL);
- addressclaiming_socket->save_addr_name(addressclaiming_socket->current_address_,htole64(J1939_NAME_ECU));
+ addressclaiming_socket->save_addr_name(addressclaiming_socket->current_address_, htole64(J1939_NAME_ECU));
AFB_DEBUG("Get address %d for this ecu", addressclaiming_socket->current_address_);
}*/
AFB_DEBUG("Get address %d for this ecu", addressclaiming_socket->current_address_);
}*/
* @param new_address If true, claim a new address, else only resend a claim with same address
* @return int -1 if fail
*/
* @param new_address If true, claim a new address, else only resend a claim with same address
* @return int -1 if fail
*/
- int socketcan_j1939_addressclaiming_t::claim_address(bool first_claim,bool new_address)
+ int socketcan_j1939_addressclaiming_t::claim_address(bool first_claim, bool new_address)
- int ret = socketcan_j1939_t::open(device_name_,htole64(J1939_NAME_ECU),J1939_NO_PGN,current_address_);
+ int ret = socketcan_j1939_t::open(device_name_, htole64(J1939_NAME_ECU), J1939_NO_PGN, current_address_);
}
AFB_DEBUG("[socketcan-j1939-addressclaiming][claim_address] Success open socket address claiming");
}
AFB_DEBUG("[socketcan-j1939-addressclaiming][claim_address] Success open socket address claiming");
- add_filter(J1939_NO_NAME,J1939_PGN_ADDRESS_CLAIMED,J1939_NO_ADDR,J1939_NO_NAME,J1939_PGN_PDU1_MAX,J1939_NO_ADDR);
+ add_filter(J1939_NO_NAME, J1939_PGN_ADDRESS_CLAIMED, J1939_NO_ADDR, J1939_NO_NAME, J1939_PGN_PDU1_MAX, J1939_NO_ADDR);
{
device_name_ = device_name;
initialize_table_j1939_address();
{
device_name_ = device_name;
initialize_table_j1939_address();
- if(claim_address(true,true) < 0)
+ if(claim_address(true, true) < 0)
{
AFB_ERROR("Claim address failed");
return -1;
{
AFB_ERROR("Claim address failed");
return -1;
std::pair<uint64_t, bool> table_j1939_address_[J1939_IDLE_ADDR];
private:
std::pair<uint64_t, bool> table_j1939_address_[J1939_IDLE_ADDR];
private:
- int claim_address(bool first_claim,bool new_address);
+ int claim_address(bool first_claim, bool new_address);
int pgn_request();
void initialize_table_j1939_address();
int pgn_request();
void initialize_table_j1939_address();
- int save_addr_name(uint8_t addr,name_t name);
+ int save_addr_name(uint8_t addr, name_t name);
uint8_t choose_new_address();
uint8_t get_addr_table(name_t name);
void change_state(claiming_state new_state);
uint8_t choose_new_address();
uint8_t get_addr_table(name_t name);
void change_state(claiming_state new_state);
*/
int socketcan_j1939_data_t::open(std::string device_name, pgn_t pgn)
{
*/
int socketcan_j1939_data_t::open(std::string device_name, pgn_t pgn)
{
- int ret = socketcan_j1939_t::open(device_name,htole64(J1939_NAME_ECU),pgn,J1939_NO_ADDR);
+ int ret = socketcan_j1939_t::open(device_name, htole64(J1939_NAME_ECU), pgn, J1939_NO_ADDR);
if(ret >= 0)
{
if(tx_address_.can_addr.j1939.pgn != J1939_NO_PGN)
if(ret >= 0)
{
if(tx_address_.can_addr.j1939.pgn != J1939_NO_PGN)
- add_filter(J1939_NO_NAME,tx_address_.can_addr.j1939.pgn,J1939_NO_ADDR,J1939_NO_NAME,J1939_NO_PGN,J1939_NO_ADDR);
+ add_filter(J1939_NO_NAME, tx_address_.can_addr.j1939.pgn, J1939_NO_ADDR, J1939_NO_NAME, J1939_NO_PGN, J1939_NO_ADDR);
*/
void socketcan_j1939_t::add_filter(name_t name, pgn_t pgn, uint8_t addr, name_t name_mask, pgn_t pgn_mask, uint8_t addr_mask)
{
*/
void socketcan_j1939_t::add_filter(name_t name, pgn_t pgn, uint8_t addr, name_t name_mask, pgn_t pgn_mask, uint8_t addr_mask)
{
- // AFB_DEBUG("[socketcan_j1939_t][add_filter] PGN : %" PRIu32 " ; NAME : %" PRIu64 " ; ADDR : %" PRIu8,pgn,(long unsigned int)name,addr);
- // AFB_DEBUG("PGN_MASK : %" PRIu32 " ; NAME_MASK : %" PRIu64 "; ADDR_MASK : %" PRIu8,pgn_mask,(long unsigned int)name_mask,addr_mask);
+ // AFB_DEBUG("[socketcan_j1939_t][add_filter] PGN : %" PRIu32 " ; NAME : %" PRIu64 " ; ADDR : %" PRIu8, pgn,(long unsigned int)name, addr);
+ // AFB_DEBUG("PGN_MASK : %" PRIu32 " ; NAME_MASK : %" PRIu64 "; ADDR_MASK : %" PRIu8, pgn_mask,(long unsigned int)name_mask, addr_mask);
int filter_on = 0;
struct j1939_filter filter;
memset(&filter, 0, sizeof(filter));
int filter_on = 0;
struct j1939_filter filter;
memset(&filter, 0, sizeof(filter));
*/
int socketcan_j1939_t::open(std::string device_name)
{
*/
int socketcan_j1939_t::open(std::string device_name)
{
- return open(device_name,0,0,0);
+ return open(device_name, 0, 0, 0);
socket_ = socketcan_t::open(PF_CAN, SOCK_DGRAM, CAN_J1939);
socket_ = socketcan_t::open(PF_CAN, SOCK_DGRAM, CAN_J1939);
- define_tx_address(device_name,name,pgn,addr);
+ define_tx_address(device_name, name, pgn, addr);
if(bind((struct sockaddr *)&tx_address_, sizeof(tx_address_)) < 0)
{
if(bind((struct sockaddr *)&tx_address_, sizeof(tx_address_)) < 0)
{
int socketcan_j1939_t::write_j1939_message(pgn_t pgn, std::vector<uint8_t> &data, uint32_t len_data)
{
j1939_message_t msg = j1939_message_t(len_data, data, 0, 0, pgn, 0);
int socketcan_j1939_t::write_j1939_message(pgn_t pgn, std::vector<uint8_t> &data, uint32_t len_data)
{
j1939_message_t msg = j1939_message_t(len_data, data, 0, 0, pgn, 0);
- msg.set_sockname(pgn,J1939_NO_NAME,J1939_NO_ADDR);
+ msg.set_sockname(pgn, J1939_NO_NAME, J1939_NO_ADDR);
return write_message(msg);
}
return write_message(msg);
}
{
if(write_message(vobj[i])<0)
{
{
if(write_message(vobj[i])<0)
{
- AFB_ERROR("Error send message %d",i);
+ AFB_ERROR("Error send message %d", i);