From e6279ae486eef2d549a4b5dd15e4e446d2180dc7 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Sat, 19 Jul 2025 15:35:02 +0800 Subject: give up monorepo --- src/messages.ts | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/messages.ts (limited to 'src/messages.ts') diff --git a/src/messages.ts b/src/messages.ts new file mode 100644 index 0000000..66c63d1 --- /dev/null +++ b/src/messages.ts @@ -0,0 +1,67 @@ +import type { EagleControlData, InstantPushData } from './types.js' +import { MessageSource } from './types.js' + +export class CommandMessage { + constructor( + readonly commandId: number, + readonly commandName: string, + readonly data: T, + readonly time: number, + readonly from: number, + ) {} + + payload() { + return { + cmdId: this.commandId, + name: this.commandName, + time: this.time, + from: this.from, + data: this.data, + } + } +} + +const current = () => { + return Math.floor(new Date().getTime() / 1000) +} + +export class InstantPushMessage extends CommandMessage { + static commandId() { + return 40 + } + + /** + * @param frequency - Report frequency in seconds. + * @param duration - Report duration in seconds. + */ + static make(frequency: number, duration: number) { + const data = { + frequencyTime: frequency, + durationTime: duration, + } + return new InstantPushMessage( + this.commandId(), + 'instantPush', + data, + current(), + MessageSource.App_Android, + ) + } +} + +export class EagleControlMesasge extends CommandMessage { + static commandId() { + return 100 + } + + static make(data: EagleControlData) { + const timestamp = Math.floor(new Date().getTime() / 1000) + return new EagleControlMesasge( + this.commandId(), + 'control', + data, + timestamp, + MessageSource.App_Android, + ) + } +} -- cgit v1.2.3