#ifndef __M4255_NFC_H__
#define __M4255_NFC_H__
#include "msystem.h"
#include "com_ttySx.h"

#define M4255_RS485ADDR    0x20

#define M4255_CARD_CMD    0x01
#define M4255_READER_GET  0x02
#define M4255_READER_SET  0x03
#define M4255_OTHER_CMD   0x04

#define M4255_CMD_MODE      0x01
#define M4255_AUTO_READ_CARDID  0x02
#define M4255_AUTO_READ_DATABLOCK   0x03
#define M4255_AUTO_READ_CARDID_DATABLOCK    0x04

#define M4255_READ_ONLYONCE     0x00
#define M4255_READ_CONTINUE     0x01

typedef struct M4255
{
    com_ttySx_t tty;

    uint8_t txbuff[32];
    uint16_t txsize;

    uint8_t rxbuff[32];
    uint16_t rxsize;
}M4255_t;


int ccu_NFCReader_Init(M4255_t *dev, const char *devname);

void ccu_NFCReader_Exit(M4255_t *dev);


int ccu_NFC_read_CardID(M4255_t *dev, uint8_t *card_type, uint8_t* card_id);

int ccu_NFC_read_DataBlock(M4255_t *dev, uint8_t useKeyB, uint8_t block_id, uint8_t* buff);

int ccu_NFC_fill_DataBlock(M4255_t *dev, uint8_t useKeyB, uint8_t block_id, uint8_t* data);

int ccu_NFC_fill_PINBlock(M4255_t *dev, uint8_t useKeyB, uint8_t block_id, uint8_t* keyA, uint8_t *keyB);

int ccu_NFCReader_Init_PrepaidIC(M4255_t *dev, uint8_t useKeyB, uint8_t block_id, uint32_t value);

int ccu_NFC_sub_PrepaidIC(M4255_t *dev, uint8_t useKeyB, uint8_t block_id, uint32_t value);

int ccu_NFC_add_PrepaidIC(M4255_t *dev, uint8_t useKeyB, uint8_t block_id, uint32_t value);

int ccu_NFC_read_PrepaidIC(M4255_t *dev, uint8_t useKeyB, uint8_t block_id, uint32_t *value);

int ccu_NFCReader_set_Beep(M4255_t *dev, uint8_t on);

int ccu_NFCReader_force_Beep(M4255_t *dev, uint8_t on);

int ccu_NFCReader_set_WorkMode(M4255_t *dev, uint8_t mode);

int ccu_NFCReader_set_ReadOnce(M4255_t *dev, uint8_t type);

int ccu_NFCReader_wait_CardID(M4255_t *dev, int timeout, char* card_id);

#endif//__M4255_NFC_H__
