![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
Dependencies: EthernetNetIf NTPClient_NetServices mbed
MyRFID.cpp@0:d441275f622f, 2010-08-09 (annotated)
- Committer:
- nucho
- Date:
- Mon Aug 09 07:01:43 2010 +0000
- Revision:
- 0:d441275f622f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:d441275f622f | 1 | #include "MyRFID.h" |
nucho | 0:d441275f622f | 2 | #include "mbed.h" |
nucho | 0:d441275f622f | 3 | |
nucho | 0:d441275f622f | 4 | using namespace mbed; |
nucho | 0:d441275f622f | 5 | |
nucho | 0:d441275f622f | 6 | MyRFID::MyRFID(PinName tx, PinName rx) |
nucho | 0:d441275f622f | 7 | : _rfid(tx,rx) {} |
nucho | 0:d441275f622f | 8 | |
nucho | 0:d441275f622f | 9 | |
nucho | 0:d441275f622f | 10 | |
nucho | 0:d441275f622f | 11 | int MyRFID::readable(void) { |
nucho | 0:d441275f622f | 12 | return (_rfid.readable()); |
nucho | 0:d441275f622f | 13 | } |
nucho | 0:d441275f622f | 14 | |
nucho | 0:d441275f622f | 15 | void MyRFID::baud(int baudrate) { |
nucho | 0:d441275f622f | 16 | return (_rfid.baud(baudrate)); |
nucho | 0:d441275f622f | 17 | } |
nucho | 0:d441275f622f | 18 | |
nucho | 0:d441275f622f | 19 | unsigned int MyRFID::read(void) { |
nucho | 0:d441275f622f | 20 | |
nucho | 0:d441275f622f | 21 | unsigned int id=0; |
nucho | 0:d441275f622f | 22 | int len,i; |
nucho | 0:d441275f622f | 23 | |
nucho | 0:d441275f622f | 24 | _rfid.getc();//header |
nucho | 0:d441275f622f | 25 | _rfid.getc();//header |
nucho | 0:d441275f622f | 26 | len = _rfid.getc(); |
nucho | 0:d441275f622f | 27 | |
nucho | 0:d441275f622f | 28 | char data[len]; |
nucho | 0:d441275f622f | 29 | for (i=0;i<len;i++) { |
nucho | 0:d441275f622f | 30 | data[i]=_rfid.getc(); |
nucho | 0:d441275f622f | 31 | } |
nucho | 0:d441275f622f | 32 | if (data[0]==0x50) {//success |
nucho | 0:d441275f622f | 33 | for (i=0;i<4;i++) { |
nucho | 0:d441275f622f | 34 | id |= (data[4-i] << (i * 8)); |
nucho | 0:d441275f622f | 35 | } |
nucho | 0:d441275f622f | 36 | } else {//failre |
nucho | 0:d441275f622f | 37 | } |
nucho | 0:d441275f622f | 38 | |
nucho | 0:d441275f622f | 39 | return id; |
nucho | 0:d441275f622f | 40 | } |