Skip to content
Draft
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

### Changed

### Hardware


## [26.1.10]

### Added

### Changed
- Added feed forward, disabled PowerTable for ERG lookup.
- Added tests and removal of duplicates in pt column.
Expand Down
2 changes: 2 additions & 0 deletions CustomCharacteristic.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ From BLE_common.h
|BLE_targetPosition |0x19 |int36|Position (in steps) the motor is maintaining. |
|BLE_externalControl |0x1A |bool |01 disables internal calculation of targetPosition.|
|BLE_syncMode |0x1B |bool |01 stops motor movement for external calibration |
|BLE_UDPLogging |0x2E |bool |Enable/disable UDP log streaming |
|BLE_BLELogging |0x30 |bool/str|Write: enable/disable BLE log streaming. Read: returns last log message|

*syncMode will disable the movement of the stepper motor by forcing stepperPosition = targetPosition prior to the motor control. While this mode is enabled, it allows the client to set parameters like incline and shifterPosition without moving the motor from it's current position. Once the parameters are set, this mode should be turned back off and SS2K will resume normal operation.

Expand Down
2 changes: 1 addition & 1 deletion dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ direct_dependencies:
- espressif/network_provisioning
- idf
- joltwallet/littlefs
manifest_hash: e7ce7a886dfdb3cc5cd59acbdb4ff333c0a91c6e4de55b9fd6323d866c7cc691
manifest_hash: df9baa925ebc2a028ee0e349be53f2169bb7ac38b2cb9c63b3ebf69123c43ef8
target: esp32
version: 2.0.0
1 change: 1 addition & 0 deletions include/BLE_Custom_Characteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const uint8_t BLE_hMax = 0x2B; // Maximum homing value
const uint8_t BLE_homingSensitivity = 0x2C; // Homing sensitivity value
const uint8_t BLE_pTab4Pwr = 0x2D; // Use power values for power table
const uint8_t BLE_UDPLogging = 0x2E; // Enable or disable UDP logging
const uint8_t BLE_BLELogging = 0x30; // Enable or disable BLE logging

