Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/gapperipheral…
Browse files Browse the repository at this point in the history
…_connection_interval_expose
  • Loading branch information
oguzcanoguz committed Mar 10, 2025
2 parents e9de553 + c4c26e0 commit ee48311
Show file tree
Hide file tree
Showing 17 changed files with 639 additions and 323 deletions.
2 changes: 1 addition & 1 deletion .clusterfuzzlite/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gcr.io/oss-fuzz-base/base-builder@sha256:1314b399d2db5f4274bea94e340325aae7ba9b1e8b30fbb77dabcf3cd785af28
FROM gcr.io/oss-fuzz-base/base-builder@sha256:27e8f4f46adcf23c78a3122e016cdbf4a821bffb28a2cd83a4f2fc7c8b4e1849

HEALTHCHECK NONE

Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM ghcr.io/philips-software/amp-devcontainer-cpp:v5.6.0@sha256:884732270a353e8446f813e649f2918ac53ce446a6c0dd4f7f84a6d58fb26bce
FROM ghcr.io/philips-software/amp-devcontainer-cpp:v5.6.1@sha256:04cda0c73cd01f0d97879aba7871c5118147ea0478616c49e8c0643653fbbc8b

HEALTHCHECK NONE
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
host_build_test_container:
name: Host Build & Test (amp-devcontainer-cpp)
runs-on: ubuntu-latest
container: ghcr.io/philips-software/amp-devcontainer-cpp:5.6.0@sha256:884732270a353e8446f813e649f2918ac53ce446a6c0dd4f7f84a6d58fb26bce
container: ghcr.io/philips-software/amp-devcontainer-cpp:v5.6.1@sha256:04cda0c73cd01f0d97879aba7871c5118147ea0478616c49e8c0643653fbbc8b
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
Expand All @@ -74,7 +74,7 @@ jobs:
host_build_test_clang_msvc:
name: Host Build & Test (clang-msvc)
runs-on: ubuntu-latest
container: ghcr.io/philips-software/amp-devcontainer-cpp:5.6.0@sha256:884732270a353e8446f813e649f2918ac53ce446a6c0dd4f7f84a6d58fb26bce
container: ghcr.io/philips-software/amp-devcontainer-cpp:v5.6.1@sha256:04cda0c73cd01f0d97879aba7871c5118147ea0478616c49e8c0643653fbbc8b
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
sonar:
name: SonarCloud
runs-on: ubuntu-latest
container: ghcr.io/philips-software/amp-devcontainer-cpp:5.6.0@sha256:884732270a353e8446f813e649f2918ac53ce446a6c0dd4f7f84a6d58fb26bce
container: ghcr.io/philips-software/amp-devcontainer-cpp:v5.6.1@sha256:04cda0c73cd01f0d97879aba7871c5118147ea0478616c49e8c0643653fbbc8b
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
codeql:
name: CodeQL
runs-on: ubuntu-latest
container: ghcr.io/philips-software/amp-devcontainer-cpp:5.6.0@sha256:884732270a353e8446f813e649f2918ac53ce446a6c0dd4f7f84a6d58fb26bce
container: ghcr.io/philips-software/amp-devcontainer-cpp:v5.6.1@sha256:04cda0c73cd01f0d97879aba7871c5118147ea0478616c49e8c0643653fbbc8b
permissions:
security-events: write
steps:
Expand Down
6 changes: 3 additions & 3 deletions external/crypto/mbedtls/mbedtls_emil_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2570,7 +2570,7 @@
*
* Uncomment to enable generic public key write functions.
*/
//#define MBEDTLS_PK_WRITE_C
#define MBEDTLS_PK_WRITE_C

/**
* \def MBEDTLS_PKCS5_C
Expand Down Expand Up @@ -3007,7 +3007,7 @@
*
* This module is the basis for creating X.509 certificates and CSRs.
*/
//#define MBEDTLS_X509_CREATE_C
#define MBEDTLS_X509_CREATE_C

/**
* \def MBEDTLS_X509_CRT_WRITE_C
Expand All @@ -3020,7 +3020,7 @@
*
* This module is required for X.509 certificate creation.
*/
//#define MBEDTLS_X509_CRT_WRITE_C
#define MBEDTLS_X509_CRT_WRITE_C

