/**
 * radio/nrf.h: interface to radiowaves prototypes
 * 2015 by true
 *
 * ----
 *
 * $Id: nrf.h 505 2021-09-05 19:07:51Z true $
 *
**/

#ifndef __DEVICE_NRF_H
#define __DEVICE_NRF_H


/* libraries */
#include "nrf24l01/true_nRF24L01.h"
#include <xxtea.h>


/* defines */
#define NRF_PAYLOAD_LEN 		8 		// 1 byte command, 1 byte class, 1 byte byte index, 4 bytes data, 1 byte checksum
#define NRF_MYADDR_EEPROM 		(uint32_t)0x080807fc 	// 4 bytes, only using highest byte right now


/* commands (main channel) */
#define NRF_CMD_GETKEY 			0x00 	// TODO: devices query for a key until they get one
#define NRF_CMD_SETKEY 			0x01 	// TODO: sends a key for devices to use
#define NRF_CMD_REQ_SUBADDR 	0x08 	// TODO: asks for subaddress in use
#define NRF_CMD_PAGEDC22 		0x19 	// TODO: pages a dc22-style badge, index is block num, 3 blocks to send, 8 char name, 4 char nonce. index >=0x80 = direct
#define NRF_CMD_PAGEDC23 		0x1a 	// TODO: pages a dc23-style badge, index is block num, 2 blocks to send, 3 char name, 4 char nonce. index >=0x80 = direct
#define NRF_CMD_MUSICNOTES 		0x40 	// TODO: queues and plays the desired music notes. 2 bytes per note, one for note to play (or start play cmd), one for duration of note
#define NRF_CMD_MUSICLIBRARY 	0x42 	// TODO: queues playing a song from the music library. if index = 0xff, badges will repeat with countdown information.
#define NRF_CMD_ANIMATION 		0x8D
#define NRF_CMD_DC22_23GREET 	0x8F
#define NRF_CMD_PING 			0x91 	// TODO: sends ping. dest waits the amount of milliseconds of its ID times two before responding. index is this badge's P1
#define NRF_CMD_PONG 			0x92 	// TODO: reply sent to target in response to ping. sends to P1 as specified in ping.


/* variables */
extern uint8_t nrf_detected;
extern uint8_t nrf_myaddr;

extern uint8_t nrf_tx_buf[NRF_PAYLOAD_LEN];

extern uint8_t nrf_last_ping_id; 	// sender's last byte
extern uint8_t nrf_last_ping_idx; 	// index byte


/* prototypes */
void nrf_init();
uint8_t nrf_checksum(uint8_t *data, uint8_t len, int32_t offset);



#endif /* __DEVICE_NRF_H */
