Skip to content

Commit

Permalink
socktap: adjust style in Autotalks code
Browse files Browse the repository at this point in the history
  • Loading branch information
riebl committed Aug 20, 2023
1 parent 0dd221f commit db36aa3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 52 deletions.
60 changes: 28 additions & 32 deletions tools/socktap/autotalks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ static void* v2x_rx_thread_entry(void * arg);

int autotalks_device_init(void)
{
atlk_rc_t rc;
const char* arg[] = {NULL, SECTON_NET_NAME};
/** Reference system initialization */
#ifdef CRATON_2
rc = ref_sys_init_ex(1, (char**) arg);
#else
#ifdef SECTON
atlk_rc_t rc;
const char* arg[] = {NULL, SECTON_NET_NAME};
/** Reference system initialization */
#if defined(CRATON_2)
rc = ref_sys_init_ex(1, (char**) arg);
#elif defined(SECTON)
rc = ref_sys_init_ex(2, (char**) arg);
#else
#error Wrong configuration selected.
#endif
#else
#error Wrong configuration selected.
#endif

// TODO //
Expand All @@ -76,7 +74,7 @@ int autotalks_device_deinit(void)
{
endRxThread = true;
if (v2x_socket_ptr)
v2x_socket_delete(v2x_socket_ptr);
v2x_socket_delete(v2x_socket_ptr);

atlk_rc_t ret;

Expand All @@ -94,41 +92,39 @@ int autotalks_device_deinit(void)
atlk_rc_t autotalks_send(const void *data_ptr, size_t data_size,
const v2x_send_params_t *params_ptr, const atlk_wait_t *wait_ptr)
{
atlk_rc_t ret = 0;
if (v2x_socket_ptr == NULL)
fprintf(stderr, "Invalid socket.\n");
else if (v2x_socket_ptr != NULL)
ret = v2x_send(v2x_socket_ptr, data_ptr, data_size, params_ptr, wait_ptr);
// Check the return value
atlk_rc_t ret = 0;
if (v2x_socket_ptr == NULL)
fprintf(stderr, "Invalid socket.\n");
else if (v2x_socket_ptr != NULL)
ret = v2x_send(v2x_socket_ptr, data_ptr, data_size, params_ptr, wait_ptr);
// Check the return value
if (atlk_error(ret)) {
fprintf(stderr, "v2x_send failed: %d\n", ret);
fprintf(stderr, "v2x_send failed: %d\n", ret);
}
return ret;
}

atlk_rc_t autotalks_receive(void *data_ptr,
size_t *data_size_ptr,
v2x_receive_params_t *params_ptr,
const atlk_wait_t *wait_ptr)
atlk_rc_t autotalks_receive(void *data_ptr, size_t *data_size_ptr,
v2x_receive_params_t *params_ptr, const atlk_wait_t *wait_ptr)
{
return v2x_receive(v2x_socket_ptr, data_ptr, data_size_ptr, params_ptr, wait_ptr);
return v2x_receive(v2x_socket_ptr, data_ptr, data_size_ptr, params_ptr, wait_ptr);
}

vanetza::MacAddress num_to_mac(eui48_t addr)
{
return vanetza::MacAddress({addr.octets[0], addr.octets[1], addr.octets[2], addr.octets[3], addr.octets[4], addr.octets[5]});
return vanetza::MacAddress({addr.octets[0], addr.octets[1], addr.octets[2], addr.octets[3], addr.octets[4], addr.octets[5]});
}

eui48_t mac_to_num(vanetza::MacAddress addr)
{
eui48_t ret;
ret.octets[0] = addr.octets[0];
ret.octets[1] = addr.octets[1];
ret.octets[2] = addr.octets[2];
ret.octets[3] = addr.octets[3];
ret.octets[4] = addr.octets[4];
ret.octets[5] = addr.octets[5];
return ret;
eui48_t ret;
ret.octets[0] = addr.octets[0];
ret.octets[1] = addr.octets[1];
ret.octets[2] = addr.octets[2];
ret.octets[3] = addr.octets[3];
ret.octets[4] = addr.octets[4];
ret.octets[5] = addr.octets[5];
return ret;
}

void insert_autotalks_header_transmit(const vanetza::access::DataRequest& request, std::unique_ptr<vanetza::ChunkPacket>& packet, uint8_t* pData, uint16_t length)
Expand Down
4 changes: 1 addition & 3 deletions tools/socktap/autotalks.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef AUTOTALKS_HPP_
#define AUTOTALKS_HPP_

#include <cstddef>
#include <memory>
#include <vanetza/net/mac_address.hpp>
#include <vanetza/access/data_request.hpp>
#include <vanetza/net/chunk_packet.hpp>
#include <vanetza/net/ethernet_header.hpp>
#include <vanetza/net/cohesive_packet.hpp>
#include "stddef.h"
#include "atlk/sdk.h"
#include "atlk/v2x_service.h"
#include "autotalks_link.hpp"
Expand Down Expand Up @@ -66,6 +66,4 @@ void init_rx(AutotalksLink*);
} // namespace autotalks
} // namespace vanetza


