Minor change to new message formats. LONG WAY TO GO

This commit is contained in:
Niklas Jensen
2025-12-31 00:52:14 +01:00
committed by nikguin04
parent 9cddbf8a9b
commit 73aa38951d
6 changed files with 41 additions and 43 deletions
-18
View File
@@ -1,21 +1,3 @@
export enum MessageTopic {
imu = 'imu',
imuCalibrate = 'imuCalibrate',
mode = 'mode',
input = 'input',
analytics = 'analytics',
position = 'position',
angles = 'angles',
i2cScan = 'i2cScan',
peripheralSettings = 'peripheralSettings',
otastatus = 'otastatus',
gait = 'walk_gait',
servoState = 'servoState',
servoPWM = 'servoPWM',
WiFiSettings = 'WiFiSettings',
sonar = 'sonar',
rssi = 'rssi'
}
export type vector = { x: number; y: number }
+12 -15
View File
@@ -23,8 +23,14 @@
walkGait
} from '$lib/stores'
import { type Analytics, type DownloadOTA } from '$lib/types/models'
import { MessageTopic } from '$lib/types/models'
import { Throttler } from '$lib/utilities'
import {
AnglesData,
GaitData,
InputData,
ModeData,
PositionData
} from '$lib/platform_shared/websocket_message'
interface Props {
children?: import('svelte').Snippet
@@ -41,20 +47,11 @@
addEventListeners()
input.subscribe(data =>
socket.sendEvent(
MessageTopic.input,
throttler.throttle(() => Object.values(data), 40)
)
)
mode.subscribe(data => socket.sendEvent(MessageTopic.mode, data))
walkGait.subscribe(data => socket.sendEvent(MessageTopic.gait, data))
servoAnglesOut.subscribe(data =>
throttler.throttle(() => socket.sendEvent(MessageTopic.angles, data), 100)
)
kinematicData.subscribe(data =>
throttler.throttle(() => socket.sendEvent(MessageTopic.position, data), 100)
)
input.subscribe(data => socket.sendEvent(InputData, InputData.create()))
mode.subscribe(data => socket.sendEvent(ModeData, data))
walkGait.subscribe(data => socket.sendEvent(GaitData, data))
servoAnglesOut.subscribe(data => socket.sendEvent(AnglesData, data))
kinematicData.subscribe(data => socket.sendEvent(PositionData, data))
})
onDestroy(() => {
+5 -4
View File
@@ -2,9 +2,10 @@
import SettingsCard from '$lib/components/SettingsCard.svelte'
import { onMount } from 'svelte'
import { socket } from '$lib/stores'
import { MessageTopic, type I2CDevice } from '$lib/types/models'
import { type I2CDevice } from '$lib/types/models'
import { Connection } from '$lib/components/icons'
import I2CSetting from './i2cSetting.svelte'
import { I2CScanData } from '$lib/platform_shared/websocket_message'
const i2cDevices = [
{ address: 30, part_number: 'HMC5883', name: '3-Axis Digital Compass/Magnetometer IC' },
@@ -25,9 +26,9 @@
let isLoading = $state(false)
onMount(() => {
socket.on(MessageTopic.i2cScan, handleScan)
socket.on(I2CScanData, handleScan)
triggerScan()
return () => socket.off(MessageTopic.i2cScan, handleScan)
return () => socket.off(I2CScanData, handleScan)
})
const handleScan = (data: { addresses: number[] }) => {
@@ -44,7 +45,7 @@
const triggerScan = () => {
isLoading = true
socket.sendEvent(MessageTopic.i2cScan, '')
socket.sendEvent(I2CScanData, '')
}
</script>
@@ -1,6 +1,6 @@
<script lang="ts">
import { ServoPWMData, ServoStateData } from '$lib/platform_shared/websocket_message'
import { socket } from '$lib/stores'
import { MessageTopic } from '$lib/types/models'
import { Throttler } from '$lib/utilities'
let { servoId = $bindable(0), pwm = $bindable(306) } = $props()
@@ -12,16 +12,16 @@
const throttler = new Throttler()
const activateServo = () => {
socket.sendEvent(MessageTopic.servoState, { active: 1 })
socket.sendEvent(ServoStateData, { active: 1 })
}
const deactivateServo = () => {
socket.sendEvent(MessageTopic.servoState, { active: 0 })
socket.sendEvent(ServoStateData, { active: 0 })
}
const updatePWM = () => {
throttler.throttle(() => {
socket.sendEvent(MessageTopic.servoPWM, { servo_id: servoId, pwm })
socket.sendEvent(ServoPWMData, { servo_id: servoId, pwm })
}, 10)
}
+19 -1
View File
@@ -1,6 +1,11 @@
<script lang="ts">
import { onMount } from 'svelte'
import { socket } from '$lib/stores'
//import { IMUReport, IMUType } from '$lib/platform_shared/example';
import { AnglesData, WebsocketMessage } from '$lib/platform_shared/websocket_message'
import { AnglesData, WebsocketMessage, IMUData } from '$lib/platform_shared/websocket_message'
// const imu_report: IMUReport = {type: IMUType.IMU_ACCEL, xVal: 4}
// const writer = IMUReport.encode(imu_report);
@@ -40,8 +45,21 @@
// console.log("True2!")
// }
const handleData = (data: IMUData) => {
console.log(data);
}
onMount(() => {
socket.on(IMUData, handleData)
return () => socket.off(IMUData, handleData)
})
</script>
<h1>Hexadecimal Output</h1>
<p><strong>Hex output:</strong> {hex}</p>
+1 -1
View File
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { WebSocketServer } from 'ws'
import { socket } from '../../src/lib/stores/socket'
import { IMUData, RSSIData, WebsocketMessage, WebsocketMessage } from '../../src/lib/platform_shared/websocket_message'
import { IMUData, RSSIData, WebsocketMessage } from '../../src/lib/platform_shared/websocket_message'
// Helper function to create encoded WebSocket messages
function createEncodedMessage(messageType: 'imu' | 'rssi' | 'mode', data: any): Uint8Array {