NEC Near Field Communication RF module library for mbed H001-000003-001 (950MHz), H001-000013-001 (920MHz), TY24FM-E2024 (2.4GHz)
Dependents: NECnfc_sample Drone_air Drone_ground
NEC Near Field Communication RF module library
NEC製の近距離無線モジュール用のライブラリです。
Diff: NECnfc.h
- Revision:
- 2:9e108187ccfe
- Parent:
- 0:337524afec9b
- Child:
- 3:71a16ce27889
diff -r 5d157700a95d -r 9e108187ccfe NECnfc.h --- a/NECnfc.h Sun Sep 02 08:06:05 2012 +0000 +++ b/NECnfc.h Thu Aug 27 05:41:24 2015 +0000 @@ -6,71 +6,79 @@ /** @file * @brief NEC Near Field Communication RF module library for mbed - * @note H001-000003-001 (950MHz), TY24FM-E2024 (2.4GHz) + * @note H001-000003-001 (950MHz), TY24FM-E2024 (2.4GHz), H001-000013-001 (920MHz) */ #include "mbed.h" -enum NECTYPE { - NECTYPE_950MHz, - NECTYPE_2400MHz, -}; - -enum NECMSG { - NECMSG_ACK = 0x00, - NECMSG_NOACK = 0x01, - NECMSG_SEARCH = 0x10, - NECMSG_SEND_DAT = 0x11, - NECMSG_RESEND = 0x12, - NECMSG_SEND_NOACK = 0x13, - NECMSG_ENERGY_DETECT = 0x16, - NECMSG_SEND_CMD = 0x17, - NECMSG_WRITE_RFCONF = 0x21, - NECMSG_READ_RSSI = 0x24, - NECMSG_READ_CONFIG = 0x29, - NECMSG_WRITE_CONFIG = 0x2A, - NECMSG_READ_DEFAULT = 0x7D, - NECMSG_WRITE_DEFAULT = 0x7E, - NECMSG_RESET = 0x77, -}; +#define NEC_MAXLENGTH 240 +#define NEC_SYSTEMID 0x0000 +#define NEC_PRODUCTID 0x8341 -enum NECPWR { - NECPWR_LOW = 0x00, - NECPWR_MID = 0x01, - NECPWR_HIGH = 0x02, -}; - -enum NECBAUD { - NECBAUD_9600 = 0x02, - NECBAUD_50k = 0x06, - NECBAUD_100k = 0x07, -}; - -enum NECUART { - UART_4800 = 0x01, - UART_9600 = 0x02, - UART_19200 = 0x04, - UART_38400 = 0x05, - UART_56700 = 0x06, - UART_115200 = 0x08, -}; - -struct ifMessage { - uint16_t start; - uint8_t length; - uint8_t msgid; - uint8_t msgno; - uint32_t dstid; - uint32_t srcid; - uint8_t parameter[242]; -} __attribute__((packed)); - +#define DBG(...) printf("" __VA_ARGS__) +//#define DBG(...) /** * NECnfc class */ class NECnfc { public: + enum NECTYPE { + TYPE_950MHz, + TYPE_2400MHz, + TYPE_920MHz, + }; + + enum NECMSG { + NECMSG_ACK = 0x00, + NECMSG_NOACK = 0x01, + NECMSG_SEARCH = 0x10, + NECMSG_SEND_DAT = 0x11, + NECMSG_RESEND = 0x12, + NECMSG_SEND_NOACK = 0x13, + NECMSG_ENERGY_DETECT = 0x16, + NECMSG_SEND_CMD = 0x17, + NECMSG_WRITE_RFCONF = 0x21, + NECMSG_READ_RSSI = 0x24, + NECMSG_READ_CONFIG = 0x29, + NECMSG_WRITE_CONFIG = 0x2A, + NECMSG_READ_DEFAULT = 0x7D, + NECMSG_WRITE_DEFAULT = 0x7E, + NECMSG_RESET = 0x77, + }; + + enum NECPWR { + PWR_LOW = 0x00, + PWR_MID = 0x01, + PWR_HIGH = 0x02, + PWR_MAX = 0x03, + }; + + enum NECBAUD { + BAUD_9600 = 0x02, + BAUD_50k = 0x06, + BAUD_100k = 0x07, + }; + + enum NECUART { + UART_4800 = 0x01, + UART_9600 = 0x02, + UART_19200 = 0x04, + UART_38400 = 0x05, + UART_56700 = 0x06, + UART_115200 = 0x08, + }; + + struct ifMessage { + uint16_t start; + uint8_t length; + uint8_t msgid; + uint8_t msgno; + uint32_t dstid; + uint32_t srcid; + uint8_t parameter[NEC_MAXLENGTH + 2]; + } __attribute__((packed)); + /** * Default constructor */ @@ -79,11 +87,11 @@ /** * configuration */ - int begin (int ch, NECBAUD baud, NECUART uart = UART_115200, NECPWR power = NECPWR_LOW, NECTYPE type = NECTYPE_950MHz); + int begin (int ch, NECBAUD baud = BAUD_50k, NECUART uart = UART_38400, NECPWR power = PWR_LOW, NECTYPE type = TYPE_920MHz); /** * send */ - int send (int msgid, unsigned long dest, char *param, int len); + int send (NECMSG msgid, unsigned long dest, char *param, int len); /** * read */