🐸 Sending and receiving a correlated request (WIP)
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
HumanInputData,
|
HumanInputData,
|
||||||
KinematicData,
|
KinematicData,
|
||||||
ModeData,
|
ModeData,
|
||||||
|
PingMsg,
|
||||||
RSSIData,
|
RSSIData,
|
||||||
SonarData,
|
SonarData,
|
||||||
WalkGaitData
|
WalkGaitData
|
||||||
@@ -74,10 +75,14 @@
|
|||||||
socket.on(RSSIData, data => telemetry.setRSSI(data)),
|
socket.on(RSSIData, data => telemetry.setRSSI(data)),
|
||||||
socket.on(ModeData, data => mode.set(data)),
|
socket.on(ModeData, data => mode.set(data)),
|
||||||
socket.on(AnalyticsData, data => {
|
socket.on(AnalyticsData, data => {
|
||||||
|
// console.log(data);
|
||||||
analytics.addData(data)
|
analytics.addData(data)
|
||||||
}),
|
}),
|
||||||
socket.on(AnglesData, data => {
|
socket.on(AnglesData, data => {
|
||||||
servoAngles.set(data)
|
servoAngles.set(data)
|
||||||
|
}),
|
||||||
|
socket.on(PingMsg, data => {
|
||||||
|
console.log("Ping received!")
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { socket } from '$lib/stores'
|
import { socket } from '$lib/stores'
|
||||||
|
|
||||||
//import { IMUReport, IMUType } from '$lib/platform_shared/example';
|
//import { IMUReport, IMUType } from '$lib/platform_shared/example';
|
||||||
import { AnglesData, WebsocketMessage, IMUData } from '$lib/platform_shared/websocket_message'
|
import { AnglesData, WebsocketMessage, IMUData, CorrelationRequest, CorrelationResponse } from '$lib/platform_shared/websocket_message'
|
||||||
|
|
||||||
// const imu_report: IMUReport = {type: IMUType.IMU_ACCEL, xVal: 4}
|
// const imu_report: IMUReport = {type: IMUType.IMU_ACCEL, xVal: 4}
|
||||||
// const writer = IMUReport.encode(imu_report);
|
// const writer = IMUReport.encode(imu_report);
|
||||||
@@ -15,9 +15,10 @@
|
|||||||
|
|
||||||
// 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: 1}, angles: {angles: [2]}}
|
||||||
// const wmd: WebsocketMessage = { imu: {temp: 0, x: 0, y: 0, z: 0} }
|
// const wmd: WebsocketMessage = { imu: {temp: 0, x: 0, y: 0, z: 0} }
|
||||||
const wmd: WebsocketMessage = { rssi: { rssi: 16 } }
|
// const wmd: WebsocketMessage = { rssi: { rssi: 16 } }
|
||||||
// const wmd: WebsocketMessage = { imu: {temp: 1, x: 2, y: 4, z: 5} }
|
// const wmd: WebsocketMessage = { imu: {temp: 1, x: 2, y: 4, z: 5} }
|
||||||
// const wmd: WebsocketMessage = { angles: {angles: [1,2,3,4]} }
|
// const wmd: WebsocketMessage = { angles: {angles: [1,2,3,4]} }
|
||||||
|
const wmd: WebsocketMessage = { pongmsg: {} }
|
||||||
const writer = WebsocketMessage.encode(wmd)
|
const writer = WebsocketMessage.encode(wmd)
|
||||||
const bytes = writer.finish()
|
const bytes = writer.finish()
|
||||||
// Convert bytes to hex
|
// Convert bytes to hex
|
||||||
@@ -44,9 +45,16 @@
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
const handleData = (data: IMUData) => {
|
const handleData = (data: IMUData) => {
|
||||||
console.log(data)
|
// console.log(data)
|
||||||
}
|
}
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
socket.on(CorrelationResponse, (data) => {
|
||||||
|
console.log(data)
|
||||||
|
})
|
||||||
|
socket.onEvent('open', () => {
|
||||||
|
socket.sendEvent(CorrelationRequest, CorrelationRequest.create({correlationId: 69, featuresDataRequest: { sonarTest: true }}))
|
||||||
|
})
|
||||||
|
|
||||||
return socket.on(IMUData, handleData)
|
return socket.on(IMUData, handleData)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -169,6 +169,32 @@ void setupEventSocket() {
|
|||||||
socket.on<socket_message_ServoStateData>([&](const socket_message_ServoStateData &data, int clientId) {
|
socket.on<socket_message_ServoStateData>([&](const socket_message_ServoStateData &data, int clientId) {
|
||||||
data.active ? servoController.activate() : servoController.deactivate();
|
data.active ? servoController.activate() : servoController.deactivate();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on<socket_message_CorrelationRequest>([&](const socket_message_CorrelationRequest &data, int clientId) {
|
||||||
|
printf("Received correlation request: %d\n", data.correlation_id);
|
||||||
|
// Temporarily hardcoded
|
||||||
|
switch (data.which_request) {
|
||||||
|
case socket_message_CorrelationRequest_features_data_request_tag: {
|
||||||
|
socket_message_CorrelationResponse res = socket_message_CorrelationResponse_init_default;
|
||||||
|
res.correlation_id = data.correlation_id;
|
||||||
|
res.stauts_code = 200;
|
||||||
|
res.which_response = socket_message_CorrelationResponse_features_data_response_tag;
|
||||||
|
|
||||||
|
feature_service::features_request(
|
||||||
|
data.request.features_data_request,
|
||||||
|
res.response.features_data_response
|
||||||
|
);
|
||||||
|
|
||||||
|
socket.emit(res, clientId);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
printf("WARNING: no tag found for correlation request: %d", data.which_request);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR SpotControlLoopEntry(void *) {
|
void IRAM_ATTR SpotControlLoopEntry(void *) {
|
||||||
|
|||||||
Reference in New Issue
Block a user