Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/hendrikmuhs/ccache…
Browse files Browse the repository at this point in the history
…-action-1.2.10
  • Loading branch information
EkelmansPh authored Nov 2, 2023
2 parents b5b3daa + 2889c8b commit ff7acf2
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 201 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ jobs:
name: Host Build & Test (ubuntu-latest)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.0.0
with:
persist-credentials: false
- uses: hendrikmuhs/ccache-action@6d1841ec156c39a52b1b23a810da917ab98da1f4 # v1.2.10
with:
key: ${{ github.job }}-ubuntu-latest
variant: sccache
- uses: seanmiddleditch/gha-setup-ninja@16b940825621068d98711680b6c3ff92201f8fc0 # v3
- uses: seanmiddleditch/gha-setup-ninja@8b297075da4cd2a5f1fd21fe011b499edf06e9d2 # v4
- uses: lukka/run-cmake@c2b72aff009141774c5a5fabe74ea46c8c04d9c4 # v10.6
with:
configurePreset: "host"
Expand All @@ -47,7 +47,7 @@ jobs:
matrix:
os: [windows-latest, windows-2019, macos-latest]
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.0.0
with:
persist-credentials: false
- uses: hendrikmuhs/ccache-action@6d1841ec156c39a52b1b23a810da917ab98da1f4 # v1.2.10
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
configuration: "RelWithDebInfo"
target: "stm32f767"
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install GNU Arm Embedded Toolchain ${{ matrix.gcc }}
uses: carlosperate/arm-none-eabi-gcc-action@6a221d7c85f5b36647d6e9b25e874abf187409d3 # v1.7.1
with:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/linting-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ jobs:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- uses: DoozyX/clang-format-lint-action@a83a8fb7d371f66da7dd1c4f33a193023899494b # v0.16
with:
clangFormatVersion: 15
inplace: true
extensions: "cpp,hpp"
- uses: reviewdog/action-suggester@3f60d0e826f0873905e0eeca522d562a6e67afbd # v1.7.1
- uses: reviewdog/action-suggester@94877e550e6b522dc1d21231974b645ff2f084ce # v1.8.0
with:
tool_name: clang-format
filter_mode: diff_context
Expand All @@ -38,23 +38,23 @@ jobs:
permissions:
pull-requests: write
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Run Linter
uses: oxsecurity/megalinter@fda6ac3a38be0e969820709ac16e442464e5a035 # v7.3.0
uses: oxsecurity/megalinter@b48455a119cc28045eee8f1e9d0a542a85e71f4f # v7.5.0
env:
APPLY_FIXES: all
VALIDATE_ALL_CODEBASE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Linter artifacts
if: ${{ success() }} || ${{ failure() }}
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
if: success() || failure()
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: linter
path: |
megalinter-reports
- uses: reviewdog/action-suggester@3f60d0e826f0873905e0eeca522d562a6e67afbd # v1.7.1
- uses: reviewdog/action-suggester@94877e550e6b522dc1d21231974b645ff2f084ce # v1.8.0
with:
tool_name: MegaLinter
filter_mode: diff_context
6 changes: 3 additions & 3 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ jobs:
actions: read
contents: read
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- name: Analysis
uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # v2.2.0
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
with:
results_file: scorecards.sarif
results_format: sarif
repo_token: ${{ secrets.SCORECARD_READ_TOKEN }}
publish_results: true
- uses: github/codeql-action/upload-sarif@1813ca74c3faaa3a2da2070b9b8a0b3e7373a0d8 # v2.21.0
- uses: github/codeql-action/upload-sarif@49abf0ba24d0b7953cb586944e918a0b92074c80 # v2.22.4
with:
sarif_file: scorecards.sarif
2 changes: 1 addition & 1 deletion .github/workflows/social-interaction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
pull-requests: write
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/first-interaction@1d8459ca65b335265f1285568221e229d45a995e
- uses: actions/first-interaction@1dbfe1ba5525b8257e1f259b09745bee346d62d8
continue-on-error: true
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
25 changes: 21 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
"configurations": [
{
"name": "stm32f767",
"cwd": "${workspaceFolder}",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"device": "STM32F767ZI",
"servertype": "external",
"showDevDebugOutput": "both",
"gdbTarget": "host.docker.internal:2331",
"overrideLaunchCommands": [
"monitor reset",
"-target-download",
"monitor reset"
],
"overrideRestartCommands": [ "monitor reset" ]
},
{
"name": "stm32f767 without container",
"cwd": "${workspaceRoot}",
"request": "launch",
"executable": "${command:cmake.launchTargetPath}",
Expand All @@ -14,21 +31,21 @@
"device": "STM32F767ZI"
},
{
"name": "stm32g431",
"name": "stm32g431 without container",
"cwd": "${workspaceRoot}",
"request": "launch",
"executable": "${command:cmake.launchTargetPath}",
"type": "cortex-debug",
"servertype": "stlink",
"servertype": "jlink",
"device": "STM32G431RB"
},
{
"name": "stm32g070",
"name": "stm32g070 without container",
"cwd": "${workspaceRoot}",
"request": "launch",
"executable": "${command:cmake.launchTargetPath}",
"type": "cortex-debug",
"servertype": "stlink",
"servertype": "jlink",
"device": "STM32G070RB"
}
]
Expand Down
7 changes: 1 addition & 6 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 24,
"patch": 0
},
"configurePresets": [
{
"name": "defaults",
Expand Down Expand Up @@ -43,11 +38,11 @@
"name": "stm32",
"hidden": true,
"inherits": "defaults",
"generator": "Ninja Multi-Config",
"environment": {
"CMAKE_TOOLCHAIN_FILE": ""
},
"cacheVariables": {
"generator": "Ninja Multi-Config",
"EMIL_GENERATE_PACKAGE_CONFIG": false,
"TARGET_MCU_VENDOR": "st"
}
Expand Down
140 changes: 58 additions & 82 deletions hal_st/middlewares/ble_middleware/GapCentralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace hal
6, // 7.5 ms
6, // 7.5 ms
0,
500,
50, // 500 ms
};

namespace
Expand Down Expand Up @@ -106,24 +106,6 @@ namespace hal
connectionParameters.supervisorTimeoutMs = evtConnectionUpdate->Supervision_Timeout * 10;
}

