Generic driver for the RWD RFID Modules from IB Technology.

Dependents:   RSEDP_DPDemo

Revision:
2:37fafd1e1a20
Parent:
1:e96aaf4d5c55
Child:
4:0c21bc193afa
--- a/RWDModule.h	Tue Jul 13 10:37:26 2010 +0000
+++ b/RWDModule.h	Tue Jul 13 16:11:29 2010 +0000
@@ -1,22 +1,64 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
 
 #ifndef RWD_MODULE_H
 #define RWD_MODULE_H
 
 #include "mbed.h"
 
-typedef unsigned char byte;
-
+/*
+The RWD modules from IB Technology are RFID readers working with different frequencies and protocols but with a common instructions set and pinout.
+*/
 class RWDModule
 {
 public:
+  /*
+  Connect module using serial port pins tx, rx and DigitalIn pin cts (clear-to-send).
+  */
   RWDModule(PinName tx, PinName rx, PinName cts);
+  
+  /*
+  Destroys instance.
+  */
   virtual ~RWDModule();
   
-  void command(byte cmd, const byte* params, int paramsLen, byte* resp, int respLen, byte ackOk, byte ackOkMask); //Ack Byte is not included in the resp buf
+
+  /*
+  Executes the command cmd on the reader, with parameters set in params buffer of paramsLen length. The acknowledge byte sent back by the reader masked with ackOkMask  must be equal to ackOk for the command to be considered a success. If so, the result is stored in buffer resp of length respLen.
+  This is a non-blocking function, and ready() should be called to check completion.
+  Please note that the buffers references must remain valid until the command has been executed.
+  */
+  void command(uint8_t cmd, const uint8_t* params, int paramsLen, uint8_t* resp, size_t respLen, uint8_t ackOk, size_t ackOkMask); //Ack Byte is not included in the resp buf
   
+  /*
+  Returns true if the previous command has been executed and an other command is ready to be sent.
+  */
   bool ready(); //Ready for a command / response is available
   
-  bool result(byte* pAck = NULL); //Get wether last command was succesful, and complete ack byte if a ptr is provided
+  /*
+  Returns true if the previous command was successful. If pAck is provided, the actual acknowledge byte returned by the reader is stored in that variable.
+  */
+  bool result(uint8_t* pAck = NULL); //Get wether last command was succesful, and complete ack byte if a ptr is provided
 
 private:
   void intClearToSend(); //Called on interrupt when CTS line falls
@@ -26,17 +68,17 @@
   Serial m_serial;
   InterruptIn m_cts;  
   
-  byte m_cmd;
-  byte* m_paramsBuf;
-  byte* m_respBuf;
-  int m_pos;
-  int m_paramsLen;
-  int m_respLen;
+  uint8_t m_cmd;
+  uint8_t* m_paramsBuf;
+  uint8_t* m_respBuf;
+  size_t m_pos;
+  size_t m_paramsLen;
+  size_t m_respLen;
     
-  byte m_ackOk;
-  byte m_ackOkMask;
+  uint8_t m_ackOk;
+  uint8_t m_ackOkMask;
   
-  byte m_ack;
+  uint8_t m_ack;
   
   enum
   {