This repository has been archived by the owner on Mar 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial.h
137 lines (116 loc) · 4.74 KB
/
serial.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/****************************************************************
*
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
* X Bonaventure Robotics Labratory X
* X X
* X serial Version 1.4 X
* X serial.cpp X
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*
* Copyright (C) 2001, 2002, 2004 Robert M. Harlan
*
* 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; version 2 of the License,
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
*
* You may obtain a copy of the GNU General Public License by writing to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* Developed by the Computer Science Departmetn, St. Bonaventure University.
* Contributors: Dr. Robert Harlan, Shelley McClarigan, Catherine Mellon,
* Brian C. Zimmel, and Josh Goodberry
* Contact: [email protected]
* http://web.sbu.edu/cs/roboticsLab
*
* This version may be the one that writes to a linux serial port
*
* Rev 1.1 Shelley McClarigan
*
* This is a serial port class to handle communication with
* a khepera robot and the host computer. The class can open
* and close the connection to the robot through a specified
* serial port. It also includes a function that sends the
* commands and receives responses from the robot.
*
* Modified from khep_serial.c written by M. von Holzen and
* L. Tettoni and released by Olivier Michel as part of the
* code we orignially got with the khepera.
*
* Rev 1.2 Dr. Robert Harlan
*
* Added default arguments to readline() and Talk() to permit
* return of lines > 64 as needed by vision turret
* Allows buffer lengths to be set by user. (4/22/01)
*
* Rev 1.3 Brian Zimmel, Mike Neel, Josh Goodberry
*
* Added error checking to notify user if a problem has
* occured. (5/24/01)
*
* Rev 1.4 Robert Harlan
* Parameter added to Serial constructor so that verbose status
* set by kRobot (default is false) is passed to Serial object (4/15/04)
*
* Date Created: 2/00
* Last Update: 4/15/04
*****************************************************************/
#ifndef serial_H
#define serial_H
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termio.h>
#include "apstring.h"
using namespace std;
#define clear(var, mask) var &= (~(mask))
#define set(var,mask) var |= (mask)
class Serial {
public:
//Purpose: Constructor.
//Preconditions: None.
//PostConditions: Sets Verbose to bool value, message size,
// and default timeout and retry.
Serial(bool);
//Purpose: Display all of the debugging messages on the screen.
//Preconditions: None.
//Postconditions: VERBOSE set to true.
void VerboseOn();
//Purpose: Stops the displaying of the debugging messages on the screen.
//Preconditions: None.
//Postconditions: VERBOSE set to false.
void VerboseOff();
//Purpose: Open connection to Khepera on port passed
// as a parameter e.g., "ttya".
//Preconditions: Port name is defined
//Postconditions: Connection open to given port. Returns true if successful,
// false otherwise.
bool Open(apstring portname);
//Purpose: Send command to Khepera and return response.
//Preconditions: Commands are in the form of a capital letter,
// followed by any parameters needed, ending with
// a carriage return and line feed.
//Postconditions: Responses are in the form of a lowercase letter
// corresponding to the capital letter command, then
// any data it needs to transmit and a carriage return.
apstring Talk(apstring send, int size = 64);
//Purpose: Close the serial connection.
//Preconditions: Connection must be open.
//Postconditions: Connection is closed to port. Returns true if successful,
// false otherwise.
bool Close();
private:
bool VERBOSE;
int MESSAGE_SIZE;
int DEFAULT_TIMEOUT;
int DEFAULT_RETRY;
int SERIAL_ID;
apstring Readline(int size = 64);
bool Configure();
bool Drain();
};
#endif