void GapCentralSt::HandleHciLeDataLengthChangeEvent(evt_le_meta_event* metaEvent)
{
GapSt::HandleHciLeDataLengthChangeEvent(metaEvent);

auto dataLengthChangeEvent = *reinterpret_cast<hci_le_data_length_change_event_rp0*>(metaEvent->data);

really_assert(dataLengthChangeEvent.Connection_Handle == connectionContext.connectionHandle);
}

void GapCentralSt::HandleHciLePhyUpdateCompleteEvent(evt_le_meta_event* metaEvent)
{
GapSt::HandleHciLePhyUpdateCompleteEvent(metaEvent);

auto phyUpdateCompleteEvent = *reinterpret_cast<hci_le_phy_update_complete_event_rp0*>(metaEvent->data);

really_assert(phyUpdateCompleteEvent.Status == BLE_STATUS_SUCCESS);
}

void GapCentralSt::HandleGapProcedureCompleteEvent(evt_blecore_aci* vendorEvent)
{
GapSt::HandleGapProcedureCompleteEvent(vendorEvent);
Expand All @@ -132,17 +114,8 @@ namespace hal

really_assert(gapProcedureEvent.Status == BLE_STATUS_SUCCESS);

switch (gapProcedureEvent.Procedure_Code)
{
case GAP_LIMITED_DISCOVERY_PROC:
case GAP_GENERAL_DISCOVERY_PROC:
if (gapProcedureEvent.Procedure_Code == GAP_LIMITED_DISCOVERY_PROC || gapProcedureEvent.Procedure_Code == GAP_GENERAL_DISCOVERY_PROC)
HandleGapDiscoveryProcedureEvent();
break;

case GAP_DIRECT_CONNECTION_ESTABLISHMENT_PROC:
HandleGapDirectConnectionEstablishmentEvent();
break;
}
}

