Fawkes API  Fawkes Development Version
lase_edl_aqt.h
1 
2 /***************************************************************************
3  * lase_edl_aqt.cpp - Thread to retrieves laser data from Lase LD A OEM
4  *
5  * Created: Wed Oct 08 13:41:02 2008
6  * Copyright 2002 Christian Fritz
7  * 2008-2009 Tim Niemueller [www.niemueller.de]
8  *
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL file in the doc directory.
22  */
23 
24 #ifndef HAVE_LIBPCAN
25 # error "Cannot use Lase EDL driver without libpcan"
26 #endif
27 
28 #ifndef _PLUGINS_LASER_LASE_EDL_AQT_H_
29 # define _PLUGINS_LASER_LASE_EDL_AQT_H_
30 
31 # include "acquisition_thread.h"
32 
33 # include <libpcan.h>
34 # include <string>
35 
37 {
38 public:
39  LaseEdlAcquisitionThread(std::string &cfg_name, std::string &cfg_prefix);
40 
41  // from LaserAcquisitionThread
43 
44  virtual void init();
45  virtual void finalize();
46  virtual void loop();
47 
48 private:
49  static const WORD RESETLEVEL_RESET;
50  static const WORD RESETLEVEL_RESTART;
51  static const WORD RESETLEVEL_HALT_IDLE;
52  static const WORD RESETLEVEL_RELOAD_VOLTSET;
53  static const WORD CONFIGITEM_ARCNET_HISTORIC;
54  static const WORD CONFIGITEM_RS232_RS422;
55  static const WORD CONFIGITEM_CAN;
56  static const WORD CONFIGITEM_SPI;
57  static const WORD CONFIGITEM_ARCNET;
58  static const WORD CONFIGITEM_GLOBAL;
59  static const WORD CONFIGDATA_LENGTH_RS232_RS422;
60  static const WORD CONFIGDATA_LENGTH_CAN;
61  static const WORD CONFIGDATA_LENGTH_ARCNET;
62  static const WORD CONFIGDATA_LENGTH_GLOBAL;
63  static const WORD SECTOR_0;
64  static const WORD SECTOR_1;
65  static const WORD SECTOR_2;
66  static const WORD SECTOR_3;
67  static const WORD SECTOR_4;
68  static const WORD SECTOR_5;
69  static const WORD SECTOR_6;
70  static const WORD SECTOR_7;
71  static const WORD SECTORFUNC_NOT_INITIALIZED;
72  static const WORD SECTORFUNC_NO_MEASUREMENT;
73  static const WORD SECTORFUNC_DUMMY_MEASUREMENT;
74  static const WORD SECTORFUNC_NORMAL_MEASUREMENT;
75  static const WORD SECTORFUNC_REFERENCE_TARGET;
76  static const WORD FLASH_YES;
77  static const WORD FLASH_NO;
78  static const WORD PROFILENUM_CONTINUOUS;
79  static const WORD PROFILEFORMAT_NUMBER;
80  static const WORD PROFILEFORMAT_COUNTER;
81  static const WORD PROFILEFORMAT_LAYER;
82  static const WORD PROFILEFORMAT_SECTOR;
83  static const WORD PROFILEFORMAT_ANGLE_STEP;
84  static const WORD PROFILEFORMAT_NUM_SECT_POINTS;
85  static const WORD PROFILEFORMAT_TIMESTAMP_START;
86  static const WORD PROFILEFORMAT_START_DIRECTION;
87  static const WORD PROFILEFORMAT_DISTANCE;
88  static const WORD PROFILEFORMAT_DIRECTION;
89  static const WORD PROFILEFORMAT_ECHO_AMPLITUDE;
90  static const WORD PROFILEFORMAT_TIMESTAMP_END;
91  static const WORD PROFILEFORMAT_END_DIRECTION;
92  static const WORD PROFILEFORMAT_SENSOR_MODE;
93  static const WORD SERVICEGROUP_STATUS;
94  static const WORD CMD_GET_IDENTIFICATION;
95  static const WORD CMD_GET_STATUS;
96  static const WORD CMD_GET_ERROR;
97  static const WORD CMD_GET_SIGNAL;
98  static const WORD CMD_SET_SIGNAL;
99  static const WORD CMD_REGISTER_APPLICATION;
100  static const WORD SERVICEGROUP_CONFIG;
101  static const WORD CMD_SET_CONFIG;
102  static const WORD CMD_GET_CONFIG;
103  static const WORD CMD_SET_SYNC_ABS;
104  static const WORD CMD_SET_SYNC_REL;
105  static const WORD CMD_SET_SYNC_CLOCK;
106  static const WORD CMD_SET_ZONE;
107  static const WORD CMD_GET_ZONE;
108  static const WORD CMD_RELEASE_ZONE;
109  static const WORD CMD_SET_FILTER;
110  static const WORD CMD_SET_FUNCTION;
111  static const WORD CMD_GET_FUNCTION;
112  static const WORD SERVICEGROUP_MEASUREMENT;
113  static const WORD CMD_GET_PROFILE;
114  static const WORD CMD_CANCEL_PROFILE;
115  static const WORD SERVICEGROUP_WORKING;
116  static const WORD CMD_DO_RESET;
117  static const WORD CMD_TRANS_IDLE;
118  static const WORD CMD_TRANS_ROTATE;
119  static const WORD CMD_TRANS_MEASURE;
120  static const WORD SERVICEGROUP_MAINTENANCE;
121  static const WORD CMD_DO_ADJUST;
122  static const WORD CMD_DO_TEST;
123  static const WORD SERVICEGROUP_INTERFACE_ROUTING;
124  static const WORD CMD_COM_ATTACH;
125  static const WORD CMD_COM_DETACH;
126  static const WORD CMD_COM_INIT;
127  static const WORD CMD_COM_OUTPUT;
128  static const WORD CMD_COM_DATA;
129  static const WORD SERVICEGROUP_FILE;
130  static const WORD CMD_DIR;
131  static const WORD CMD_SAVE;
132  static const WORD CMD_LOAD;
133  static const WORD CMD_DELETE;
134  static const WORD SERVICEGROUP_MONITOR;
135  static const WORD CMD_MONITOR_ENABLE_LOG;
136  static const WORD CMD_MONITOR_DISABLE_LOG;
137  //static const WORD SERVICEGROUP_APPLICATION; 0x1000 to 0x3F00
138  static const WORD SERVICEGROUP_ADJUST;
139  static const WORD SERVICEGROUP_SPECIAL;
140  static const WORD CMD_SERVICE_FAILURE;
141  static const WORD RESPONSE_BIT;
142  static const float DISTANCE_FACTOR;
143 
144 private:
145  unsigned int calc_angle_step(unsigned int rotation_freq, unsigned int max_pulse_freq);
146  inline WORD
147  respcode(WORD cmd)
148  {
149  return cmd | RESPONSE_BIT;
150  }
151  void init_bus();
152  void send(WORD *data, int n);
153  int recv(WORD **data, bool allocate = true);
154 
155  void send_and_check(WORD * command_data,
156  int command_length,
157  WORD * expected_response,
158  int n,
159  WORD **real_response = NULL,
160  int * response_size = NULL);
161 
162  inline void append_to_msg(WORD word, TPCANMsg *msg);
163  inline void append_to_msg(BYTE byte, TPCANMsg *msg);
164  inline WORD get_word_from_msg(TPCANMsg *msg, int *index);
165  WORD * make_word_array(int count, ...);
166  int compare_word_arrays(int count, WORD *a, WORD *b);
167  void print_word_array(int count, WORD *a);
168  void print_message(TPCANMsg *m);
169 
170  void process_profiles();
171 
172  void SET_CONFIG(WORD config_item, int k, ...);
173  void SET_FUNCTION(WORD sect_num, WORD sect_func, WORD sect_stop, WORD flash);
174  void GET_PROFILE(WORD prof_num, WORD prof_format);
175  void CANCEL_PROFILE();
176  void DO_RESET(WORD reset_level);
177  void TRANS_IDLE();
178  void TRANS_ROTATE(WORD frequency);
179  void TRANS_MEASURE();
180 
181 private:
182  HANDLE handle_;
183  bool pre_init_done_;
184 
185  std::string cfg_name_;
186  std::string cfg_prefix_;
187 
188  bool cfg_use_default_;
189  bool cfg_set_default_;
190  unsigned int cfg_rotation_freq_;
191  unsigned int cfg_angle_step_;
192  unsigned int cfg_max_pulse_freq_;
193  unsigned int cfg_profile_format_;
194  unsigned int cfg_can_id_;
195  unsigned int cfg_can_id_resp_;
196  unsigned int cfg_sensor_id_;
197  unsigned int cfg_sensor_id_resp_;
198  unsigned int cfg_interface_type_;
199  unsigned int cfg_btr0btr1_;
200  unsigned int cfg_port_;
201  unsigned int cfg_irq_;
202  unsigned int cfg_num_init_tries_;
203  float cfg_mount_rotation_;
204 
205  unsigned int min_angle_step_;
206  unsigned int number_of_values_;
207 };
208 
209 #endif
LaserAcquisitionThread
Definition: acquisition_thread.h:37
LaseEdlAcquisitionThread::loop
virtual void loop()
Code to execute in the thread.
Definition: lase_edl_aqt.cpp:309
LaseEdlAcquisitionThread::finalize
virtual void finalize()
Finalize the thread.
Definition: lase_edl_aqt.cpp:298
fawkes::Configuration
Definition: config.h:68
LaseEdlAcquisitionThread::pre_init
virtual void pre_init(fawkes::Configuration *config, fawkes::Logger *logger)
Definition: lase_edl_aqt.cpp:153
LaseEdlAcquisitionThread::init
virtual void init()
Initialize the thread.
Definition: lase_edl_aqt.cpp:233
fawkes::LoggingAspect::logger
Logger * logger
Definition: logging.h:50
fawkes::Logger
Definition: logger.h:40
fawkes::ConfigurableAspect::config
Configuration * config
Definition: configurable.h:50
LaseEdlAcquisitionThread
Definition: lase_edl_aqt.h:35
LaseEdlAcquisitionThread::LaseEdlAcquisitionThread
LaseEdlAcquisitionThread(std::string &cfg_name, std::string &cfg_prefix)
Constructor.
Definition: lase_edl_aqt.cpp:143