summaryrefslogtreecommitdiff
path: root/src/messages.ts
diff options
context:
space:
mode:
authorLi Zhineng <[email protected]>2025-07-19 15:35:02 +0800
committerLi Zhineng <[email protected]>2025-07-19 15:35:02 +0800
commite6279ae486eef2d549a4b5dd15e4e446d2180dc7 (patch)
treeb25897278de3685d79df0a0381ceba9ca23d1ef9 /src/messages.ts
parent3cbee218d16e2c7c86d3c1433fde100246da0332 (diff)
downloadairmx-e6279ae486eef2d549a4b5dd15e4e446d2180dc7.tar.gz
airmx-e6279ae486eef2d549a4b5dd15e4e446d2180dc7.zip
give up monorepo
Diffstat (limited to 'src/messages.ts')
-rw-r--r--src/messages.ts67
1 files changed, 67 insertions, 0 deletions
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<T> {
+ 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<InstantPushData> {
+ 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<EagleControlData> {
+ 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,
+ )
+ }
+}