⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skyetekm1.cc

📁 机器人仿真软件
💻 CC
📖 第 1 页 / 共 2 页
字号:
/* *  Player - One Hell of a Robot Server *  Copyright (C) 2006 Radu Bogdan Rusu (rusu@cs.tum.edu) * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * *//* Desc: Driver for the SkyeTek M1/M1-mini RFID readers Author: Radu Bogdan Rusu Date: 27 Jan 2006 CVS: $Id: skyetekM1.cc,v 1.3 2006/04/06 16:14:26 veedee Exp $*//** @ingroup drivers *//** @{ *//** @defgroup driver_skyetekM1 skyetekM1 * @brief Skyetek M1 RFID readerThe skyetekM1 driver controls the SkyeTek M1/M1-mini RFID readers (13.56Mhz). Currently, only ISO 15693 tags are supported.@par Compile-time dependencies- none@par Provides- @ref interface_rfid@par Requires- none@par Configuration requests- PLAYER_RFID_REQ_POWER- PLAYER_RFID_REQ_READTAG- PLAYER_RFID_REQ_WRITETAG- PLAYER_RFID_REQ_LOCKTAG@par Configuration file options- port (string)  - Default: "/dev/ttyS0"  - Serial port to which the SkyeTek M1/M1-mini reader is attached.  If you are     using a USB/232 or USB/422 converter, this will be "/dev/ttyUSBx".- rate (integer)  - Default: 9600  - Baud rate. Valid values are 9600, 19200, 38400 and 57600.@par Example @verbatimdriver(  name "skyetekM1"  provides ["rfid:0"]  port "/dev/ttyS0"  rate "9600")@endverbatim@author Radu Bogdan Rusu*//** @} */#include <fcntl.h>#include <string.h>#include <termios.h>#include <unistd.h>// Includes needed for player#include <libplayercore/playercore.h>#define DEFAULT_RFID_PORT "/dev/ttyS0"#define DEFAULT_RFID_RATE B9600// The SkyetekM1 device class.class SkyetekM1 : public Driver{	public:		// Constructor		SkyetekM1 (ConfigFile* cf, int section);		// Destructor		~SkyetekM1 ();		// Implementations of virtual functions		int Setup ();		int Shutdown ();		// This method will be invoked on each incoming message		virtual int ProcessMessage (MessageQueue* resp_queue, 					    player_msghdr * hdr,					    void * data);	private:		// Main function for device thread.		virtual void Main  ();		void RefreshData ();						// Port file descriptor		int                fd;		// Initial serial port attributes		struct termios     initial_options;		// RFID interface		player_rfid_data_t Data;		player_rfid_cmd_t  Cmd;				const char*        portName;		int                portSpeed;				// 0=select just a single tag (no anticollision)		// 1=select all tags in the RFID field (anticollision)		int                selectTagMultiple;		// Inside functions		unsigned int  CRC16       (unsigned char *dataP, unsigned char n);		unsigned char VerifyCRC   (unsigned char *resp);		void WriteSerial (unsigned char *mdmData, unsigned char commandLen);		int  ReadSerial  (unsigned char *mdmData, unsigned char commandLen);		int  S_ReadWrite (unsigned char *mdmData, unsigned char length, 						  unsigned char *response);		void SelectTags  ();		unsigned char Wake  ();		unsigned char Sleep ();};//////////////////////////////////////////////////////////////////////////////////Factory creation function. This functions is given as an argument when// the driver is added to the driver tableDriver* SkyetekM1_Init (ConfigFile* cf, int section){	// Create and return a new instance of this driver	return ((Driver*)(new SkyetekM1 (cf, section)));}//////////////////////////////////////////////////////////////////////////////////Registers the driver in the driver table. Called from the // player_driver_init function that the loader looks forvoid SkyetekM1_Register (DriverTable* table){	table->AddDriver ("skyetekM1", SkyetekM1_Init);}////////////////////////////////////////////////////////////////////////////////// Constructor.  Retrieve options from the configuration file and do any// pre-Setup() setup.SkyetekM1::SkyetekM1 (ConfigFile* cf, int section)	: Driver (cf, section, false, PLAYER_MSGQUEUE_DEFAULT_MAXLEN, 			  PLAYER_RFID_CODE){	this->portName  = cf->ReadString (section, "port", DEFAULT_RFID_PORT);	this->portSpeed = cf->ReadInt (section, "speed", DEFAULT_RFID_RATE);		// Enable the anticollision mode	this->selectTagMultiple = 1;		return;}SkyetekM1::~SkyetekM1(){}////////////////////////////////////////////////////////////////////////////////// Set up the device.  Return 0 if things go well, and -1 otherwise.int SkyetekM1::Setup (){		// Open serial port	this->fd = open (this->portName, O_RDWR);	if (this->fd < 0)	{		PLAYER_ERROR2 ("> Connecting to Skyetek M1 on [%s]; [%s]...[failed!]",				   (char*) this->portName, strerror (errno));		return (-1);	}	PLAYER_MSG0 (1, "> Connecting to Skyetek M1...[done]");	// Change port settings	struct termios options;	memset (&options, 0, sizeof (options));// clear the struct for new port settings		// Get the current port settings	if (tcgetattr (this->fd, &options) != 0) {		PLAYER_ERROR (">> Unable to get serial port attributes !");		return (-1);	}	tcgetattr (this->fd, &this->initial_options);		// turn off break sig, cr->nl, parity off, 8 bit strip, flow control	options.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);	// turn off echo, canonical mode, extended processing, signals	options.c_lflag &= ~(ECHO | ECHOE | ICANON | IEXTEN | ISIG);	options.c_cflag &= ~(CSTOPB);   // use one stop bit	options.c_cflag &= ~(PARENB);   // no parity	options.c_cflag &= ~(CSIZE );   // clear size	options.c_cflag |= (CS8);       // set bit size (default is 8)	options.c_oflag &= ~(OPOST);    // turn output processing off	// read satisfied if TIME is exceeded (t = TIME *0.1 s)	options.c_cc[VTIME] = 10;	options.c_cc[VMIN] = 0;	switch (this->portSpeed) {	    case 9600:{		this->portSpeed = B9600;		break;	    }	    case 19200:{		this->portSpeed = B19200;		break;	    }	    case 38400:{		this->portSpeed = B38400;		break;	    }	    case 57600:{		this->portSpeed = B57600;		break;	    }	    default:{		this->portSpeed = B9600;		break;	    }	}	// Set the baudrate to the given portSpeed	cfsetispeed (&options, this->portSpeed);	cfsetospeed (&options, this->portSpeed);		// Activate the settings for the port	if (tcsetattr (this->fd, TCSAFLUSH, &options) < 0)	{		PLAYER_ERROR (">> Unable to set serial port attributes !");		return (-1);	}	// Make sure queues are empty before we begin	tcflush (this->fd, TCIOFLUSH);			// Start the device thread	StartThread ();	return (0);}////////////////////////////////////////////////////////////////////////////////// Shutdown the deviceint SkyetekM1::Shutdown (){	// Stop the driver thread	StopThread ();	// Close the serial port	tcsetattr (this->fd, TCSANOW, &this->initial_options);	close (this->fd);		PLAYER_MSG0 (1, "> SkyetekM1 driver shutting down... [done]");	return (0);}int SkyetekM1::ProcessMessage (MessageQueue* resp_queue, 			   player_msghdr * hdr,			   void * data){		if (Message::MatchMessage (hdr, PLAYER_MSGTYPE_REQ, PLAYER_RFID_REQ_POWER,	    device_addr))	{		// Power up/down the RFID reader (NACK for now) 		Publish (device_addr, resp_queue, PLAYER_MSGTYPE_RESP_NACK, 			 hdr->subtype);	}		else if (Message::MatchMessage (hdr, PLAYER_MSGTYPE_REQ, 			 PLAYER_RFID_REQ_READTAG, device_addr))	{		// Read RFID tag data (NACK for now)		Publish (device_addr, resp_queue, PLAYER_MSGTYPE_RESP_NACK, 			 hdr->subtype);	}		else if (Message::MatchMessage (hdr, PLAYER_MSGTYPE_REQ, 			 PLAYER_RFID_REQ_WRITETAG, device_addr))	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -