-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: fixes #146 ANT-Device not launching
- Loading branch information
Guido Doumen
committed
Nov 19, 2024
1 parent
2e0bd93
commit 9868a9c
Showing
5 changed files
with
129 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { EventLogger,ConsoleAdapter } from "gd-eventlog" | ||
import { AdapterFactory, InterfaceFactory, SerialScannerProps } from "../index" | ||
import { sleep } from "../utils/utils"; | ||
import AntAdapter from "./base/adapter"; | ||
import { AntInterface } from "incyclist-devices"; | ||
|
||
const {AntDevice} = require('incyclist-ant-plus/lib/bindings'); | ||
|
||
EventLogger.registerAdapter(new ConsoleAdapter()) | ||
|
||
describe('Ant+ Scan', () => { | ||
|
||
|
||
|
||
test('Simulate scan and pair', async () => { | ||
const logger = new EventLogger('AntSample') | ||
|
||
const ant = InterfaceFactory.create('ant',{logger, log:true, binding:AntDevice}) as unknown as AntInterface | ||
|
||
|
||
const scan = ():Promise<AntAdapter<any>|null> =>{ | ||
logger.logEvent({message:'scanning ....'}) | ||
|
||
let found = false | ||
|
||
return new Promise(async (resolve,reject)=>{ | ||
const onData = (...args) =>{ | ||
console.log(...args) | ||
} | ||
const onDevice = async (settings)=> { | ||
console.log(settings) | ||
found = true | ||
const adapter = AdapterFactory.create(settings) | ||
|
||
await sleep(4000) | ||
|
||
ant.off('device',onDevice) | ||
ant.off('data',onData) | ||
adapter.pause() | ||
const stopped = await ant.stopScan() | ||
console.log(stopped) | ||
adapter.removeAllListeners('data') | ||
resolve(adapter) | ||
} | ||
|
||
ant.on('device',onDevice) | ||
ant.on('data',onData) | ||
|
||
const devices = await ant.scan( { timeout: 10000} ) | ||
logger.logEvent({message:'devices found', devices}) | ||
if (!found) | ||
resolve(null) | ||
|
||
}) | ||
} | ||
|
||
|
||
|
||
const connected = await ant.connect() | ||
if (connected) { | ||
const device = await scan() | ||
if (device) { | ||
//found.start() | ||
await device.stop() | ||
|
||
device.on('data',console.log) | ||
await device.start() | ||
|
||
await sleep(4000) | ||
await device.stop() | ||
|
||
} | ||
|
||
await ant.disconnect() | ||
} | ||
else ( | ||
console.log('~~~ no ANT+ stick connected') | ||
) | ||
|
||
},40000) | ||
}) |