class BLE_ss2kCustomCharacteristic {
public:
Expand Down
23 changes: 23 additions & 0 deletions include/BleAppender.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2020 Anthony Doud & Joel Baranick
* All rights reserved
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#pragma once

#include "LogAppender.h"
#include <string>

class BleAppender : public ILogAppender {
public:
void Log(const char *message);
void Initialize();
const char *getLastMessage();

private:
static const size_t MAX_MESSAGE_SIZE = 500; // MTU-safe size
std::string lastMessage;
void trimMessage(const char *message);
};
4 changes: 4 additions & 0 deletions include/SmartSpin_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class RuntimeParameters {
int minResistance = -DEFAULT_RESISTANCE_RANGE;
int maxResistance = DEFAULT_RESISTANCE_RANGE;
bool simTargetWatts = false;
bool bleLogEnabled = false;

public:
Measurement watts;
Expand Down Expand Up @@ -114,6 +115,9 @@ class RuntimeParameters {
void setMaxResistance(int max) { maxResistance = max; }
int getMaxResistance() { return maxResistance; }

void setBleLogEnabled(bool enabled) { bleLogEnabled = enabled; }
bool getBleLogEnabled() { return bleLogEnabled; }

String returnJSON();
};

Expand Down
16 changes: 16 additions & 0 deletions src/BLE_Custom_Characteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ This characteristic allows for reading and writing various user configuration pa
#include <Power_Table.h>
#include <BLE_Custom_Characteristic.h>
#include <Constants.h>
#include "BleAppender.h"

extern BleAppender bleAppender;

void BLE_ss2kCustomCharacteristic::setupService(NimBLEServer *pServer) {
pSmartSpin2kService = spinBLEServer.pServer->createService(SMARTSPIN2K_SERVICE_UUID);
Expand Down Expand Up @@ -828,6 +831,19 @@ void BLE_ss2kCustomCharacteristic::process(std::string rxValue) {
}
break;

case BLE_BLELogging: // 0x30
LOG_BUF_APPEND("<-BLELogging");
if (rxValue[0] == cc_read) {
returnValue[0] = cc_success;
returnString = bleAppender.getLastMessage();
}
if (rxValue[0] == cc_write) {
returnValue[0] = cc_success;
rtConfig->setBleLogEnabled(rxValue[2]);
LOG_BUF_APPEND("(%s)", rtConfig->getBleLogEnabled() ? "true" : "false");
}
break;

default:
LOG_BUF_APPEND("<-Unknown Characteristic");
returnValue[0] = cc_error;
Expand Down
2 changes: 1 addition & 1 deletion src/BLE_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void MyServerCallbacks::onDisconnect(NimBLEServer* pServer) {
}

void MyServerCallbacks::onMTUChange(uint16_t MTU, NimBLEConnInfo& connInfo) {
SS2K_LOG(BLE_SERVER_LOG_TAG, "MTU updated: %u for connection ID: %u", MTU, connInfo.getConnHandle());
//SS2K_LOG(BLE_SERVER_LOG_TAG, "MTU updated: %u for connection ID: %u", MTU, connInfo.getConnHandle());
}

bool MyServerCallbacks::onConnParamsUpdateRequest(uint16_t handle, const ble_gap_upd_params* params) {
Expand Down
48 changes: 48 additions & 0 deletions src/BleAppender.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2020 Anthony Doud & Joel Baranick
* All rights reserved
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#include "BleAppender.h"
#include "Main.h"
#include "BLE_Custom_Characteristic.h"

void BleAppender::Initialize() {}

void BleAppender::Log(const char *message) {
if (!rtConfig->getBleLogEnabled()) {
return;
}

// Cache the message
trimMessage(message);

// Use the existing custom characteristic notification mechanism
BLE_ss2kCustomCharacteristic::notify(BLE_BLELogging);
}

const char *BleAppender::getLastMessage() {
return lastMessage.c_str();
}

void BleAppender::trimMessage(const char *message) {
if (message == nullptr) {
lastMessage = "";
return;
}

// Copy message and remove trailing newlines
std::string msg(message);
while (!msg.empty() && (msg.back() == '\n' || msg.back() == '\r')) {
msg.pop_back();
}

// Trim to MTU-safe size
if (msg.length() > MAX_MESSAGE_SIZE) {
msg = msg.substr(0, MAX_MESSAGE_SIZE);
}

lastMessage = msg;
}
3 changes: 3 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Power_Table.h"
#include "UdpAppender.h"
#include "WebsocketAppender.h"
#include "BleAppender.h"
#include "BLE_Custom_Characteristic.h"
#include "BLE_Definitions.h"
#include <Constants.h>
Expand Down Expand Up @@ -52,6 +53,7 @@ RuntimeParameters* rtConfig = new RuntimeParameters;
///////////// Log Appender /////////////
UdpAppender udpAppender;
WebSocketAppender webSocketAppender;
BleAppender bleAppender;

///////////// BEGIN SETUP /////////////
#ifndef UNIT_TEST
Expand Down Expand Up @@ -141,6 +143,7 @@ extern "C" void app_main() {
// Configure and Initialize Logger
logHandler.addAppender(&webSocketAppender);
logHandler.addAppender(&udpAppender);
logHandler.addAppender(&bleAppender);
logHandler.initialize();
ss2k->startTasks();
httpServer.start();
Expand Down
1 change: 1 addition & 0 deletions src/SmartSpin_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ JsonDocument doc;
doc["maxStep"] = this->maxStep;
doc["minResistance"] = this->minResistance;
doc["maxResistance"] = this->maxResistance;
doc["bleLogEnabled"] = this->bleLogEnabled;

String output;
serializeJson(doc, output);
Expand Down