-
Notifications
You must be signed in to change notification settings - Fork 0
/
vrpn_Atmel.h
128 lines (94 loc) · 4.79 KB
/
vrpn_Atmel.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
// -*- Mode:C++ -*-
/***************************************************************************************************/
/* */
/* Copyright (C) 2004 Bauhaus University Weimar */
/* Released into the public domain on 6/23/2007 as part of the VRPN project */
/* by Jan P. Springer. */
/* */
/***************************************************************************************************/
/* */
/* module : vrpn_Atmel.h */
/* project : vrpn_Avango */
/* description: server for microcontroller board based on Atmel's ATMEGA32 */
/* hardware developed by Albotronic: www.albotronic.de */
/* */
/***************************************************************************************************/
#ifndef VRPN_ATMEL
#define VRPN_ATMEL
/***************************************************************************************************/
/* compiler flags */
/* serial lib
default is atmellib
can be changed to vrpn_Serial (problems when dropping connection from client side,
read blocks for unknown reason
*/
//#define VRPN_ATMEL_SERIAL_VRPN
/* debug flags */
#define VRPN_ATMEL_VERBOSE
//#define VRPN_ATMEL_TIME_MEASURE
/***************************************************************************************************/
/* vrpn atmellib error values -> reported to the client */
#define VRPN_ATMEL_ERROR_READING_IN -21
#define VRPN_ATMEL_ERROR_WRITING_DOWN -22
#define VRPN_ATMEL_ERROR_OUT_OF_RANGE -23
#define VRPN_ATMEL_ERROR_NOT_WRITABLE -24
#define VRPN_ATMEL_MODE_RO 101
#define VRPN_ATMEL_MODE_RW 102
#define VRPN_ATMEL_MODE_WO 103
#define VRPN_ATMEL_MODE_NA 104
#define VRPN_ATMEL_STATUS_WAITING_FOR_CONNECTION 201
#define VRPN_ATMEL_STATUS_RUNNING 202
#define VRPN_ATMEL_STATUS_ERROR -200
#define VRPN_ATMEL_CHANNEL_NOT_VALID -1
#define VRPN_ATMEL_ALIVE_TIME_LOOK_SEC 3
#define VRPN_ATMEL_ALIVE_TIME_LOOK_USEC 0
#define VRPN_ATMEL_ALIVE_INTERVAL_SEC 1
/***************************************************************************************************/
/* system includes */
#include <vector> // for vector
#include <stddef.h> // for NULL
/***************************************************************************************************/
/* project includes */
#include "vrpn_Analog.h" // for vrpn_Analog_Server
#include "vrpn_Analog_Output.h" // for vrpn_Analog_Output_Server
#include "vrpn_Configure.h" // for VRPN_API
#include "vrpn_Shared.h" // for timeval
class VRPN_API vrpn_Connection;
#ifdef VRPN_ATMEL_SERIAL_VRPN
# include "vrpn_Serial.h"
#endif
/***************************************************************************************************/
class VRPN_API vrpn_Atmel : public vrpn_Analog_Server, vrpn_Analog_Output_Server {
public:
static vrpn_Atmel *
Create(char* name, vrpn_Connection *c,
const char *port="/dev/ttyS0/", long baud=9600,
int channel_count=0,
int * channel_mode=NULL);
~vrpn_Atmel();
void mainloop();
private:
// constructor
vrpn_Atmel(char* name, vrpn_Connection *c, int fd);
private:
void init_channel_mode(int * channel_mode);
// do the serial communication in mainloop
bool mainloop_serial_io();
// things which have to be done when a new connection has been established
bool handle_new_connection();
// enable connection reliability checking by additional select
bool Check_Serial_Alive();
private:
// indicator for current status of server
// one of the predefined value: VRPN_ATMEL_STATUS_*
int _status;
// time of report
struct timeval timestamp;
int serial_fd;
// indicator for io-mode of the channels
// one of the predefined values: VRPN_ATMEL_MODE_*
std::vector<int> _channel_mode;
// helper for Serial_Alive: do the stuff not in every mainloop -> _time_alive
struct timeval _time_alive;
};
#endif // #ifndef VRPN_ATMEL