/**
* \def MBEDTLS_X509_CSR_WRITE_C
Expand Down
46 changes: 24 additions & 22 deletions hal/unix/UartUnix.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#include "hal/unix/UartUnix.hpp"
#include "hal/unix/UartUnixBase.hpp"
#include "infra/event/EventDispatcher.hpp"
#include "infra/util/ByteRange.hpp"
#include "infra/util/Function.hpp"
#include <cerrno>
#include <mutex>
#include <stdexcept>
#include <string>
#include <system_error>
#include <thread>
#ifdef EMIL_OS_DARWIN
#include <IOKit/serial/ioss.h>
#else
Expand All @@ -15,21 +23,12 @@ namespace hal

UartUnix::UartUnix(const std::string& portName, const Config& config)
: UartUnixBase(portName, config)
, readThread{ [this]()
{
Read();
} }
{
}

UartUnix::~UartUnix()
{
{
std::unique_lock lock(mutex);
running = false;
receivedDataSet.notify_all();
}

running = false;
if (readThread.joinable())
readThread.join();
}
Expand All @@ -49,21 +48,22 @@ namespace hal

void UartUnix::ReceiveData(infra::Function<void(infra::ConstByteRange data)> dataReceived)
{
std::unique_lock lock(mutex);
receivedData = dataReceived;
receivedDataSet.notify_all();
}
running = true;

void UartUnix::Read()
{
{
std::unique_lock lock(mutex);
receivedDataSet.wait(lock, [this]
std::unique_lock lock(receivedDataMutex);
receivedData = dataReceived;
}

if (!readThread.joinable())
readThread = std::thread([this]
{
return static_cast<bool>(receivedData);
Read();
});
}
}

void UartUnix::Read()
{
while (running)
{
auto range = infra::MakeByteRange(buffer);
Expand All @@ -72,9 +72,11 @@ namespace hal
if (size < 0)
throw std::system_error(EFAULT, std::system_category());

std::unique_lock lock(mutex);
if (receivedData != nullptr)
if (running)
{
std::unique_lock lock(receivedDataMutex);
receivedData(infra::ConstByteRange(range.begin(), range.begin() + size));
}
}
}
}
9 changes: 5 additions & 4 deletions hal/unix/UartUnix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

#include "hal/interfaces/SerialCommunication.hpp"
#include "hal/unix/UartUnixBase.hpp"
#include "infra/util/ByteRange.hpp"
#include "infra/util/Function.hpp"
#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <mutex>
#include <string>
#include <thread>
Expand All @@ -30,10 +32,9 @@ namespace hal

private:
uint8_t buffer;
std::atomic<bool> running{ true };
std::mutex mutex;
std::condition_variable receivedDataSet;
std::atomic<bool> running{ false };
std::thread readThread;
std::mutex receivedDataMutex;
infra::Function<void(infra::ConstByteRange data)> receivedData;
};
}
Expand Down
2 changes: 1 addition & 1 deletion infra/stream/ConstructBinStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ namespace infra
ConstructBin& operator<<(ConstructBin&& constructBin, const TextStreamHelper& helper)
{
helper.callback(infra::StdVectorOutputStream(constructBin.Vector()) << infra::text);
return constructBin;
return static_cast<ConstructBin&>(constructBin);
}
}
2 changes: 1 addition & 1 deletion infra/syntax/Json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ namespace infra

JsonValue JsonObject::GetValue(infra::BoundedConstString key)
{
for (auto& keyValue : *this)
for (const auto& keyValue : *this)
{
if (keyValue.key == key)
return keyValue.value;
Expand Down
46 changes: 45 additions & 1 deletion infra/syntax/Json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

#include "infra/stream/OutputStream.hpp"
#include "infra/util/BoundedString.hpp"
#include "infra/util/Compatibility.hpp"
#include "infra/util/Optional.hpp"
#include "infra/util/ReverseRange.hpp"
#include "infra/util/Variant.hpp"
#include <cstdint>

#ifdef EMIL_HOST_BUILD
#include <string>
Expand Down Expand Up @@ -293,6 +295,9 @@ namespace infra
JsonArray GetArray(infra::BoundedConstString key);
JsonValue GetValue(infra::BoundedConstString key);

template<class T>
T GetIntegerAs(infra::BoundedConstString key);

infra::Optional<JsonString> GetOptionalString(infra::BoundedConstString key);
infra::Optional<JsonFloat> GetOptionalFloat(infra::BoundedConstString key);
infra::Optional<bool> GetOptionalBoolean(infra::BoundedConstString key);
Expand All @@ -313,6 +318,9 @@ namespace infra
template<class T>
infra::Optional<T> GetOptionalValue(infra::BoundedConstString key);

template<class T>
T ConvertValueTo(std::uint64_t value, bool negative);

private:
infra::BoundedConstString objectString;
bool error = false;
Expand Down Expand Up @@ -492,7 +500,6 @@ namespace infra
JsonValueArrayIterator() = default;
JsonValueArrayIterator(const JsonArrayIterator& arrayIterator, const JsonArrayIterator& arrayEndIterator);

public:
bool operator==(const JsonValueArrayIterator& other) const;
bool operator!=(const JsonValueArrayIterator& other) const;

Expand All @@ -517,6 +524,43 @@ namespace infra

//// Implementation ////

template<class T>
T JsonObject::GetIntegerAs(infra::BoundedConstString key)
{
const auto jsonValue = GetValue(key);

if (jsonValue.Is<int32_t>())
return ConvertValueTo<T>(std::abs(static_cast<int64_t>(jsonValue.Get<int32_t>())), jsonValue.Get<int32_t>() < 0);
else if (jsonValue.Is<JsonBiggerInt>())
return ConvertValueTo<T>(jsonValue.Get<JsonBiggerInt>().Value(), jsonValue.Get<JsonBiggerInt>().Negative());

SetError();
return {};
}

template<class T>
T JsonObject::ConvertValueTo(std::uint64_t value, bool negative)
{
if (negative)
{
// the offset by one (twice) is to prevent overflow when converting a uint64_t
// to a int64_t, where the uint64_t value is equal to the absolute of
// std::numeric_limits<int64_t>::min(), which is equivalent to
// 9223372036854775808, which can't be represented in a int64_t.
// the offset first reduces the 9223372036854775808 to 9223372036854775807
// which can be represented in a int64_t, and the second offset is to
// convert -9223372036854775807 back to -9223372036854775808
const auto signedValue = (static_cast<int64_t>(value - 1) * -1) - 1;
if (signedValue < 0 && infra::in_range<T>(signedValue))
return static_cast<T>(signedValue);
}
else if (infra::in_range<T>(value))
return static_cast<T>(value);

SetError();
return {};
}

template<class T>
JsonValueArrayIterator<T>::JsonValueArrayIterator(const JsonArrayIterator& arrayIterator, const JsonArrayIterator& arrayEndIterator)
: arrayIterator(arrayIterator)
Expand Down
5 changes: 5 additions & 0 deletions infra/syntax/JsonFormatter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "infra/syntax/JsonFormatter.hpp"
#include "infra/syntax/EscapeCharacterHelper.hpp"
#include "infra/syntax/Json.hpp"
#include "infra/util/BoundedVector.hpp"

namespace infra
Expand Down Expand Up @@ -369,6 +370,8 @@ namespace infra
Add(keyValue.key, keyValue.value.Get<bool>());
else if (keyValue.value.Is<int32_t>())
Add(keyValue.key, keyValue.value.Get<int32_t>());
else if (keyValue.value.Is<JsonBiggerInt>())
Add(keyValue.key, keyValue.value.Get<JsonBiggerInt>());
else if (keyValue.value.Is<JsonString>())
Add(keyValue.key, keyValue.value.Get<JsonString>());
else if (keyValue.value.Is<JsonObject>())
Expand All @@ -385,6 +388,8 @@ namespace infra
Add(key, value.Get<bool>());
else if (value.Is<int32_t>())
Add(key, value.Get<int32_t>());
else if (value.Is<JsonBiggerInt>())
Add(key, value.Get<JsonBiggerInt>());
else if (value.Is<JsonFloat>())
Add(key, value.Get<JsonFloat>());
else if (value.Is<JsonString>())
Expand Down
Loading

0 comments on commit ee48311

Please sign in to comment.