-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix issue with FULL_WRITE - Remove `COMMAND_FULL_READ` - Add `formatHexData` utility for hex formatting - Output sent and received data on the devtool console
- Loading branch information
1 parent
5f6865c
commit 82c6fcb
Showing
4 changed files
with
33 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Formats a Uint8Array into a string of hex data, 16 bytes per line. | ||
* | ||
* @param data - The Uint8Array to format. | ||
* @returns A string where each line contains 16 bytes in hexadecimal format. | ||
* @throws Will throw an error if the input is not a Uint8Array. | ||
*/ | ||
export function formatHexData(data: Uint8Array): string { | ||
if (!(data instanceof Uint8Array)) { | ||
throw new Error("Input should be a Uint8Array"); | ||
} | ||
|
||
let result = ''; | ||
for (let i = 0; i < data.length; i += 16) { | ||
let line = ''; | ||
for (let j = 0; j < 16 && i + j < data.length; j++) { | ||
line += data[i + j].toString(16).padStart(2, '0').toUpperCase() + ' '; | ||
} | ||
result += line.trim() + '\n'; | ||
} | ||
return result.trim(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters