Skip to content

Commit

Permalink
add some function parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
g3gg0 committed Aug 4, 2023
1 parent d1b2f51 commit 659d555
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion contrib/data/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ <h2>File Viewer</h2>
};
this.handleModeChange = this.handleModeChange.bind(this);
this.hexToStr = this.hexToStr.bind(this);
this.littleEndianToNum = this.littleEndianToNum.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -1223,6 +1224,21 @@ <h2>File Viewer</h2>
return str;
}

littleEndianToNum(hexString) {
let bigEndianHex = "";
for (let i = 0; i < hexString.length; i += 2) {
bigEndianHex = hexString.substring(i, i + 2) + bigEndianHex;
}

let num = parseInt(bigEndianHex, 16);
let maxVal = 2 ** 31;

if (num >= maxVal) {
num = num - 2 * maxVal;
}
return num;
}

initSSE = () => {
const eventSource = new EventSource('/api/sse');

Expand All @@ -1242,9 +1258,11 @@ <h2>File Viewer</h2>
}));
});


eventSource.addEventListener('rtnl-raw-log2', e => {
const data = JSON.parse(e.data);
const functionHandlers = {
/* ESP32 box events */
"15-15452": (payload) => {
if (payload.length === 16) {
const rearrangedPayload = payload.slice(8) + payload.slice(0, 8);
Expand All @@ -1267,8 +1285,31 @@ <h2>File Viewer</h2>
console.log(`Incorrect payload length for '${payload}'. Unable to rearrange.`);
}
},
"12-15427": (payload) => {
if (payload.length === 8) {
const value = this.littleEndianToNum(payload);
this.setState(prevState => ({
messages: [...prevState.messages,
`UpsideState | ${value}`]
}));
} else {
console.log(`Incorrect payload length for '${payload}'. Unable to rearrange.`);
}
},
"12-15426": (payload) => {
if (payload.length === 8) {
const value = this.littleEndianToNum(payload);
this.setState(prevState => ({
messages: [...prevState.messages,
`UprightState | ${value}`]
}));
} else {
console.log(`Incorrect payload length for '${payload}'. Unable to rearrange.`);
}
},
};



console.log("raw", data);
this.setState(prevState => ({
messages: [...prevState.messages,
Expand Down

0 comments on commit 659d555

Please sign in to comment.