Skip to content

Commit

Permalink
Intial fix for issue 69 (#77)
Browse files Browse the repository at this point in the history
* Initial Fix/Workaround of the Simultanuous BLE use
  • Loading branch information
JaapvanEkris authored Feb 7, 2025
1 parent 1bfd518 commit e959971
Show file tree
Hide file tree
Showing 45 changed files with 1,930 additions and 2,163 deletions.
9 changes: 8 additions & 1 deletion app/peripherals/PeripheralManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ export function createPeripheralManager (config) {
setupPeripherals()

async function setupPeripherals () {
await createBlePeripheral(config.bluetoothMode)
await createHrmPeripheral(config.heartRateMode)
if (config.heartRateMode === 'BLE') { await delay(10000) } // WORKAROUND for BLE-Fix. ToDo: remove the need for this delay in the bluetooth startup completely
await createBlePeripheral(config.bluetoothMode)
await createAntPeripheral(config.antPlusMode)
}

Expand Down Expand Up @@ -341,3 +342,9 @@ export function createPeripheralManager (config) {
notifyStatus
})
}

function delay (ms) {
return new Promise(resolve => {
setTimeout(() => resolve(), ms)
})
}
2 changes: 1 addition & 1 deletion app/peripherals/ble/BufferBuilder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
/*
Open Rowing Monitor, https://github.com/laberning/openrowingmonitor
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
A buffer builder that simplifies the creation of payloads for BLE messages
*/
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/BufferBuilder.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
/*
Open Rowing Monitor, https://github.com/laberning/openrowingmonitor
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
*/
import { test } from 'uvu'
import * as assert from 'uvu/assert'
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/CpsPeripheral.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Creates a Bluetooth Low Energy (BLE) Peripheral with all the Services that are required for
a Cycling Power Profile
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'
import CyclingPowerService from './cps/CyclingPowerMeterService.js'
import DeviceInformationService from './common/DeviceInformationService.js'
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/CscPeripheral.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Creates a Bluetooth Low Energy (BLE) Peripheral with all the Services that are required for
a Cycling Speed and Cadence Profile
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'
import DeviceInformationService from './common/DeviceInformationService.js'
import CyclingSpeedCadenceService from './csc/CyclingSpeedCadenceService.js'
Expand Down
7 changes: 5 additions & 2 deletions app/peripherals/ble/FtmsPeripheral.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
The Fitness Machine may instantiate the Device Information Service
(Manufacturer Name String, Model Number String)
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import FitnessMachineService from './ftms/FitnessMachineService.js'
import log from 'loglevel'
import DeviceInformationService from './common/DeviceInformationService.js'
Expand All @@ -34,7 +34,10 @@ export function createFtmsPeripheral (controlCallback, config, simulateIndoorBik
let timer = setTimeout(onBroadcastInterval, broadcastInterval)

bleno.on('stateChange', (state) => {
triggerAdvertising(state)
log.debug(`BLE Peripheral stateChange: ${state}`)
if (state === 'poweredOn') {
triggerAdvertising(state)
}
})

bleno.on('advertisingStart', (error) => {
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/Pm5Peripheral.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
see: https://www.concept2.co.uk/files/pdf/us/monitors/PM5_BluetoothSmartInterfaceDefinition.pdf
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import { pm5Constants } from './pm5/Pm5Constants.js'
import DeviceInformationService from './pm5/DeviceInformationService.js'
import GapService from './pm5/GapService.js'
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/common/DeviceInformationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
todo: Could provide some info on the device here, maybe OS, Node version etc...
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import { PeripheralConstants } from '../../PeripheralConstants.js'
import StaticReadCharacteristic from './StaticReadCharacteristic.js'

Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/common/StaticNotifyCharacteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'

export default class StaticNotifyCharacteristic extends bleno.Characteristic {
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/common/StaticReadCharacteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'

export default class StaticReadCharacteristic extends bleno.Characteristic {
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/cps/CpsControlPointCharacteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
But for our use case proper implementation is not necessary (its mere existence with an empty handler suffice)
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'

export default class CyclingPowerControlPointCharacteristic extends bleno.Characteristic {
constructor (controlPointCallback) {
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/cps/CpsMeasurementCharacteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'
import BufferBuilder from '../BufferBuilder.js'

Expand Down
4 changes: 2 additions & 2 deletions app/peripherals/ble/cps/CyclingPowerMeterService.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
/*
Open Rowing Monitor, https://github.com/laberning/openrowingmonitor
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import BufferBuilder from '../BufferBuilder.js'
import { SensorLocationAsBuffer } from '../common/SensorLocation.js'
import StaticReadCharacteristic from '../common/StaticReadCharacteristic.js'
Expand Down
4 changes: 2 additions & 2 deletions app/peripherals/ble/csc/CscControlPointCharacteristic.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'
/*
Open Rowing Monitor, https://github.com/laberning/openrowingmonitor
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
The connected Central can remotely control some parameters or our rowing monitor via this Control Point
But for our use case proper implementation is not necessary (its mere existence with an empty handler suffice)
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'

export default class CyclingSpeedCadenceControlPointCharacteristic extends bleno.Characteristic {
constructor (controlPointCallback) {
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/csc/CscMeasurementCharacteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'
import BufferBuilder from '../BufferBuilder.js'

Expand Down
4 changes: 2 additions & 2 deletions app/peripherals/ble/csc/CyclingSpeedCadenceService.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
/*
Open Rowing Monitor, https://github.com/laberning/openrowingmonitor
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import BufferBuilder from '../BufferBuilder.js'
import { SensorLocationAsBuffer } from '../common/SensorLocation.js'
import StaticReadCharacteristic from '../common/StaticReadCharacteristic.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Fulgaz: uses setIndoorBikeSimulationParameters
- Zwift: uses startOrResume and setIndoorBikeSimulationParameters
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'
import { ResultOpCode } from '../common/CommonOpCodes.js'

Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/ftms/FitnessMachineService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- Fitness Machine Status Characteristic
- Fitness Machine Control Point Characteristic
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'

import RowerDataCharacteristic from './RowerDataCharacteristic.js'
import IndoorBikeDataCharacteristic from './IndoorBikeDataCharacteristic.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
/*
Open Rowing Monitor, https://github.com/laberning/openrowingmonitor
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
Implements the Status Characteristics, that can be used to notify the central about the current
training machine settings. Currently only used to notify the central about training resets.
Expand All @@ -9,7 +9,7 @@
If the Server supports the Fitness Machine Control Point, the Fitness Machine Status characteristic
shall be exposed by the Server. Otherwise, supporting the Fitness Machine Status characteristic is optional.
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'

// see page 67 https://www.bluetooth.com/specifications/specs/fitness-machine-service-1-0
Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/ftms/IndoorBikeDataCharacteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
The Server should notify this characteristic at a regular interval, typically once per second
while in a connection and the interval is not configurable by the Client
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'
import BufferBuilder from '../BufferBuilder.js'

Expand Down
2 changes: 1 addition & 1 deletion app/peripherals/ble/ftms/RowerDataCharacteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
The Server should notify this characteristic at a regular interval, typically once per second
while in a connection and the interval is not configurable by the Client
*/
import bleno from '@abandonware/bleno'
import bleno from '@stoprocent/bleno'
import log from 'loglevel'
import BufferBuilder from '../BufferBuilder.js'

Expand Down
Loading

0 comments on commit e959971

Please sign in to comment.