Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci-cd-multi-platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ jobs:
}
- {
name: "macOS Clang",
os: [self-hosted, macOS, ARM64],
os: macos-latest,
shell: "bash",
generator: "Unix Makefiles",
cc: "clang",
cxx: "clang++",
jobs_count: 4,
initial_cache: ".github/workflows/macos_initial_cache.txt",
}

Expand Down
51 changes: 32 additions & 19 deletions aether/format/default_formatters.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
#ifndef AETHER_FORMAT_DEFAULT_FORMATTERS_H_
#define AETHER_FORMAT_DEFAULT_FORMATTERS_H_

#include <iomanip>
#include <memory>
#include <cassert>
#include <cstdint>
#include <optional>
#include <iostream>
#include <charconv>
#include <type_traits>
#include <string_view>

Expand Down Expand Up @@ -55,17 +56,7 @@ template <typename T>
struct Formatter<
T, std::enable_if_t<IsStreamOutputSpecified<T>::value &&
!IstextSpecified<T>::value && !std::is_enum_v<T> &&
!std::is_integral_v<T> && !IsTimePoint<T>::value &&
!IsDuration<T>::value>> {
template <typename TStream>
void Format(T const& value, FormatContext<TStream>& ctx) const {
ctx.out().stream() << value;
}
};

