*/
#include <cstring>
-#include <sstream>
#include <iomanip>
#include <net/if.h>
#include "../../binding/low-can-hat.hpp"
+#include "../../utils/converter.hpp"
#include "j1939-message.hpp"
/**
/**
* @brief Construct a new j1939 message t::j1939 message t object
*
- * @param maxdlen The max length of the message
* @param length The length of the message
* @param format The format of the message
* @param data The vector data of the message
* @param pgn The PGN of the message
* @param addr The address of the message
*/
-j1939_message_t::j1939_message_t(uint32_t maxdlen,
- uint32_t length,
- message_format_t format,
+j1939_message_t::j1939_message_t(uint32_t length,
std::vector<uint8_t>& data,
uint64_t timestamp,
name_t name,
pgn_t pgn,
uint8_t addr):
- message_t(maxdlen,length, format, data, timestamp),
+ message_t(J1939_MAX_DLEN, length, J1939_PROTOCOL, data, timestamp),
name_{name},
pgn_{pgn},
addr_{addr}
return addr_;
}
-/**
- * @brief Convert hex data to string
- *
- * @param data An array of data
- * @param length The length of the data
- * @return std::string The string data
- */
-std::string to_hex( uint8_t data[], const size_t length)
-{
- std::stringstream stream;
- stream << std::hex << std::setfill('0');
- for(int i = 0; i < length; i++)
- {
- stream << std::hex << ((int) data[i]);
- }
- return stream.str();
-}
/// @brief Take a sockaddr_can struct and array of data to initialize class members
///
{
int i;
uint32_t length = 0;
- message_format_t format;
std::vector<uint8_t> data_vector;
if(nbytes > J1939_MAX_DLEN)
{
AFB_DEBUG("Unsupported j1939 frame");
- format = message_format_t::INVALID;
- }
- else
- {
- //AFB_DEBUG("Got a j1939 frame");
- format = message_format_t::J1939;
+ return std::make_shared<j1939_message_t>(j1939_message_t());
}
length = (uint32_t) nbytes;
data_vector.clear();
std::string data_string;
- data_string = to_hex(data,length);
+ data_string = converter_t::to_hex(data,length);
for(i=0;i<length;i++)
{
data_vector.push_back(data[i]);
};
- AFB_DEBUG("Found pgn: %X, format: %X, length: %X, data %s",
- addr.can_addr.j1939.pgn, (uint8_t)format, 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(J1939_MAX_DLEN,length, format, 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.
return get_pgn();
}
+void j1939_message_t::set_id(const canid_t id)
+{
+ pgn_ = id;
+}
+
+
/**
* @brief Return the sockname of the message
*