From 386e8c3ed1b24a7d837c8b86c4a2447f11299209 Mon Sep 17 00:00:00 2001 From: Jack Hadrill Date: Tue, 19 Nov 2024 23:15:50 +0000 Subject: [PATCH] Add get history message --- src/common.ts | 2 +- src/mapping.ts | 11 +++-------- src/messages/history.ts | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 src/messages/history.ts diff --git a/src/common.ts b/src/common.ts index 0ae31ed..db9e257 100644 --- a/src/common.ts +++ b/src/common.ts @@ -8,5 +8,5 @@ export enum MessageTypes { UserDataRequest = 0x0002, UserDataResponse = 0x0003, Keepalive = 0x0005, - Unsubscribe = 0xFFFF + GetHistory = 0xfffe, } diff --git a/src/mapping.ts b/src/mapping.ts index 8f0b4b7..8f44360 100644 --- a/src/mapping.ts +++ b/src/mapping.ts @@ -1,9 +1,4 @@ -import { packSubscribeMessage } from './messages/subscribe' -import { packBasicMessage, unpackBasicMessage } from './messages/basic' -import { packUserDataRequestMessage, unpackUserDataRequestMessage } from './messages/userDataRequest' -import { packUserDataResponseMessage, unpackUserDataResponseMessage } from './messages/userDataResponse' -import { packKeepaliveMessage } from './messages/keepalive' -import { packUnsubscribeMessage } from './messages/unsubscribe' +import { packGetHistoryMessage } from "./messages/history"; export const packers = { 0x0000: packSubscribeMessage, @@ -11,8 +6,8 @@ export const packers = { 0x0002: packUserDataRequestMessage, 0x0003: packUserDataResponseMessage, 0x0005: packKeepaliveMessage, - 0xffff: packUnsubscribeMessage -} + 0xfffe: packGetHistoryMessage, + 0xffff: packUnsubscribeMessage, export const unpackers = { 0x0001: unpackBasicMessage, diff --git a/src/messages/history.ts b/src/messages/history.ts new file mode 100644 index 0000000..30dd6d9 --- /dev/null +++ b/src/messages/history.ts @@ -0,0 +1,16 @@ +import { MessageTypes } from "../common"; +import { numberToUint16BE } from "../utilities/number"; +import { packOutgoingPacket } from "./packet"; + +const MESSAGE_TYPE = numberToUint16BE(MessageTypes.Keepalive); + +/** + * Create an outgoing keepalive (0x0005) packet. + * @returns An outgoing keepalive (0x0005) packet. + */ +export function packGetHistoryMessage(): Uint8Array { + return packOutgoingPacket({ + messageType: MESSAGE_TYPE, + data: new Uint8Array(0), + }); +}