Skip to content

Commit

Permalink
Merge branch 'develop' into feature/ota
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Nov 28, 2023
2 parents cee4aad + f4dbc8c commit 38a7aaa
Show file tree
Hide file tree
Showing 16 changed files with 432 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OPENSHOCK_API_DOMAIN=api.shocklink.net
OPENSHOCK_FW_VERSION=0.0.0-unknown
OPENSHOCK_FW_HOSTNAME=OpenShock
OPENSHOCK_FW_AP_PREFIX=OpenShock-
OPENSHOCK_FW_AP_PREFIX=OpenShock-
95 changes: 95 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: 'CodeQL'

on:
push:
branches: ['master']
pull_request:
branches: ['master']
schedule:
- cron: '0 6 * * 1'

env:
NODE_VERSION: 16
PYTHON_VERSION: 3.12
OPENSHOCK_API_DOMAIN: api.shocklink.net
# OPENSHOCK_FW_VERSION:
# - If this is branch "master" or "develop", we use "0.0.0-master" or "0.0.0-develop" respectively.
# - All other scenarios we use "0.0.0-unknown", as we cannot guarantee SemVer compliance by accepting any branch name. So this is the safe option.
OPENSHOCK_FW_VERSION: ${{ (contains(fromJSON('["master","develop"]'), github.ref_name) && format('0.0.0-{0}', github.ref_name)) || '0.0.0-unknown' }}
OPENSHOCK_FW_COMMIT: ${{ github.sha }}

jobs:
get-targets:
uses: ./.github/workflows/get-targets.yml

analyze-js-py:
name: Analyze JS/PY
runs-on: 'ubuntu-latest'
timeout-minutes: 360
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ['javascript-typescript', 'python']

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v2

# Build stuff here

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: '/language:${{matrix.language}}'

analyze-cpp:
name: Analyze C/C++
runs-on: 'ubuntu-latest'
needs: [get-targets]
timeout-minutes: 360
permissions:
actions: read
contents: read
security-events: write

env:
language: 'c-cpp'

strategy:
fail-fast: false
matrix:
board: ${{ fromJson(needs.get-targets.outputs.board-array) }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ env.language }}

- uses: ./.github/actions/build-firmware
with:
python-version: ${{ env.PYTHON_VERSION }}
board: ${{ matrix.board }}
skip-checkout: true

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: '/language:${{ env.language }}'
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,32 @@ txPin():number {
return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0;
}

keepaliveEnabled():boolean {
const offset = this.bb!.__offset(this.bb_pos, 6);
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
}

static startRFConfig(builder:flatbuffers.Builder) {
builder.startObject(1);
builder.startObject(2);
}

static addTxPin(builder:flatbuffers.Builder, txPin:number) {
builder.addFieldInt8(0, txPin, 0);
}

static addKeepaliveEnabled(builder:flatbuffers.Builder, keepaliveEnabled:boolean) {
builder.addFieldInt8(1, +keepaliveEnabled, +false);
}

static endRFConfig(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
}

static createRFConfig(builder:flatbuffers.Builder, txPin:number):flatbuffers.Offset {
static createRFConfig(builder:flatbuffers.Builder, txPin:number, keepaliveEnabled:boolean):flatbuffers.Offset {
RFConfig.startRFConfig(builder);
RFConfig.addTxPin(builder, txPin);
RFConfig.addKeepaliveEnabled(builder, keepaliveEnabled);
return RFConfig.endRFConfig(builder);
}
}
3 changes: 3 additions & 0 deletions include/CommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ namespace OpenShock::CommandHandler {
SetRfPinResultCode SetRfTxPin(std::uint8_t txPin);
std::uint8_t GetRfTxPin();

bool SetKeepAliveEnabled(bool enabled);
bool SetKeepAlivePaused(bool paused);

bool HandleCommand(ShockerModelType shockerModel, std::uint16_t shockerId, ShockerCommandType type, std::uint8_t intensity, std::uint16_t durationMs);
} // namespace OpenShock::CommandHandler
1 change: 1 addition & 0 deletions include/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace OpenShock::Config {
bool SetBackendConfig(const BackendConfig& config);

bool SetRFConfigTxPin(std::uint8_t txPin);
bool SetRFConfigKeepAliveEnabled(bool enabled);

std::uint8_t AddWiFiCredentials(const std::string& ssid, const std::uint8_t (&bssid)[6], const std::string& password);
bool TryGetWiFiCredentialsByID(std::uint8_t id, WiFiCredentials& out);
Expand Down
2 changes: 1 addition & 1 deletion include/radio/RFTransmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace OpenShock {

inline bool ok() const { return m_rmtHandle != nullptr && m_queueHandle != nullptr && m_taskHandle != nullptr; }

bool SendCommand(ShockerModelType model, std::uint16_t shockerId, ShockerCommandType type, std::uint8_t intensity, std::uint16_t durationMs);
bool SendCommand(ShockerModelType model, std::uint16_t shockerId, ShockerCommandType type, std::uint8_t intensity, std::uint16_t durationMs, bool overwriteExisting = true);
void ClearPendingCommands();

private:
Expand Down
14 changes: 12 additions & 2 deletions include/serialization/_fbs/ConfigFile_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ struct RFConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return "OpenShock.Serialization.Configuration.RFConfig";
}
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_TX_PIN = 4
VT_TX_PIN = 4,
VT_KEEPALIVE_ENABLED = 6
};
uint8_t tx_pin() const {
return GetField<uint8_t>(VT_TX_PIN, 0);
}
bool keepalive_enabled() const {
return GetField<uint8_t>(VT_KEEPALIVE_ENABLED, 0) != 0;
}
bool Verify(::flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<uint8_t>(verifier, VT_TX_PIN, 1) &&
VerifyField<uint8_t>(verifier, VT_KEEPALIVE_ENABLED, 1) &&
verifier.EndTable();
}
};
Expand All @@ -88,6 +93,9 @@ struct RFConfigBuilder {
void add_tx_pin(uint8_t tx_pin) {
fbb_.AddElement<uint8_t>(RFConfig::VT_TX_PIN, tx_pin, 0);
}
void add_keepalive_enabled(bool keepalive_enabled) {
fbb_.AddElement<uint8_t>(RFConfig::VT_KEEPALIVE_ENABLED, static_cast<uint8_t>(keepalive_enabled), 0);
}
explicit RFConfigBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
Expand All @@ -101,8 +109,10 @@ struct RFConfigBuilder {

inline ::flatbuffers::Offset<RFConfig> CreateRFConfig(
::flatbuffers::FlatBufferBuilder &_fbb,
uint8_t tx_pin = 0) {
uint8_t tx_pin = 0,
bool keepalive_enabled = false) {
RFConfigBuilder builder_(_fbb);
builder_.add_keepalive_enabled(keepalive_enabled);
builder_.add_tx_pin(tx_pin);
return builder_.Finish();
}
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ build_flags =
-DOPENSHOCK_LED_GPIO=35
-DOPENSHOCK_TX_PIN=15
-DOPENSHOCK_ESTOP_PIN=13
-DARDUINO_USB_CDC_ON_BOOT=1

; TODO:
; https://docs.platformio.org/en/latest/boards/espressif32/upesy_wroom.html;upesy-esp32-wroom-devkit
1 change: 1 addition & 0 deletions schemas/ConfigFile.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct BSSID {

table RFConfig {
tx_pin:uint8;
keepalive_enabled:bool;
}

table WiFiCredentials {
Expand Down
Loading

0 comments on commit 38a7aaa

Please sign in to comment.