rfi341_protocol.h
00001 /* 00002 * Player - One Hell of a Robot Server 00003 * Copyright (C) 2007 00004 * Nico Blodow and Radu Bogdan Rusu 00005 * 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 /* 00023 Desc: Driver for the SICK RFI341 unit 00024 Author: Nico Blodow and Radu Bogdan Rusu 00025 Date: 9 Mar 2007 00026 CVS: $Id: rfi341_protocol.h 8129 2009-07-24 18:39:50Z thjc $ 00027 */ 00028 #include <termios.h> 00029 #include <sys/types.h> 00030 #include <libplayercore/playercore.h> 00031 00032 #define BUF_SIZE 1024 00033 00034 #define STX 0x02 00035 #define ETX 0x03 00036 #define ACK 0x06 00037 #define NAK 0x15 00038 #define SYN 0x16 00039 #define ESC 0x18 00040 00042 class rfi341_protocol 00043 { 00044 public: 00045 rfi341_protocol (const char* port_name, int debug_mode); 00046 00047 // Creates socket, connects 00048 // Connects first at 'connect_speed' 00049 int Connect (int connect_speed); 00050 00051 // but for transfer, we might want to use a different 'transfer_speed' 00052 int SetupSensor (int transfer_speed); 00053 00054 int Disconnect (); 00055 00056 // assembles a command and sends it on the wire 00057 int SendCommand (const char* cmd); 00058 // reads the result of a query from the device 00059 int ReadResult (); 00060 player_rfid_data_t ReadTags (); 00061 00062 private: 00063 // assembles STX's, message, checksum ready to be sent. Cool. 00064 int assemblecommand (unsigned char* command, int len); 00065 00066 int number_of_tags; 00067 char **tags; 00068 00069 // Initial serial port attributes 00070 struct termios initial_options; 00071 00072 // Internal Parameters: 00073 int verbose; 00074 int fd; 00075 const char* port; 00076 int portspeed; 00077 00078 // for reading: 00079 unsigned char buffer[4096]; 00080 unsigned int bufferlength; 00081 int checksum; 00082 00083 // for sending: 00084 unsigned char command[BUF_SIZE]; 00085 int commandlength; 00086 };