Skip to content

Commit

Permalink
copy improvements from fork dabe/incyclist-ant-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
Guido Doumen committed Dec 12, 2023
1 parent be357e6 commit 7bd8a63
Show file tree
Hide file tree
Showing 9 changed files with 494 additions and 214 deletions.
3 changes: 3 additions & 0 deletions src/bindings/ant-server-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ export default class AntServerBinding extends AntDevice implements IAntDevice{

if (!this.server)
return;

this.server.removeAllListeners()
this.server.kill()
this.logEvent({message:'stopping ANT+ Server'})
}

Expand Down
37 changes: 36 additions & 1 deletion src/sensors/base-sensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,50 @@ import { ChannelConfiguration, IChannel, ISensor, Profile } from '../types';

const SEND_TIMEOUT = 10000;

export abstract class SensorState {
public constructor(deviceID: number) {
this.DeviceID = deviceID;
}

DeviceID: number;

// Common page - Manufacturer's Identification
ManId?: number = undefined;
SerialNumber?: number = undefined;

// Common page - Product Information
HwVersion?: number = undefined;
SwVersion?: number = undefined;
ModelNum?: number = undefined;

// Common page - Battery status
BatteryLevel?: number = undefined;
BatteryVoltage?: number = undefined;
BatteryStatus?: 'New' | 'Good' | 'Ok' | 'Low' | 'Critical' | 'Invalid' = 'Invalid';

// Debugging
_RawData?: Buffer;
Channel?: number;

// Scanner
Rssi?: number;
Threshold?: number;
}

export default abstract class Sensor implements ISensor {
protected deviceID: number;
protected channel: IChannel;
protected sendTimeout: number;
protected sendTimeout: number;

constructor(deviceID:number=0, channel?:IChannel) {
this.deviceID = Number(deviceID)
this.channel = channel
this.sendTimeout = SEND_TIMEOUT

// Bind 'this' to callbacks, so that it has the proper context
// when called as a callback in the channel
this.onMessage = this.onMessage.bind(this);
this.onEvent = this.onEvent.bind(this);
}

getChannel(): IChannel {
Expand Down
1 change: 1 addition & 0 deletions src/sensors/bicycle-power-sensor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe( 'BicyclePowerSensor',()=> {
sensor.onMessage(data);

expect((sensor as any).states[60916].ManId).toEqual(130);
expect((sensor as any).states[60916].Channel).toEqual(0);
})
})
})
Loading

0 comments on commit 7bd8a63

Please sign in to comment.