🚚 Rename websocket_message to messages
This commit is contained in:
@@ -19,7 +19,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
submodules: "recursive"
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
@@ -34,13 +34,11 @@ jobs:
|
||||
- name: Install PlatformIO Core
|
||||
run: pip install --upgrade platformio
|
||||
|
||||
|
||||
- name: Install Python dependencies for nanopb
|
||||
run: pip install protobuf grpcio-tools
|
||||
|
||||
- name: Build Protocol Buffers (nanopb)
|
||||
run: python ./submodules/nanopb/generator/nanopb_generator.py -I "./platform_shared/" -D esp32/src/platform_shared ./platform_shared/websocket_message.proto ./platform_shared/rest_message.proto
|
||||
|
||||
run: python ./submodules/nanopb/generator/nanopb_generator.py -I "./platform_shared/" -D esp32/src/platform_shared ./platform_shared/message.proto
|
||||
|
||||
- name: Build PlatformIO Project
|
||||
run: pio run
|
||||
|
||||
@@ -6,7 +6,6 @@ on:
|
||||
pull_request:
|
||||
branches: [master, protobuf-playground]
|
||||
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -20,7 +19,7 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
submodules: "recursive"
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v4
|
||||
@@ -31,7 +30,7 @@ jobs:
|
||||
run: pip install protobuf grpcio-tools
|
||||
|
||||
- name: Build Protocol Buffers (nanopb)
|
||||
run: python ./submodules/nanopb/generator/nanopb_generator.py -I "./platform_shared/" -D esp32/src/platform_shared ./platform_shared/websocket_message.proto ./platform_shared/rest_message.proto
|
||||
run: python ./submodules/nanopb/generator/nanopb_generator.py -I "./platform_shared/" -D esp32/src/platform_shared ./platform_shared/message.proto
|
||||
|
||||
- name: Setup Protocol Buffers compiler
|
||||
uses: arduino/setup-protoc@v3
|
||||
|
||||
@@ -17,7 +17,7 @@ const pluginPath =
|
||||
path.join(projectRoot, 'node_modules', '.bin', 'protoc-gen-ts_proto.cmd')
|
||||
: path.join(projectRoot, 'node_modules', '.bin', 'protoc-gen-ts_proto')
|
||||
|
||||
const protoFiles = ['websocket_message.proto', 'rest_message.proto']
|
||||
const protoFiles = ['message.proto']
|
||||
|
||||
const tsProtoOpts = ['useExactTypes=false', 'outputExtensions=true', 'outputSchema=true'].join(',')
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
import { radToDeg } from 'three/src/math/MathUtils.js'
|
||||
import type { URDFRobot } from 'urdf-loader'
|
||||
import { get } from 'svelte/store'
|
||||
import { AnglesData, KinematicData, ModesEnum } from '$lib/platform_shared/websocket_message'
|
||||
import { AnglesData, KinematicData, ModesEnum } from '$lib/platform_shared/message'
|
||||
|
||||
interface Props {
|
||||
defaultColor?: string | null
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { ModeData, ModesEnum } from '$lib/platform_shared/websocket_message'
|
||||
import { ModeData, ModesEnum } from '$lib/platform_shared/message'
|
||||
import { mode } from '$lib/stores'
|
||||
|
||||
const deactivate = async () => {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { get } from 'svelte/store'
|
||||
import type { body_state_t } from './kinematic'
|
||||
import { currentKinematic } from './stores/featureFlags'
|
||||
import { HumanInputData, WalkGaits } from './platform_shared/websocket_message'
|
||||
import { HumanInputData, WalkGaits } from './platform_shared/message'
|
||||
|
||||
export interface gait_state_t {
|
||||
step_height: number
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AnalyticsData } from '$lib/platform_shared/websocket_message'
|
||||
import { AnalyticsData } from '$lib/platform_shared/message'
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
const analytics_data: AnalyticsData[] = []
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { writable } from 'svelte/store'
|
||||
import { IMUData } from '$lib/platform_shared/websocket_message'
|
||||
import { IMUData } from '$lib/platform_shared/message'
|
||||
|
||||
const imu_data: IMUData[] = []
|
||||
const maxIMUData = 100
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ModesEnum,
|
||||
WalkGaitData,
|
||||
WalkGaits
|
||||
} from '$lib/platform_shared/websocket_message'
|
||||
} from '$lib/platform_shared/message'
|
||||
import { persistentStore } from '$lib/utilities/svelte-utilities'
|
||||
import { writable, type Writable } from 'svelte/store'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AnglesData } from '$lib/platform_shared/websocket_message'
|
||||
import { AnglesData } from '$lib/platform_shared/message'
|
||||
import { writable, type Writable } from 'svelte/store'
|
||||
|
||||
export const servoAnglesOut: Writable<AnglesData> = writable(
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { writable } from 'svelte/store'
|
||||
import {
|
||||
WebsocketMessage,
|
||||
Message,
|
||||
CorrelationRequest,
|
||||
CorrelationResponse,
|
||||
protoMetadata as websocket_md,
|
||||
protoMetadata,
|
||||
type MessageFns
|
||||
} from '$lib/platform_shared/websocket_message'
|
||||
import * as WebsocketMessages from '$lib/platform_shared/websocket_message'
|
||||
} from '$lib/platform_shared/message'
|
||||
import * as Messages from '$lib/platform_shared/message'
|
||||
|
||||
export const MESSAGE_TYPE_TO_KEY = new Map<MessageFns<unknown>, string>()
|
||||
export const MESSAGE_TYPE_TO_TAG = new Map<MessageFns<unknown>, number>()
|
||||
@@ -20,14 +20,14 @@ type PendingRequest = {
|
||||
timeoutId: ReturnType<typeof setTimeout>
|
||||
}
|
||||
|
||||
const websocketMessageType = websocket_md.fileDescriptor.messageType?.find(
|
||||
(msg: { name: string }) => msg.name === 'WebsocketMessage'
|
||||
const MessageType = protoMetadata.fileDescriptor.messageType?.find(
|
||||
(msg: { name: string }) => msg.name === 'Message'
|
||||
)
|
||||
|
||||
if (websocketMessageType?.field) {
|
||||
for (const field of websocketMessageType.field) {
|
||||
if (MessageType?.field) {
|
||||
for (const field of MessageType.field) {
|
||||
if (field.typeName) {
|
||||
const messageFns = websocket_md.references[field.typeName]
|
||||
const messageFns = protoMetadata.references[field.typeName]
|
||||
if (messageFns && field.jsonName && field.number) {
|
||||
MESSAGE_TYPE_TO_KEY.set(messageFns, field.jsonName)
|
||||
MESSAGE_TYPE_TO_TAG.set(messageFns, field.number)
|
||||
@@ -38,21 +38,21 @@ if (websocketMessageType?.field) {
|
||||
}
|
||||
}
|
||||
|
||||
function get_name_from_messagetype<T>(event_type: MessageFns<T>): string {
|
||||
function getNameFromMessageType<T>(event_type: MessageFns<T>): string {
|
||||
const event = MESSAGE_TYPE_TO_KEY.get(event_type as MessageFns<unknown>)
|
||||
if (!event) {
|
||||
throw new Error(
|
||||
"Event type not found in 'WebsocketMessage'. The MessageFns you passed doesn't correspond to any WebsocketMessage field."
|
||||
"Event type not found in 'Message'. The MessageFns you passed doesn't correspond to any Message field."
|
||||
)
|
||||
}
|
||||
return event
|
||||
}
|
||||
|
||||
function get_tag_from_messagetype<T>(event_type: MessageFns<T>): number {
|
||||
function getTagFromMessageType<T>(event_type: MessageFns<T>): number {
|
||||
const fieldNumber = MESSAGE_TYPE_TO_TAG.get(event_type as MessageFns<unknown>)
|
||||
if (fieldNumber === undefined) {
|
||||
throw new Error(
|
||||
"Tag not found in 'WebsocketMessage'. The MessageFns you passed doesn't correspond to any WebsocketMessage field."
|
||||
"Tag not found in 'Message'. The MessageFns you passed doesn't correspond to any Message field."
|
||||
)
|
||||
}
|
||||
return fieldNumber
|
||||
@@ -60,10 +60,10 @@ function get_tag_from_messagetype<T>(event_type: MessageFns<T>): number {
|
||||
|
||||
type SocketEvent = 'open' | 'close' | 'error' | 'message' | 'unresponsive'
|
||||
|
||||
type TaggedSocketMessage = { tag: number; msg: WebsocketMessage }
|
||||
type TaggedMessage = { tag: number; msg: Message }
|
||||
|
||||
export const decodeMessage = (data: ArrayBuffer): TaggedSocketMessage => {
|
||||
const decoded = WebsocketMessage.decode(new Uint8Array(data))
|
||||
export const decodeMessage = (data: ArrayBuffer): TaggedMessage => {
|
||||
const decoded = Message.decode(new Uint8Array(data))
|
||||
const values = Object.entries(decoded).filter(([, value]) => value !== undefined)
|
||||
if (values.length != 1) {
|
||||
throw new Error('Message included either 0 or more than 1 data point')
|
||||
@@ -76,8 +76,8 @@ export const decodeMessage = (data: ArrayBuffer): TaggedSocketMessage => {
|
||||
return { tag: tag, msg: decoded }
|
||||
}
|
||||
|
||||
export const encodeMessage = (data: WebsocketMessage): Uint8Array<ArrayBuffer> => {
|
||||
const encoded = WebsocketMessage.encode(data).finish()
|
||||
export const encodeMessage = (data: Message): Uint8Array<ArrayBuffer> => {
|
||||
const encoded = Message.encode(data).finish()
|
||||
return encoded
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ function createWebSocket() {
|
||||
}
|
||||
|
||||
function unsubscribe<MT>(event_type: MessageFns<MT>, listener: (data: MT) => void) {
|
||||
const tag = get_tag_from_messagetype(event_type)
|
||||
const tag = getTagFromMessageType(event_type)
|
||||
const message_listeners_totag = message_listeners.get(tag)
|
||||
if (!message_listeners_totag) return
|
||||
|
||||
@@ -182,43 +182,43 @@ function createWebSocket() {
|
||||
|
||||
function sendEvent<T>(event: MessageFns<T>, data: T) {
|
||||
if (!ws || ws.readyState !== WebSocket.OPEN) return
|
||||
const type = get_name_from_messagetype(event)
|
||||
const wsm = WebsocketMessage.create() as Record<string, unknown>
|
||||
const type = getNameFromMessageType(event)
|
||||
const wsm = Message.create() as Record<string, unknown>
|
||||
wsm[type] = data
|
||||
send(wsm as WebsocketMessage)
|
||||
send(wsm as Message)
|
||||
}
|
||||
|
||||
function unsubscribeToMessageFromServer<T>(event_type: MessageFns<T>) {
|
||||
if (!ws || ws.readyState !== WebSocket.OPEN) return
|
||||
const unsub_msg = WebsocketMessages.UnsubscribeNotification.create({
|
||||
tag: get_tag_from_messagetype(event_type)
|
||||
const unsub_msg = Messages.UnsubscribeNotification.create({
|
||||
tag: getTagFromMessageType(event_type)
|
||||
})
|
||||
send(WebsocketMessage.create({ unsubNotif: unsub_msg }))
|
||||
send(Message.create({ unsubNotif: unsub_msg }))
|
||||
}
|
||||
|
||||
function subscribeToEvent<T>(event_type: MessageFns<T>) {
|
||||
if (!ws || ws.readyState !== WebSocket.OPEN) return
|
||||
const sub_msg = WebsocketMessages.SubscribeNotification.create({
|
||||
tag: get_tag_from_messagetype(event_type)
|
||||
const sub_msg = Messages.SubscribeNotification.create({
|
||||
tag: getTagFromMessageType(event_type)
|
||||
})
|
||||
send(WebsocketMessage.create({ subNotif: sub_msg }))
|
||||
send(Message.create({ subNotif: sub_msg }))
|
||||
}
|
||||
|
||||
function resubscribeAll() {
|
||||
for (const tag of message_listeners.keys()) {
|
||||
const sub_msg = WebsocketMessages.SubscribeNotification.create({ tag })
|
||||
send(WebsocketMessage.create({ subNotif: sub_msg }))
|
||||
const sub_msg = Messages.SubscribeNotification.create({ tag })
|
||||
send(Message.create({ subNotif: sub_msg }))
|
||||
}
|
||||
}
|
||||
|
||||
function send(data: WebsocketMessage) {
|
||||
function send(data: Message) {
|
||||
if (!ws || ws.readyState !== WebSocket.OPEN) return
|
||||
const encoded = encodeMessage(data)
|
||||
ws.send(encoded)
|
||||
}
|
||||
|
||||
function ping() {
|
||||
send(WebsocketMessage.create({ pingmsg: {} }))
|
||||
send(Message.create({ pingmsg: {} }))
|
||||
}
|
||||
|
||||
function sendRequest(
|
||||
@@ -235,7 +235,7 @@ function createWebSocket() {
|
||||
pending_requests.set(correlationId, { resolve, reject, timeoutId })
|
||||
|
||||
const request = CorrelationRequest.create({ correlationId, ...data })
|
||||
send(WebsocketMessage.create({ correlationRequest: request }))
|
||||
send(Message.create({ correlationRequest: request }))
|
||||
}
|
||||
|
||||
function flushQueuedRequests() {
|
||||
@@ -250,7 +250,7 @@ function createWebSocket() {
|
||||
sendEvent,
|
||||
init,
|
||||
on: <MT>(event_type: MessageFns<MT>, listener: (data: MT) => void): (() => void) => {
|
||||
const tag = get_tag_from_messagetype(event_type)
|
||||
const tag = getTagFromMessageType(event_type)
|
||||
|
||||
let message_listeners_totag = message_listeners.get(tag)
|
||||
if (!message_listeners_totag) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DownloadOTAData, RSSIData } from '$lib/platform_shared/websocket_message'
|
||||
import { DownloadOTAData, RSSIData } from '$lib/platform_shared/message'
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
type telemetry_data_type = {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
RSSIData,
|
||||
SonarData,
|
||||
WalkGaitData
|
||||
} from '$lib/platform_shared/websocket_message'
|
||||
} from '$lib/platform_shared/message'
|
||||
import { Throttler } from '$lib/utilities'
|
||||
|
||||
interface Props {
|
||||
@@ -82,7 +82,7 @@
|
||||
servoAngles.set(data)
|
||||
}),
|
||||
socket.on(PingMsg, data => {
|
||||
console.log("Ping received!")
|
||||
console.log('Ping received!')
|
||||
})
|
||||
]
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { onMount } from 'svelte'
|
||||
import { mpu, socket } from '$lib/stores'
|
||||
import { imu } from '$lib/stores/imu'
|
||||
import { IMUData } from '$lib/platform_shared/websocket_message'
|
||||
import { IMUData } from '$lib/platform_shared/message'
|
||||
|
||||
let layout = $derived($views.find(v => v.name === $selectedView)!)
|
||||
|
||||
|
||||
@@ -14,12 +14,7 @@
|
||||
import { VerticalSlider } from '$lib/components/input'
|
||||
import { gamepadAxes, gamepadButtonsEdges, hasGamepad } from '$lib/stores/gamepad'
|
||||
import { notifications } from '$lib/components/toasts/notifications'
|
||||
import {
|
||||
ModeData,
|
||||
ModesEnum,
|
||||
WalkGaitData,
|
||||
WalkGaits
|
||||
} from '$lib/platform_shared/websocket_message'
|
||||
import { ModeData, ModesEnum, WalkGaitData, WalkGaits } from '$lib/platform_shared/message'
|
||||
|
||||
let left: nipplejs.JoystickManager
|
||||
let right: nipplejs.JoystickManager
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { socket } from '$lib/stores'
|
||||
import { Connection } from '$lib/components/icons'
|
||||
import I2CSetting from './i2cSetting.svelte'
|
||||
import type { I2CDevice } from '$lib/platform_shared/websocket_message'
|
||||
import type { I2CDevice } from '$lib/platform_shared/message'
|
||||
|
||||
let active_devices: I2CDevice[] = $state([])
|
||||
let isLoading = $state(false)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import {
|
||||
PeripheralSettingsData,
|
||||
PeripheralSettingsDataRequest
|
||||
} from '$lib/platform_shared/websocket_message'
|
||||
} from '$lib/platform_shared/message'
|
||||
|
||||
let settings: PeripheralSettingsData | null = $state(null)
|
||||
let isEditing = $state(false)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import { useFeatureFlags } from '$lib/stores/featureFlags'
|
||||
import { Rotate3d } from '$lib/components/icons'
|
||||
|
||||
import { type IMUCalibrateData, IMUData } from '$lib/platform_shared/websocket_message'
|
||||
import { type IMUCalibrateData, IMUData } from '$lib/platform_shared/message'
|
||||
|
||||
Chart.register(...registerables)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { ServoPWMData, ServoStateData } from '$lib/platform_shared/websocket_message'
|
||||
import { ServoPWMData, ServoStateData } from '$lib/platform_shared/message'
|
||||
import { socket } from '$lib/stores'
|
||||
import { Throttler } from '$lib/utilities'
|
||||
|
||||
|
||||
@@ -3,7 +3,13 @@
|
||||
import { socket } from '$lib/stores'
|
||||
|
||||
//import { IMUReport, IMUType } from '$lib/platform_shared/example';
|
||||
import { AnglesData, WebsocketMessage, IMUData, CorrelationRequest, CorrelationResponse } from '$lib/platform_shared/websocket_message'
|
||||
import {
|
||||
AnglesData,
|
||||
Message,
|
||||
IMUData,
|
||||
CorrelationRequest,
|
||||
CorrelationResponse
|
||||
} from '$lib/platform_shared/message'
|
||||
|
||||
// const imu_report: IMUReport = {type: IMUType.IMU_ACCEL, xVal: 4}
|
||||
// const writer = IMUReport.encode(imu_report);
|
||||
@@ -13,20 +19,20 @@
|
||||
// .map((b) => b.toString(16).padStart(2, '0'))
|
||||
// .join(' ');
|
||||
|
||||
// const wmd: WebsocketMessage = { imu: {temp: 0, x: 0, y: 0, z: 1}, angles: {angles: [2]}}
|
||||
// const wmd: WebsocketMessage = { imu: {temp: 0, x: 0, y: 0, z: 0} }
|
||||
// const wmd: WebsocketMessage = { rssi: { rssi: 16 } }
|
||||
// const wmd: WebsocketMessage = { imu: {temp: 1, x: 2, y: 4, z: 5} }
|
||||
// const wmd: WebsocketMessage = { angles: {angles: [1,2,3,4]} }
|
||||
const wmd: WebsocketMessage = { pongmsg: {} }
|
||||
const writer = WebsocketMessage.encode(wmd)
|
||||
// const wmd: Message = { imu: {temp: 0, x: 0, y: 0, z: 1}, angles: {angles: [2]}}
|
||||
// const wmd: Message = { imu: {temp: 0, x: 0, y: 0, z: 0} }
|
||||
// const wmd: Message = { rssi: { rssi: 16 } }
|
||||
// const wmd: Message = { imu: {temp: 1, x: 2, y: 4, z: 5} }
|
||||
// const wmd: Message = { angles: {angles: [1,2,3,4]} }
|
||||
const wmd: Message = { pongmsg: {} }
|
||||
const writer = Message.encode(wmd)
|
||||
const bytes = writer.finish()
|
||||
// Convert bytes to hex
|
||||
const hex = Array.from(bytes)
|
||||
.map(b => b.toString(16).padStart(2, '0'))
|
||||
.join(' ')
|
||||
|
||||
// const decodedmsg: WebsocketMessage = WebsocketMessage.decode(bytes);
|
||||
// const decodedmsg: Message = Message.decode(bytes);
|
||||
// const objects = Object.entries(decodedmsg)
|
||||
|
||||
// console.log(Object.keys(AnglesData.create())[0] )
|
||||
@@ -48,11 +54,17 @@
|
||||
// console.log(data)
|
||||
}
|
||||
onMount(() => {
|
||||
socket.on(CorrelationResponse, (data) => {
|
||||
socket.on(CorrelationResponse, data => {
|
||||
console.log(data)
|
||||
})
|
||||
socket.onEvent('open', () => {
|
||||
socket.sendEvent(CorrelationRequest, CorrelationRequest.create({correlationId: 69, featuresDataRequest: { sonarTest: true }}))
|
||||
socket.sendEvent(
|
||||
CorrelationRequest,
|
||||
CorrelationRequest.create({
|
||||
correlationId: 69,
|
||||
featuresDataRequest: { sonarTest: true }
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
return socket.on(IMUData, handleData)
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
} from '$lib/components/icons'
|
||||
import StatusItem from '$lib/components/StatusItem.svelte'
|
||||
import ActionButton from './ActionButton.svelte'
|
||||
import { AnalyticsData, type SystemInformation } from '$lib/platform_shared/websocket_message'
|
||||
import { AnalyticsData, type SystemInformation } from '$lib/platform_shared/message'
|
||||
|
||||
const features = useFeatureFlags()
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
Edit
|
||||
} from '$lib/components/icons'
|
||||
import StatusItem from '$lib/components/StatusItem.svelte'
|
||||
import { KnownNetworkItem } from '$lib/platform_shared/websocket_message'
|
||||
import { KnownNetworkItem } from '$lib/platform_shared/message'
|
||||
import { WifiSettings, type WifiStatus } from '$lib/platform_shared/rest_message'
|
||||
|
||||
let networkEditable: KnownNetworkItem = $state(KnownNetworkItem.create())
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { WebSocketServer } from 'ws'
|
||||
import { decodeMessage, MESSAGE_KEY_TO_TAG, socket } from '../../src/lib/stores/socket'
|
||||
import {
|
||||
IMUData,
|
||||
PingMsg,
|
||||
PongMsg,
|
||||
WebsocketMessage
|
||||
} from '../../src/lib/platform_shared/websocket_message'
|
||||
import { IMUData, PingMsg, PongMsg, Message } from '../../src/lib/platform_shared/message'
|
||||
|
||||
// Helper function to create encoded WebSocket messages
|
||||
function createEncodedMessage(messageType: 'imu' | 'rssi' | 'mode', data: unknown): Uint8Array {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const message: any = {}
|
||||
message[messageType] = data
|
||||
const wsMessage = WebsocketMessage.create(message)
|
||||
return WebsocketMessage.encode(wsMessage).finish()
|
||||
const wsMessage = Message.create(message)
|
||||
return Message.encode(wsMessage).finish()
|
||||
}
|
||||
|
||||
describe.sequential('WebSocket Integration Tests', () => {
|
||||
@@ -130,7 +125,7 @@ describe.sequential('WebSocket Integration Tests', () => {
|
||||
|
||||
try {
|
||||
// Decode the protobuf message
|
||||
const decoded = WebsocketMessage.decode(new Uint8Array(data))
|
||||
const decoded = Message.decode(new Uint8Array(data))
|
||||
// console.log('Server: Decoded message:', JSON.stringify(decoded, null, 2))
|
||||
|
||||
// Only resolve if we got actual IMU data
|
||||
@@ -193,9 +188,9 @@ describe.sequential('WebSocket Integration Tests', () => {
|
||||
setTimeout(() => {
|
||||
console.log('Client: Sending invalid message type...')
|
||||
// Send any invalid message type
|
||||
const wsm = WebsocketMessage.create()
|
||||
const wsm = Message.create()
|
||||
try {
|
||||
socket.sendEvent(WebsocketMessage as any, wsm)
|
||||
socket.sendEvent(Message as any, wsm)
|
||||
clearTimeout(timeout)
|
||||
reject(new Error('Expected sendEvent to throw, but it did not'))
|
||||
} catch (e) {
|
||||
@@ -208,7 +203,7 @@ describe.sequential('WebSocket Integration Tests', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('WebsocketMessage Protobuf Encoding/Decoding', () => {
|
||||
describe('Message Protobuf Encoding/Decoding', () => {
|
||||
it('should encode and decode IMU data correctly', () => {
|
||||
const imuData = IMUData.create({
|
||||
x: 3.25,
|
||||
@@ -233,21 +228,17 @@ describe('WebsocketMessage Protobuf Encoding/Decoding', () => {
|
||||
})
|
||||
|
||||
it('should encode and decode two empty types correctly', () => {
|
||||
const encoded_ping = WebsocketMessage.encode(
|
||||
WebsocketMessage.create({ pingmsg: PingMsg.create() })
|
||||
).finish()
|
||||
const encoded_ping = Message.encode(Message.create({ pingmsg: PingMsg.create() })).finish()
|
||||
const decoded_ping = decodeMessage(encoded_ping.buffer)
|
||||
expect(decoded_ping.tag).toBe(MESSAGE_KEY_TO_TAG.get('pingmsg'))
|
||||
|
||||
const encoded_pong = WebsocketMessage.encode(
|
||||
WebsocketMessage.create({ pongmsg: PongMsg.create() })
|
||||
).finish()
|
||||
const encoded_pong = Message.encode(Message.create({ pongmsg: PongMsg.create() })).finish()
|
||||
const decoded_pong = decodeMessage(encoded_pong.buffer)
|
||||
expect(decoded_pong.tag).toBe(MESSAGE_KEY_TO_TAG.get('pongmsg'))
|
||||
})
|
||||
|
||||
it('should encode and decode complete WebsocketMessage', () => {
|
||||
const original = WebsocketMessage.create({
|
||||
it('should encode and decode complete Message', () => {
|
||||
const original = Message.create({
|
||||
imu: IMUData.create({
|
||||
x: 3.25,
|
||||
y: 2.5,
|
||||
@@ -259,8 +250,8 @@ describe('WebsocketMessage Protobuf Encoding/Decoding', () => {
|
||||
})
|
||||
})
|
||||
|
||||
const encoded = WebsocketMessage.encode(original).finish()
|
||||
const decoded = WebsocketMessage.decode(encoded)
|
||||
const encoded = Message.encode(original).finish()
|
||||
const decoded = Message.decode(encoded)
|
||||
|
||||
expect(decoded.imu).toBeDefined()
|
||||
expect(decoded.imu?.x).toBe(3.25)
|
||||
|
||||
@@ -42,7 +42,7 @@ class CommAdapterBase {
|
||||
MessageTraits<T>::assign(msg_, data);
|
||||
|
||||
pb_ostream_t stream = pb_ostream_from_buffer(buffer_, sizeof(buffer_));
|
||||
if (!pb_encode(&stream, socket_message_WebsocketMessage_fields, &msg_)) {
|
||||
if (!pb_encode(&stream, socket_message_Message_fields, &msg_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,10 +86,10 @@ class CommAdapterBase {
|
||||
|
||||
void sendPong(int cid) {
|
||||
uint8_t pongBuffer[16];
|
||||
msg_.which_message = socket_message_WebsocketMessage_pongmsg_tag;
|
||||
msg_.which_message = socket_message_Message_pongmsg_tag;
|
||||
msg_.message.pongmsg = socket_message_PongMsg_init_zero;
|
||||
pb_ostream_t stream = pb_ostream_from_buffer(pongBuffer, sizeof(pongBuffer));
|
||||
if (pb_encode(&stream, socket_message_WebsocketMessage_fields, &msg_)) {
|
||||
if (pb_encode(&stream, socket_message_Message_fields, &msg_)) {
|
||||
send(pongBuffer, stream.bytes_written, cid);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ class CommAdapterBase {
|
||||
SemaphoreHandle_t mutex_;
|
||||
std::map<int32_t, std::list<int>> client_subscriptions_;
|
||||
ProtoDecoder decoder_;
|
||||
socket_message_WebsocketMessage msg_ = socket_message_WebsocketMessage_init_zero;
|
||||
socket_message_Message msg_ = socket_message_Message_init_zero;
|
||||
uint8_t buffer_[PROTO_BUFFER_SIZE];
|
||||
|
||||
private:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <pb_encode.h>
|
||||
#include <pb_decode.h>
|
||||
#include <platform_shared/websocket_message.pb.h>
|
||||
#include <platform_shared/message.pb.h>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
@@ -14,11 +14,11 @@ struct MessageTraits;
|
||||
#define DEFINE_MESSAGE_TRAITS(DataType, field) \
|
||||
template <> \
|
||||
struct MessageTraits<socket_message_##DataType> { \
|
||||
static constexpr pb_size_t tag = socket_message_WebsocketMessage_##field##_tag; \
|
||||
static void assign(socket_message_WebsocketMessage& msg, const socket_message_##DataType& data) { \
|
||||
static constexpr pb_size_t tag = socket_message_Message_##field##_tag; \
|
||||
static void assign(socket_message_Message& msg, const socket_message_##DataType& data) { \
|
||||
msg.message.field = data; \
|
||||
} \
|
||||
static const socket_message_##DataType& access(const socket_message_WebsocketMessage& msg) { \
|
||||
static const socket_message_##DataType& access(const socket_message_Message& msg) { \
|
||||
return msg.message.field; \
|
||||
} \
|
||||
};
|
||||
@@ -42,7 +42,6 @@ DEFINE_MESSAGE_TRAITS(ServoStateData, servo_state)
|
||||
DEFINE_MESSAGE_TRAITS(CorrelationRequest, correlation_request)
|
||||
DEFINE_MESSAGE_TRAITS(CorrelationResponse, correlation_response)
|
||||
|
||||
|
||||
#undef DEFINE_MESSAGE_TRAITS
|
||||
|
||||
class ProtoDecoder {
|
||||
@@ -65,20 +64,20 @@ class ProtoDecoder {
|
||||
bool decode(const uint8_t* data, size_t len, int clientId) {
|
||||
pb_istream_t stream = pb_istream_from_buffer(data, len);
|
||||
|
||||
if (!pb_decode(&stream, socket_message_WebsocketMessage_fields, &msg_)) {
|
||||
if (!pb_decode(&stream, socket_message_Message_fields, &msg_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (msg_.which_message) {
|
||||
case socket_message_WebsocketMessage_sub_notif_tag:
|
||||
case socket_message_Message_sub_notif_tag:
|
||||
if (subscribeHandler_) subscribeHandler_(msg_.message.sub_notif.tag, clientId);
|
||||
return true;
|
||||
|
||||
case socket_message_WebsocketMessage_unsub_notif_tag:
|
||||
case socket_message_Message_unsub_notif_tag:
|
||||
if (unsubscribeHandler_) unsubscribeHandler_(msg_.message.unsub_notif.tag, clientId);
|
||||
return true;
|
||||
|
||||
case socket_message_WebsocketMessage_pingmsg_tag:
|
||||
case socket_message_Message_pingmsg_tag:
|
||||
if (pingHandler_) pingHandler_(clientId);
|
||||
return true;
|
||||
|
||||
@@ -94,7 +93,7 @@ class ProtoDecoder {
|
||||
}
|
||||
|
||||
private:
|
||||
socket_message_WebsocketMessage msg_ = socket_message_WebsocketMessage_init_zero;
|
||||
socket_message_Message msg_ = socket_message_Message_init_zero;
|
||||
SubscribeHandler subscribeHandler_;
|
||||
UnsubscribeHandler unsubscribeHandler_;
|
||||
PingHandler pingHandler_;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <WiFi.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include "platform_shared/websocket_message.pb.h"
|
||||
#include "platform_shared/message.pb.h"
|
||||
|
||||
#define FT_ENABLED(feature) feature
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <platform_shared/websocket_message.pb.h>
|
||||
#include <platform_shared/message.pb.h>
|
||||
|
||||
struct CommandMsg {
|
||||
float lx, ly, rx, ry, h, s, s1;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <features.h>
|
||||
#include <settings/peripherals_settings.h>
|
||||
#include <template/stateful_endpoint.h>
|
||||
#include <platform_shared/websocket_message.pb.h>
|
||||
#include <platform_shared/message.pb.h>
|
||||
|
||||
#include <list>
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -16,10 +16,7 @@ def compile_nanopb():
|
||||
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
proto_files = [
|
||||
proto_dir / "websocket_message.proto",
|
||||
proto_dir / "rest_message.proto"
|
||||
]
|
||||
proto_files = [proto_dir / "message.proto"]
|
||||
|
||||
print(f"Compiling protobuf files with nanopb...")
|
||||
print(f" Proto dir: {proto_dir}")
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
syntax = "proto3";
|
||||
|
||||
|
||||
package socket_message;
|
||||
|
||||
|
||||
// Partial data types
|
||||
message Vector { float x = 1; float y = 2; }
|
||||
message I2CDevice { int32 address = 1; string part_number = 2; string name = 3; }
|
||||
message PinConfig { int32 pin = 1; string mode = 2; string type = 3; string role = 4; }
|
||||
@@ -39,8 +38,6 @@ message FeaturesDataResponse {
|
||||
|
||||
message FeaturesDataRequest { }
|
||||
|
||||
|
||||
|
||||
message CorrelationRequest {
|
||||
uint32 correlation_id = 1;
|
||||
oneof request {
|
||||
@@ -49,6 +46,7 @@ message CorrelationRequest {
|
||||
IMUCalibrateExecute imu_calibrate_execute = 30;
|
||||
}
|
||||
}
|
||||
|
||||
message CorrelationResponse {
|
||||
uint32 correlation_id = 1;
|
||||
uint32 status_code = 2;
|
||||
@@ -67,6 +65,7 @@ enum ModesEnum {
|
||||
STAND = 4;
|
||||
WALK = 5;
|
||||
}
|
||||
|
||||
message StaticSystemInformation {
|
||||
string esp_platform = 1;
|
||||
string firmware_version = 2;
|
||||
@@ -83,10 +82,12 @@ message StaticSystemInformation {
|
||||
string cpu_reset_reason = 13;
|
||||
}
|
||||
|
||||
|
||||
message IMUCalibrateData { bool success = 1; }
|
||||
|
||||
message IMUCalibrateExecute {}
|
||||
|
||||
message ModeData { ModesEnum mode = 1; }
|
||||
|
||||
message ControllerInputData {
|
||||
Vector left = 1;
|
||||
Vector right = 2;
|
||||
@@ -94,6 +95,7 @@ message ControllerInputData {
|
||||
float speed = 4;
|
||||
float s1 = 5;
|
||||
}
|
||||
|
||||
message AnalyticsData {
|
||||
int32 max_alloc_heap = 1;
|
||||
int32 psram_size = 2;
|
||||
@@ -114,32 +116,46 @@ message ServoPWMData {
|
||||
int32 servo_id = 1;
|
||||
uint32 servo_pwm = 2;
|
||||
}
|
||||
|
||||
message ServoStateData {
|
||||
bool active = 1;
|
||||
}
|
||||
|
||||
message AnglesData { repeated int32 angles = 1; }
|
||||
|
||||
message I2CScanData { repeated I2CDevice devices = 1; }
|
||||
|
||||
message I2CScanDataRequest {}
|
||||
|
||||
message PeripheralSettingsData { int32 sda = 1; int32 scl = 2; int32 frequency = 3; repeated PinConfig pins = 4; }
|
||||
|
||||
message PeripheralSettingsDataRequest {}
|
||||
|
||||
message WifiSettingsData { string hostname = 1; bool priority_rssi = 2; repeated KnownNetworkItem wifi_networks = 3; }
|
||||
|
||||
message RSSIData { int32 rssi = 1; }
|
||||
|
||||
message DownloadOTAData { string status = 1; int32 progress = 2; string error = 3; }
|
||||
|
||||
message SonarData { string dummy_field = 1; }
|
||||
|
||||
message HumanInputData {
|
||||
Vector left = 10; Vector right = 11; float height = 20; float speed = 21; float s1 = 22;
|
||||
}
|
||||
|
||||
message SystemInformation {
|
||||
AnalyticsData analytics_data = 1; StaticSystemInformation static_system_information = 2;
|
||||
}
|
||||
|
||||
enum WalkGaits {
|
||||
TROT = 0;
|
||||
CRAWL = 1;
|
||||
}
|
||||
|
||||
message WalkGaitData {
|
||||
WalkGaits gait = 1;
|
||||
}
|
||||
|
||||
message KinematicData {
|
||||
float omega = 1;
|
||||
float phi = 2;
|
||||
@@ -150,15 +166,15 @@ message KinematicData {
|
||||
}
|
||||
|
||||
message SubscribeNotification { int32 tag = 1; }
|
||||
|
||||
message UnsubscribeNotification {int32 tag = 1; }
|
||||
|
||||
message PingMsg {}
|
||||
|
||||
message PongMsg {}
|
||||
|
||||
|
||||
// WebSocket message wrapper
|
||||
// Only ONE field will be set at a time (oneof ensures this)
|
||||
message WebsocketMessage {
|
||||
message Message {
|
||||
oneof message {
|
||||
CorrelationRequest correlation_request = 10;
|
||||
CorrelationResponse correlation_response = 11;
|
||||
@@ -1,12 +0,0 @@
|
||||
rest_message.WifiStatus.local_ip max_size:16
|
||||
rest_message.WifiStatus.mac_address max_size:18
|
||||
rest_message.WifiStatus.ssid max_size:33
|
||||
rest_message.WifiStatus.bssid max_size:18
|
||||
rest_message.WifiStatus.subnet_mask max_size:16
|
||||
rest_message.WifiStatus.gateway_ip max_size:16
|
||||
rest_message.WifiStatus.dns_ip_1 max_size:16
|
||||
rest_message.WifiStatus.dns_ip_2 max_size:16
|
||||
|
||||
rest_message.WifiSettings.hostname max_size:32
|
||||
rest_message.WifiSettings.wifi_networks max_count:8
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "websocket_message.proto";
|
||||
|
||||
// Note: This is most likely a "temporary" proto that will be redone, as these endpoints are static for the esp32, which means we are forced to use WiFi for communication
|
||||
package rest_message;
|
||||
|
||||
|
||||
message WifiStatus {
|
||||
int32 status = 1;
|
||||
string local_ip = 2;
|
||||
string mac_address = 3;
|
||||
float rssi = 4;
|
||||
string ssid = 5;
|
||||
string bssid = 6;
|
||||
uint32 channel = 7;
|
||||
string subnet_mask = 8;
|
||||
string gateway_ip = 9;
|
||||
string dns_ip_1 = 10;
|
||||
optional string dns_ip_2 = 11;
|
||||
}
|
||||
|
||||
message WifiSettings {
|
||||
string hostname = 1;
|
||||
bool priority_rssi = 2;
|
||||
repeated socket_message.KnownNetworkItem wifi_networks = 3;
|
||||
}
|
||||
Reference in New Issue
Block a user