// for any integral type
template <typename T>
struct Formatter<T, std::enable_if_t<std::is_integral_v<T>>> {
!IsTimePoint<T>::value && !IsDuration<T>::value>> {
template <typename TStream>
void Format(T const& value, FormatContext<TStream>& ctx) const {
ctx.out().stream() << value;
Expand Down Expand Up @@ -131,16 +122,38 @@ struct Formatter<T, std::enable_if_t<!(IsString<std::decay_t<T>>::value ||

template <typename TStream>
void FormatBuffer(T const& value, FormatContext<TStream>& ctx) const {
ctx.out().stream() << std::setfill('0');
for (auto it = std::begin(value); it != std::end(value); ++it) {
ctx.out().stream() << std::setw(2) << std::hex;
if constexpr (std::is_unsigned_v<typename T::value_type>) {
ctx.out().stream() << std::uint64_t{*it};
static_assert(sizeof(typename T::value_type) == 1,
"Print buffer only for one byte size values");

constexpr std::size_t kLocalBuffSize = 128;
constexpr std::size_t kTwoMinCharValue = 0x10;
constexpr int kPrintBase = 16;
std::size_t v_size = 2; // 2 chars on byte
std::size_t buff_size = v_size * value.size();

std::array<char, kLocalBuffSize> local_buff;
std::unique_ptr<char[]> alloc_buff; // NOLINT(*avoid-c-arrays)

char* buff; // NOLINT(*init-variables)
if (buff_size > local_buff.size()) {
alloc_buff =
std::make_unique<char[]>(buff_size); // NOLINT(*avoid-c-arrays)
buff = alloc_buff.get();
} else {
buff = local_buff.data();
}
std::size_t wp = 0;
for (auto const& v : value) {
// convert value with leading 0
if (v < kTwoMinCharValue) {
*(buff + wp) = '0';
std::to_chars(buff + wp + 1, buff + wp + v_size, v, kPrintBase);
} else {
ctx.out().stream() << std::int64_t{*it};
std::to_chars(buff + wp, buff + wp + v_size, v, kPrintBase);
}
wp += v_size;
}
ctx.out().stream() << std::setfill(' ') << std::setw(0) << std::dec;
ctx.out().stream().write(buff, static_cast<std::streamsize>(wp));
}
};

Expand Down
3 changes: 1 addition & 2 deletions aether/poller/epoll_poller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void EpollImpl::Callback(DescriptorType fd, EventCb cb) {
}

void EpollImpl::Event(DescriptorType fd, EventType events) {
AE_TELED_DEBUG("Poller event for fd:{} events: {}", fd,
static_cast<std::uint8_t>(events));
AE_TELED_DEBUG("Poller event for fd:{} events: {}", fd, events);
auto it = event_map_.find(fd);
if (it == event_map_.end()) {
assert(false && "Callback should setup first");
Expand Down
3 changes: 1 addition & 2 deletions aether/safe_stream/details/safe_stream_send_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ class SafeStreamSendAction {
[this, range{selected_sch.range}]() {
repeat_timer_.Reset();
ProcessRepeat(range);
// enqueue repeat timeout for the next chunk
EnqueueRepeatTimeout();
},
wait_time);
}
Expand Down Expand Up @@ -302,6 +300,7 @@ class SafeStreamSendAction {
return RegisterChunk(dspan, chunk_index_range, current_time);
});
if (!res) {
AE_TELED_DEBUG("Send chunk error {}", res.error());
// If any error over empty buffer
if (res.error() != 0) {
AE_TELED_ERROR("Chunk send error!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ std::optional<std::size_t> LwipCBUdpSocket::Send(Span<std::uint8_t> data) {
memcpy(p->payload, data.data(), data.size());

err = udp_send(pcb_, p);

if (err != ERR_OK) {
AE_TELED_ERROR("Send failed: {}", err);
if (err == ERR_MEM) {
// internal buffer is full
return 0;
}
AE_TELED_ERROR("Send failed: {}", static_cast<int>(err));
OnError();
return std::nullopt;
}
Expand Down
5 changes: 5 additions & 0 deletions aether/transport/system_sockets/tcp/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class SendAction final : public PacketSendAction {
SetStatus(WriteAction::Status::kFail);
return;
}
if (*res == 0) {
reenqueue_ = true;
return;
}

AE_TELED_DEBUG("Data has been written size {} data {}", *res, data_);
sent_offset_ += *res;

Expand Down
6 changes: 4 additions & 2 deletions aether/transport/system_sockets/udp/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SendAction final : public PacketSendAction {
AE_CLASS_MOVE_ONLY(SendAction)

void Send() override {
reenqueue_ = false;
auto res = socket_->Send(Span{data_.data(), data_.size()});
if (!res) {
AE_TELED_ERROR("Data has not been written");
Expand All @@ -62,6 +63,7 @@ class SendAction final : public PacketSendAction {
AE_TELED_DEBUG("Data has been written size {}", data_.size());

if (*res == 0) {
reenqueue_ = true;
// Not sent yet
return;
}
Expand All @@ -80,7 +82,7 @@ class SendAction final : public PacketSendAction {
}

bool is_done() const override { return is_done_; }
bool re_enqueue() const override { return reenque_; }
bool re_enqueue() const override { return reenqueue_; }

protected:
void SetStatus(WriteAction::Status status) noexcept override {
Expand All @@ -93,7 +95,7 @@ class SendAction final : public PacketSendAction {
AeContext ae_context_;
Socket* socket_;
DataBuffer data_;
bool reenque_ = false;
bool reenqueue_ = false;
bool is_done_ = false;
TaskSubscription set_status_;
};
Expand Down
34 changes: 30 additions & 4 deletions aether/types/uid.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#include <cstdint>
#include <cstddef>
#include <cassert>
#include <charconv>
#include <string_view>

#include "aether/type_traits.h"
#include "aether/types/span.h"
#include "aether/format/format.h"
#include "aether/reflect/reflect.h"
#include "aether/types/literal_array.h"
Expand Down Expand Up @@ -102,9 +102,35 @@ template <>
struct Formatter<Uid> {
template <typename TStream>
void Format(Uid const& uid, FormatContext<TStream>& ctx) const {
ae::Format(ctx.out(), "{}-{}-{}-{}-{}", Span{uid.value.data(), 4},
Span{uid.value.data() + 4, 2}, Span{uid.value.data() + 6, 2},
Span{uid.value.data() + 8, 2}, Span{uid.value.data() + 10, 6});
constexpr std::uint8_t kMinTwoCharsValue = 0x10;
constexpr int kPrintBase = 16;
// each hex value takes 2 chars + 4 '-'
std::array<char, (Uid::kSize * 2) + 4> buff;
std::size_t wp = 0;

for (std::size_t i = 0; i < Uid::kSize; i++) {
switch (i) {
case 4:
case 6:
case 8:
case 10:
buff[wp++] = '-';
break;
default:
break;
}
auto v = uid.value[i];
// convert value with leading 0
if (v < kMinTwoCharsValue) {
*(buff.data() + wp) = '0';
std::to_chars(buff.data() + wp + 1, buff.data() + wp + 2, v,
kPrintBase);
} else {
std::to_chars(buff.data() + wp, buff.data() + wp + 2, v, kPrintBase);
}
wp += 2;
}
ctx.out().stream().write(buff.data(), buff.size());
}
};

Expand Down
19 changes: 8 additions & 11 deletions aether/wifi/esp_wifi_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void EventHandler(void* arg, esp_event_base_t event_base, int32_t event_id,
case EspWifiDriver::State::kDisconnected:
driver->DisconnectedEventHandler(event_base, event_id, event_data);
break;
case EspWifiDriver::State::kDisconnecring:
case EspWifiDriver::State::kDisconnecting:
driver->DisconnectingEventHandler(event_base, event_id, event_data);
break;
case EspWifiDriver::State::kConnecting:
Expand Down Expand Up @@ -236,13 +236,6 @@ void StartWifiConnection(esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap,
AE_TELED_DEBUG("Using DHCP for IP configuration");
}

wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
// We disable aggregation so that the packages go out one by one and quickly
wifi_init_config.ampdu_rx_enable = 0;
wifi_init_config.ampdu_tx_enable = 0;

ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_config));

ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
if (psp) {
Expand Down Expand Up @@ -310,8 +303,12 @@ void EspWifiDriver::Init() {

espt_init_sta_ = esp_netif_create_default_wifi_sta();

wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
// We disable aggregation so that the packages go out one by one and quickly
wifi_init_config.ampdu_rx_enable = 0;
wifi_init_config.ampdu_tx_enable = 0;

ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_config));

esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID,
esp_wifi_driver_internal::EventHandler, this);
Expand Down Expand Up @@ -342,7 +339,7 @@ void EspWifiDriver::Deinit() {
}

void EspWifiDriver::Disconnect() {
connection_state_.state = State::kDisconnecring;
connection_state_.state = State::kDisconnecting;
connected_to_.reset();
esp_wifi_disconnect();
esp_wifi_stop();
Expand Down
2 changes: 1 addition & 1 deletion aether/wifi/esp_wifi_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class EspWifiDriver final : public WifiDriver {
public:
enum class State : char {
kDisconnected,
kDisconnecring,
kDisconnecting,
kConnecting,
kConnected,
};
Expand Down
57 changes: 57 additions & 0 deletions aether/work_cloud_api/client_api/client_api_safe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@
#include "aether/tele/tele.h"

namespace ae {

ClientApiSafe::ClientApiSafe(ProtocolContext& protocol_context)
: ApiClassImpl{protocol_context}, return_result{protocol_context} {}

void ClientApiSafe::ChangeParent([[maybe_unused]] Uid const& uid) {
AE_TELED_DEBUG("ChangeParent");
}

void ClientApiSafe::ChangeAlias([[maybe_unused]] Uid const& uid) {
AE_TELED_DEBUG("ChangeAlias");
}

void ClientApiSafe::NewChildren([[maybe_unused]] std::vector<Uid> const& uids) {
AE_TELED_DEBUG("NewChildren");
}

void ClientApiSafe::SendMessages(std::vector<AeMessage> const& messages) {
for (auto const& msg : messages) {
AE_TELED_DEBUG("Received message uid:{}", msg.uid);
Expand Down Expand Up @@ -58,4 +71,48 @@ void ClientApiSafe::SendClouds(

void ClientApiSafe::RequestTelemetry() { request_telemetry_event_.Emit(); }

void ClientApiSafe::SendAccessGroups(
[[maybe_unused]] std::vector<AccessGroup> const& access_group) {
AE_TELED_DEBUG("SendAccessGroups");
}
void ClientApiSafe::SendAccessGroupForClient(
[[maybe_unused]] Uid const& uid,
[[maybe_unused]] std::vector<std::uint64_t> const& groups) {
AE_TELED_DEBUG("SendAccessGroupForClient");
}
void ClientApiSafe::AddItemsToAccessGroup(
[[maybe_unused]] std::uint64_t id,
[[maybe_unused]] std::vector<Uid> const& groups) {
AE_TELED_DEBUG("AddItemsToAccessGroup");
}
void ClientApiSafe::RemoveItemsFromAccessGroup(
[[maybe_unused]] std::uint64_t id,
[[maybe_unused]] std::vector<Uid> const& groups) {
AE_TELED_DEBUG("RemoveItemsFromAccessGroup");
}
void ClientApiSafe::AddAccessGroupsToClient(
[[maybe_unused]] Uid const& uid,
[[maybe_unused]] std::vector<std::uint64_t> const& groups) {
AE_TELED_DEBUG("AddAccessGroupsToClient");
}
void ClientApiSafe::RemoveAccessGroupsFromClient(
[[maybe_unused]] Uid const& uid,
[[maybe_unused]] std::vector<std::uint64_t> const& groups) {
AE_TELED_DEBUG("RemoveAccessGroupsFromClient");
}
void ClientApiSafe::SendAllAccessedClients(
[[maybe_unused]] Uid const& uid,
[[maybe_unused]] std::vector<Uid> const& accessed_clients) {
AE_TELED_DEBUG("SendAllAccessedClients");
}
void ClientApiSafe::SendAccessCheckResults(
[[maybe_unused]] std::vector<AccessCheckResult> const& results) {
AE_TELED_DEBUG("SendAccessCheckResults");
}

void ClientApiSafe::SendMessage(AeMessage const& msg) {
AE_TELED_DEBUG("Received message uid:{}", msg.uid);
send_message_event_.Emit(msg);
}

} // namespace ae
Loading
Loading