rfi341_protocol.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2007
4  * Nico Blodow and Radu Bogdan Rusu
5  *
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /*
23  Desc: Driver for the SICK RFI341 unit
24  Author: Nico Blodow and Radu Bogdan Rusu
25  Date: 9 Mar 2007
26  CVS: $Id$
27 */
28 #include <termios.h>
29 #include <sys/types.h>
30 #include <libplayercore/playercore.h>
31 
32 #define BUF_SIZE 1024
33 
34 #define STX 0x02
35 #define ETX 0x03
36 #define ACK 0x06
37 #define NAK 0x15
38 #define SYN 0x16
39 #define ESC 0x18
40 
43 {
44  public:
45  rfi341_protocol (const char* port_name, int debug_mode);
46 
47  // Creates socket, connects
48  // Connects first at 'connect_speed'
49  int Connect (int connect_speed);
50 
51  // but for transfer, we might want to use a different 'transfer_speed'
52  int SetupSensor (int transfer_speed);
53 
54  int Disconnect ();
55 
56  // assembles a command and sends it on the wire
57  int SendCommand (const char* cmd);
58  // reads the result of a query from the device
59  int ReadResult ();
60  player_rfid_data_t ReadTags ();
61 
62  private:
63  // assembles STX's, message, checksum ready to be sent. Cool.
64  int assemblecommand (unsigned char* command, int len);
65 
66  int number_of_tags;
67  char **tags;
68 
69  // Initial serial port attributes
70  struct termios initial_options;
71 
72  // Internal Parameters:
73  int verbose;
74  int fd;
75  const char* port;
76  int portspeed;
77 
78  // for reading:
79  unsigned char buffer[4096];
80  unsigned int bufferlength;
81  int checksum;
82 
83  // for sending:
84  unsigned char command[BUF_SIZE];
85  int commandlength;
86 };
#define PLAYER_WARN1(msg, a)
Error message macros.
Definition: error.h:89
char * guid
The Globally Unique IDentifier (GUID) of the tag.
Definition: player_interfaces.h:4323
player_rfid_tag_t * tags
The list of RFID tags.
Definition: player_interfaces.h:4334
#define PLAYER_MSG1(level, msg, a)
Error message macros.
Definition: error.h:105
Generic message header.
Definition: player.h:160
uint8_t subtype
Message subtype; interface specific.
Definition: player.h:167
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:94
#define PLAYER_ERROR2(msg, a, b)
Error message macros.
Definition: error.h:82
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
Class for loading configuration file information.
Definition: configfile.h:195
virtual int Setup()
Initialize the driver.
Definition: driver.h:385
An autopointer for the message queue.
Definition: message.h:72
uint32_t tags_count
The number of RFID tags found.
Definition: player_interfaces.h:4332
#define PLAYER_ERROR1(msg, a)
Error message macros.
Definition: error.h:81
uint32_t type
Tag type.
Definition: player_interfaces.h:4319
Definition: rfi341_protocol.h:42
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:80
uint32_t size
Size in bytes of the payload to follow.
Definition: player.h:173
Structure describing a single RFID tag.
Definition: player_interfaces.h:4316
virtual int Shutdown()
Finalize the driver.
Definition: driver.h:392
Base class for all drivers.
Definition: driver.h:107
uint32_t guid_count
GUID count.
Definition: player_interfaces.h:4321
Data.
Definition: player_interfaces.h:4329
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:75