#endif /* AUTOTALKS_HPP_ */

23 changes: 11 additions & 12 deletions tools/socktap/autotalks_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ AutotalksLink::~AutotalksLink(void)

void AutotalksLink::request(const vanetza::access::DataRequest& request, std::unique_ptr<vanetza::ChunkPacket> packet)
{
uint8_t toSend[SendBufferSize];
size_t j = 0;
uint8_t toSend[SendBufferSize];
size_t j = 0;

constexpr std::size_t layers = num_osi_layers(vanetza::OsiLayer::Physical, vanetza::OsiLayer::Application);
constexpr std::size_t layers = num_osi_layers(vanetza::OsiLayer::Physical, vanetza::OsiLayer::Application);
std::array<boost::asio::const_buffer, layers> const_buffers;
for (auto& layer : vanetza::osi_layer_range<vanetza::OsiLayer::Physical, vanetza::OsiLayer::Application>()) {
const auto index = distance(vanetza::OsiLayer::Physical, layer);
packet->layer(layer).convert(buffers_[index]);
const_buffers[index] = boost::asio::buffer(buffers_[index]);

for (size_t i = 0; i < buffers_[index].size() && j < SendBufferSize; i++)
toSend[j++] = buffers_[index][i];
toSend[j++] = buffers_[index][i];
}

uint16_t datalen = j;
Expand All @@ -37,17 +37,16 @@ void AutotalksLink::request(const vanetza::access::DataRequest& request, std::un

void AutotalksLink::data_received(uint8_t* pBuf, uint16_t size, v2x_receive_params_t rx_params)
{
vanetza::ByteBuffer buffer(size);
for (uint16_t i = 0; i < size; i++)
buffer[i] = pBuf[i];
vanetza::CohesivePacket packet(std::move(buffer), vanetza::OsiLayer::Physical);
boost::optional<vanetza::EthernetHeader> eth = vanetza::autotalks::strip_autotalks_rx_header(packet, rx_params);
if (callback_ && eth)
callback_(std::move(packet), *eth);
vanetza::ByteBuffer buffer(size);
for (uint16_t i = 0; i < size; i++)
buffer[i] = pBuf[i];
vanetza::CohesivePacket packet(std::move(buffer), vanetza::OsiLayer::Physical);
boost::optional<vanetza::EthernetHeader> eth = vanetza::autotalks::strip_autotalks_rx_header(packet, rx_params);
if (callback_ && eth)
callback_(std::move(packet), *eth);
}

void AutotalksLink::indicate(IndicationCallback cb)
{
callback_ = cb;
}

1 change: 0 additions & 1 deletion tools/socktap/autotalks_link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
class AutotalksLink : public LinkLayer
{
public:

/*
* Constructor used for device and thread initialization.
*/
Expand Down
7 changes: 3 additions & 4 deletions tools/socktap/link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#endif

#ifdef SOCKTAP_WITH_AUTOTALKS
# include "autotalks_link.hpp"
# include "autotalks.hpp"
# include "autotalks_link.hpp"
# include "autotalks.hpp"
#endif

boost::optional<std::pair<boost::asio::ip::address, unsigned short>> parse_ip_port(const std::string& ip_port)
Expand Down Expand Up @@ -90,8 +90,7 @@ create_link_layer(boost::asio::io_service& io_service, const EthernetDevice& dev

link_layer.reset(tcp);

}
else if (name == "autotalks") {
} else if (name == "autotalks") {
#ifdef SOCKTAP_WITH_AUTOTALKS
link_layer.reset(new AutotalksLink { });
#endif
Expand Down

0 comments on commit db36aa3

Please sign in to comment.