bootloader-frame.js 493 B

12345678910111213141516171819202122
  1. const BOOTLOADER_HEAD = [0x46, 0x54]
  2. function isBootloaderFrame(bytes) {
  3. return Array.isArray(bytes)
  4. && bytes.length >= 2
  5. && bytes[0] === BOOTLOADER_HEAD[0]
  6. && bytes[1] === BOOTLOADER_HEAD[1]
  7. }
  8. function getBootloaderResponseLength(bytes) {
  9. if (!isBootloaderFrame(bytes) || bytes.length < 3) return 0
  10. if (bytes[2] === 0x39) return 15
  11. if (bytes[2] === 0x19) return 9
  12. return 8
  13. }
  14. module.exports = {
  15. BOOTLOADER_HEAD,
  16. getBootloaderResponseLength,
  17. isBootloaderFrame
  18. }