void GapCentralSt::HandleGattCompleteEvent(evt_blecore_aci* vendorEvent)
Expand All @@ -151,12 +124,10 @@ namespace hal

auto gattCompleteEvent = *reinterpret_cast<aci_gatt_proc_complete_event_rp0*>(vendorEvent->data);

auto localOnConnection = std::exchange(onConnection, nullptr);

if (localOnConnection && gattCompleteEvent.Error_Code == BLE_STATUS_SUCCESS)
if (onMtuExchangeDone && gattCompleteEvent.Error_Code == BLE_STATUS_SUCCESS)
{
really_assert(gattCompleteEvent.Connection_Handle == connectionContext.connectionHandle);
infra::Subject<services::GapCentralObserver>::NotifyObservers(localOnConnection);
onMtuExchangeDone();
}
}

Expand All @@ -168,90 +139,95 @@ namespace hal

aci_l2cap_connection_parameter_update_resp(
l2capEvent.Connection_Handle, l2capEvent.Interval_Min, l2capEvent.Interval_Max, l2capEvent.Slave_Latency,
l2capEvent.Timeout_Multiplier, minConnectionEventLength, maxConnectionEventLength, l2capEvent.Identifier, acceptAllParameters);
l2capEvent.Timeout_Multiplier, minConnectionEventLength, maxConnectionEventLength, l2capEvent.Identifier, rejectParameters);

infra::EventDispatcherWithWeakPtr::Instance().Schedule([this]()
{
MtuExchange();
});
}

void GapCentralSt::HandleGapDiscoveryProcedureEvent()
void GapCentralSt::HandleHciLeDataLengthChangeEvent(evt_le_meta_event* metaEvent)
{
discovering = false;
GapSt::HandleHciLeDataLengthChangeEvent(metaEvent);

infra::Subject<services::GapCentralObserver>::NotifyObservers([](auto& observer) { observer.StateChanged(services::GapState::standby); });
}
auto dataLengthChangeEvent = *reinterpret_cast<hci_le_data_length_change_event_rp0*>(metaEvent->data);

void GapCentralSt::HandleGapDirectConnectionEstablishmentEvent()
{
onConnection = [](services::GapCentralObserver& observer)
{
observer.StateChanged(services::GapState::connected);
};
really_assert(dataLengthChangeEvent.Connection_Handle == connectionContext.connectionHandle);

SetPhy();
SetDataLength();
MtuExchange();
if (onDataLengthChanged)
onDataLengthChanged();
}

