upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
sm130.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Based on SM130 library developed by Marc Boon <http://www.marcboon.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <string>
29 #include <mraa/aio.h>
30 #include <mraa/gpio.h>
31 #include <mraa/i2c.h>
32 #include <unistd.h>
33 #include <stdlib.h>
34 
35 #define SIZE_PAYLOAD 18 // maximum payload size of I2C packet
36 #define SIZE_PACKET (SIZE_PAYLOAD + 2) // total I2C packet size, including length uint8_t and checksum
37 
38 #define HIGH 1
39 #define LOW 0
40 
41 namespace upm {
42 
63 class SM130 {
64 
65  uint8_t m_Data[SIZE_PACKET];
66  char m_Version[8];
67  uint8_t m_TagNumber[7];
68  uint8_t m_TagLength;
69  char m_TagString[15];
70  uint8_t m_TagType;
71  char errorCode;
72  uint8_t antennaPower;
73  uint8_t m_LastCMD;
74 
75  public:
76  static const uint8_t MIFARE_ULTRALIGHT = 1;
77  static const uint8_t MIFARE_1K = 2;
78  static const uint8_t MIFARE_4K = 3;
79 
80  static const uint8_t CMD_RESET = 0x80;
81  static const uint8_t CMD_VERSION = 0x81;
82  static const uint8_t CMD_SEEK_TAG = 0x82;
83  static const uint8_t CMD_SELECT_TAG = 0x83;
84  static const uint8_t CMD_AUTHENTICATE = 0x85;
85  static const uint8_t CMD_READ16 = 0x86;
86  static const uint8_t CMD_READ_VALUE = 0x87;
87  static const uint8_t CMD_WRITE16 = 0x89;
88  static const uint8_t CMD_WRITE_VALUE = 0x8a;
89  static const uint8_t CMD_WRITE4 = 0x8b;
90  static const uint8_t CMD_WRITE_KEY = 0x8c;
91  static const uint8_t CMD_INC_VALUE = 0x8d;
92  static const uint8_t CMD_DEC_VALUE = 0x8e;
93  static const uint8_t CMD_ANTENNA_POWER = 0x90;
94  static const uint8_t CMD_READ_PORT = 0x91;
95  static const uint8_t CMD_WRITE_PORT = 0x92;
96  static const uint8_t CMD_HALT_TAG = 0x93;
97  static const uint8_t CMD_SET_BAUD = 0x94;
98  static const uint8_t CMD_SLEEP = 0x96;
99 
106  SM130 (int bus, int devAddr, int rst, int dready);
107 
111  ~SM130 ();
112 
116  const char* getFirmwareVersion ();
117 
126  uint8_t available ();
127 
131  uint8_t getPacketLength () { return this->m_Data[0]; };
132 
136  uint8_t getCommand () { return this->m_Data[1]; };
137 
141  std::string name()
142  {
143  return m_name;
144  }
145  private:
146  std::string m_name;
147  mraa_gpio_context m_resetPinCtx;
148  mraa_gpio_context m_dataReadyPinCtx;
149 
150  int m_i2cAddr;
151  int m_bus;
152  mraa_i2c_context m_i2Ctx;
153 
154  void arrayToHex (char *s, uint8_t array[], uint8_t len);
155  char toHex (uint8_t b);
156 
157  uint16_t i2cRecievePacket (uint32_t len);
158  mraa_result_t i2cTransmitPacket (uint32_t len);
159  mraa_result_t sendCommand (uint8_t cmd);
160 };
161 
162 }
std::string name()
Definition: sm130.h:141
const char * getFirmwareVersion()
Definition: sm130.cxx:96
~SM130()
Definition: sm130.cxx:78
Definition: a110x.h:29
uint8_t available()
Definition: sm130.cxx:109
uint8_t getCommand()
Definition: sm130.h:136
SM130(int bus, int devAddr, int rst, int dready)
Definition: sm130.cxx:42
uint8_t getPacketLength()
Definition: sm130.h:131
C++ API for SM130 RFID reader module.
Definition: sm130.h:63