send P2PAlive immediately after P2pRdy

This commit is contained in:
David Ventura
2024-04-30 23:16:24 +02:00
parent b653368d89
commit 5bb0038d9b
2 changed files with 8 additions and 4 deletions
+3 -2
View File
@@ -27,11 +27,12 @@ export const handle_P2PAlive = (session: Session, _: DataView) => {
}; };
export const handle_P2PRdy = (session: Session, _: DataView) => { export const handle_P2PRdy = (session: Session, _: DataView) => {
// TODO - config
const b = SendUsrChk(session, "admin", "admin"); const b = SendUsrChk(session, "admin", "admin");
session.send(b); session.send(b);
}; };
export const makePunchPkt = (dev: DevSerial): DataView => { export const makeP2pRdy = (dev: DevSerial): DataView => {
const len = dev.prefix.length + dev.suffix.length + 8; const len = dev.prefix.length + dev.suffix.length + 8;
const outbuf = new DataView(new Uint8Array(0x14).buffer); // 8 = serial u64 const outbuf = new DataView(new Uint8Array(0x14).buffer); // 8 = serial u64
outbuf.add(0).writeString(dev.prefix); outbuf.add(0).writeString(dev.prefix);
@@ -73,7 +74,7 @@ export const createResponseForControlCommand = (session: Session, dv: DataView):
let dbm = dv.add(0x24).readU8() - 0x100; // 0xbf - 0x100 = -65dbm .. constant?? let dbm = dv.add(0x24).readU8() - 0x100; // 0xbf - 0x100 = -65dbm .. constant??
// > -50 = excellent, -50 to -60 good, -60 to -70 fair, <-70 weak // > -50 = excellent, -50 to -60 good, -60 to -70 fair, <-70 weak
console.log(`Camera ${session.devName}: ${charging}charging, battery at ${power/1000}V, Wifi ${dbm} dBm`); console.log(`Camera ${session.devName}: ${charging}charging, battery at ${power / 1000}V, Wifi ${dbm} dBm`);
} }
if (cmd_id == ControlCommands.WifiSettingsAck) { if (cmd_id == ControlCommands.WifiSettingsAck) {
+5 -2
View File
@@ -2,7 +2,7 @@ import { createSocket, RemoteInfo } from "node:dgram";
import EventEmitter from "node:events"; import EventEmitter from "node:events";
import { Commands, CommandsByValue } from "./datatypes.js"; import { Commands, CommandsByValue } from "./datatypes.js";
import { handle_Drw, handle_P2PAlive, handle_P2PRdy, makePunchPkt, noop, notImpl } from "./handlers.js"; import { handle_Drw, handle_P2PAlive, handle_P2PRdy, makeP2pRdy, noop, notImpl } from "./handlers.js";
import { hexdump } from "./hexdump.js"; import { hexdump } from "./hexdump.js";
import { create_P2pAlive, DevSerial, SendStartVideo, SendVideoResolution, SendWifiDetails } from "./impl.js"; import { create_P2pAlive, DevSerial, SendStartVideo, SendVideoResolution, SendWifiDetails } from "./impl.js";
import { opt } from "./options.js"; import { opt } from "./options.js";
@@ -62,8 +62,11 @@ export const makeSession = (
sock.on("message", (msg, rinfo) => handleIncoming(session, handlers, msg, rinfo)); sock.on("message", (msg, rinfo) => handleIncoming(session, handlers, msg, rinfo));
sock.on("listening", () => { sock.on("listening", () => {
const buf = makePunchPkt(dev); const buf = makeP2pRdy(dev);
session.send(buf); session.send(buf);
// The YsxLite sends a P2PAlive message immediately after P2PRdy
const alive_buf = create_P2pAlive();
session.send(alive_buf);
}); });
const SEND_PORT = 32108; const SEND_PORT = 32108;