KatanaNativeInterface $VERSION$
cplSerial.h
Go to the documentation of this file.
1/*
2 * Katana Native Interface - A C++ interface to the robot arm Katana.
3 * Copyright (C) 2005 Neuronics AG
4 * Check out the AUTHORS file for detailed contact information.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21
22/******************************************************************************************************************/
23#ifndef _CPLSERIAL_H_
24#define _CPLSERIAL_H_
25/******************************************************************************************************************/
26#include "common/dllexport.h"
27#include "common/exception.h"
28#include "KNI/cplBase.h"
30
31#define NUMBER_OF_RETRIES_SEND 3 // Number of retries after a failing in the Communication
32#define NUMBER_OF_RETRIES_RECV 3 // Number of retries after a failing in the Communication
33/******************************************************************************************************************/
34
36const int KATANA_ERROR_FLAG = 192;
41
45public:
47 Exception("CRC check failed", -20) {}
48};
49
53protected:
56public:
57 FirmwareException(const std::string & error, const int error_number, const int axis, const char command) throw ():
58 Exception("FirmwareException : '" + error + "'", error_number),
59 _axis_number(axis),
60 _command_char(command) {}
61 const int axis_number() const throw() {
62 return _axis_number;
63 }
64 const char command_char() const throw() {
65 return _command_char;
66 }
67};
68
72
75struct THeader {
76 byte size;
77 byte data[256];
78};
79
82struct TPacket {
83 byte send_sz;
84 byte read_sz;
85};
86
87//----------------------------------------------------------------------------------------------------------------//
88
89
92class DLLDIR CCplSerial : public CCplBase {
93
94protected:
96 TPacket cmd[256];
97
98 byte send_buf[256];
99 byte read_buf[256];
100
101protected:
102 virtual bool load_tbl() = 0;
103 virtual void defineProtocol(byte _kataddr) = 0;
104};
105
106//----------------------------------------------------------------------------------------------------------------//
107
112// class DLLDIR CCplSerialZero : public CCplSerial {
113//
114// protected:
115// virtual bool load_tbl(); //!< Loads the command table from the robot's firmware.
116// virtual void defineProtocol(byte _kataddr); //!< Defines the protocol's attributes.
117//
118// public:
119// /*! \brief Initializing function
120// *
121// * Init the protocols basic attributes.
122// */
123// virtual bool init(CCdlBase* _device, byte _kataddr = 24);
124//
125//
126// /*! \brief Communication function
127// *
128// * Sends a communications packet and receives one from the robot.
129// */
130// virtual TRetCOMM comm(const byte* _pack, byte* _buf, byte* _size);
131// };
132
133//----------------------------------------------------------------------------------------------------------------//
134
138
139protected:
140 virtual bool load_tbl();
141 virtual void defineProtocol(byte _kataddr);
142 virtual void send(byte* send_buf, byte write_sz, short retries = 3); // Sends a packet.
143 virtual void recv(byte* read_buf, byte read_sz, byte* size); // Receives the packet and checks the CRC.
144
145public:
150 virtual bool init(CCdlBase* _device, byte _kataddr = 24);
151
156 virtual void comm(const byte* pack, byte* buf, byte* size);
157
162 virtual void getMasterFirmware(short* fw, short* rev);
163
164};
165
166/******************************************************************************************************************/
167#endif //_CPLSERIALZERO_H_
168/******************************************************************************************************************/
Abstract base class for devices.
Definition: cdlBase.h:47
Abstract base class for protocol definiton.
Definition: cplBase.h:47
Implement the Serial-Zero protocol.
Definition: cplSerial.h:137
virtual void send(byte *send_buf, byte write_sz, short retries=3)
virtual void defineProtocol(byte _kataddr)
Defines the protocol's attributes.
virtual bool init(CCdlBase *_device, byte _kataddr=24)
Initializing function.
virtual void recv(byte *read_buf, byte read_sz, byte *size)
virtual void getMasterFirmware(short *fw, short *rev)
Get the master firmware of the robot we are communicating with.
virtual void comm(const byte *pack, byte *buf, byte *size)
Communication function.
virtual bool load_tbl()
Loads the command table from the robot's firmware.
Base class of two different serial protocols.
Definition: cplSerial.h:92
virtual bool load_tbl()=0
Loads the command table from the robot's firmware.
THeader hdr
header
Definition: cplSerial.h:95
virtual void defineProtocol(byte _kataddr)=0
Defines the protocol's attributes.
Exception(const std::string &message, const int error_number)
Definition: exception.h:85
const int error_number() const
Definition: exception.h:100
Exception reported by the firmware.
Definition: cplSerial.h:52
const char command_char() const
Definition: cplSerial.h:64
const int axis_number() const
Definition: cplSerial.h:61
char _command_char
the command that caused the error
Definition: cplSerial.h:55
FirmwareException(const std::string &error, const int error_number, const int axis, const char command)
Definition: cplSerial.h:57
int _axis_number
axis number, if any
Definition: cplSerial.h:54
CRC check for the answer package failed.
Definition: cplSerial.h:44
const int KATANA_ERROR_FLAG
defines the error flag number
Definition: cplSerial.h:36
#define DLLDIR
Definition: dllexport.h:30
Header of a communication packet.
Definition: cplSerial.h:75
byte data[256]
data part: 16x zero, 1x one, 1x katadr
Definition: cplSerial.h:77
byte size
header size
Definition: cplSerial.h:76
Communication packet.
Definition: cplSerial.h:82
byte read_sz
read size of the packet
Definition: cplSerial.h:84
byte send_sz
send size of the packet
Definition: cplSerial.h:83