#pragma once

#include <Arduino.h>

enum class LoraFrameDecodeStatus : uint8_t {
  Ok = 0,
  LengthMismatch = 1,
  CrcFail = 2,
  InvalidMsgKind = 3
};

uint16_t lora_crc16_ccitt(const uint8_t *data, size_t len);

bool lora_build_frame(uint8_t msg_kind, uint16_t device_id_short, const uint8_t *payload, size_t payload_len,
                      uint8_t *out_frame, size_t out_cap, size_t &out_len);

LoraFrameDecodeStatus lora_parse_frame(const uint8_t *frame, size_t frame_len, uint8_t max_msg_kind, uint8_t *out_msg_kind,
                                       uint16_t *out_device_id_short, uint8_t *out_payload, size_t payload_cap,
                                       size_t *out_payload_len);