void GapCentralSt::SetPhy()
void GapCentralSt::HandleHciLePhyUpdateCompleteEvent(evt_le_meta_event* metaEvent)
{
infra::EventDispatcherWithWeakPtr::Instance().Schedule([this]()
GapSt::HandleHciLePhyUpdateCompleteEvent(metaEvent);

auto phyUpdateCompleteEvent = *reinterpret_cast<hci_le_phy_update_complete_event_rp0*>(metaEvent->data);

really_assert(phyUpdateCompleteEvent.Connection_Handle == connectionContext.connectionHandle);

infra::Subject<services::GapCentralObserver>::NotifyObservers([](services::GapCentralObserver& observer)
{
if (hci_le_set_phy(this->connectionContext.connectionHandle, GapSt::allPhys, GapSt::speed2Mbps, GapSt::speed2Mbps, 0) == commandDisallowed)
{
infra::EventDispatcherWithWeakPtr::Instance().Schedule([this]()
{
this->SetPhy();
});
}
observer.StateChanged(services::GapState::connected);
});
}

void GapCentralSt::SetDataLength() const
void GapCentralSt::HandleGapDiscoveryProcedureEvent()
{
infra::EventDispatcherWithWeakPtr::Instance().Schedule([this]()
discovering = false;

infra::Subject<services::GapCentralObserver>::NotifyObservers([](auto& observer)
{
hci_le_set_data_length(this->connectionContext.connectionHandle, services::GapConnectionParameters::connectionInitialMaxTxOctets, services::GapConnectionParameters::connectionInitialMaxTxTime);
observer.StateChanged(services::GapState::standby);
});
}

void GapCentralSt::MtuExchange() const
void GapCentralSt::MtuExchange()
{
infra::EventDispatcherWithWeakPtr::Instance().Schedule([this]()
{
if (aci_gatt_exchange_config(this->connectionContext.connectionHandle) == commandDisallowed)
{
infra::EventDispatcherWithWeakPtr::Instance().Schedule([this]()
{
this->MtuExchange();
});
}
});
onMtuExchangeDone = [this]()
{
SetDataLength();
};

auto status = aci_gatt_exchange_config(this->connectionContext.connectionHandle);
assert(status == BLE_STATUS_SUCCESS);
}

void GapCentralSt::SetDataLength()
{
onDataLengthChanged = [this]()
{
SetPhy();
};

auto status = hci_le_set_data_length(this->connectionContext.connectionHandle, services::GapConnectionParameters::connectionInitialMaxTxOctets, services::GapConnectionParameters::connectionInitialMaxTxTime);
assert(status == BLE_STATUS_SUCCESS);
}

void GapCentralSt::SetPhy() const
{
auto status = hci_le_set_phy(this->connectionContext.connectionHandle, GapSt::allPhys, GapSt::speed2Mbps, GapSt::speed2Mbps, 0);
assert(status == BLE_STATUS_SUCCESS);
}

void GapCentralSt::HandleAdvertisingReport(const Advertising_Report_t& advertisingReport)
{
services::GapAdvertisingReport discoveredDevice;

auto advertisementData = const_cast<uint8_t*>(&advertisingReport.Length_Data) + 1;
std::copy_n(std::begin(advertisingReport.Address), discoveredDevice.address.size(), std::begin(discoveredDevice.address));
discoveredDevice.eventType = ToAdvertisingEventType(advertisingReport.Event_Type);
discoveredDevice.addressType = ToAdvertisingAddressType(advertisingReport.Address_Type);
discoveredDevice.rssi = -static_cast<int8_t>(advertisingReport.RSSI);
std::copy_n(std::begin(advertisingReport.Address), discoveredDevice.address.size(), std::begin(discoveredDevice.address));

auto advertisementData = reinterpret_cast<const uint8_t*>(&advertisingReport.Length_Data) + 1;

discoveredDevice.data = infra::MemoryRange(advertisementData, advertisementData + advertisingReport.Length_Data);
discoveredDevice.rssi = static_cast<int8_t>(*const_cast<uint8_t*>(advertisementData + advertisingReport.Length_Data));

infra::Subject<services::GapCentralObserver>::NotifyObservers([&discoveredDevice](auto& observer)
{
observer.DeviceDiscovered(discoveredDevice);
});
}

void GapCentralSt::SetConnectionInterval() const
{
aci_l2cap_connection_parameter_update_req(connectionContext.connectionHandle,
connectionParameters.minConnIntMultiplier, connectionParameters.maxConnIntMultiplier,
connectionParameters.slaveLatency, connectionParameters.supervisorTimeoutMs);
}

void GapCentralSt::Initialize(const GapService& gapService)
{
uint16_t gapServiceHandle, gapDevNameCharHandle, gapAppearanceCharHandle;
Expand Down
Loading

0 comments on commit ff7acf2

Please sign in to comment.