const BOOTLOADER_HEAD = [0x46, 0x54]

function isBootloaderFrame(bytes) {
  return Array.isArray(bytes)
    && bytes.length >= 2
    && bytes[0] === BOOTLOADER_HEAD[0]
    && bytes[1] === BOOTLOADER_HEAD[1]
}

function getBootloaderResponseLength(bytes) {
  if (!isBootloaderFrame(bytes) || bytes.length < 3) return 0
  if (bytes[2] === 0x39) return 15
  if (bytes[2] === 0x19) return 9

  return 8
}

module.exports = {
  BOOTLOADER_HEAD,
  getBootloaderResponseLength,
  isBootloaderFrame
}
