From 5d7407aded9c6dace130a510f5e785318c0f0006 Mon Sep 17 00:00:00 2001 From: Tristan Krause Date: Wed, 22 May 2019 10:32:51 +0200 Subject: [PATCH] doc update --- control/examples/pegel/main.cpp | 8 +- control/src/drv/b15f.h | 13 +- docs/README.md | 3 + docs/doxygen-cfg | 6 +- docs/html/b15f_8cpp_source.html | 5 +- docs/html/b15f_8h_source.html | 5 +- docs/html/classB15F-members.html | 23 +- docs/html/classB15F.html | 33 +- docs/html/functions.html | 7 - docs/html/functions_func.html | 7 - docs/html/index.html | 9 +- docs/html/menudata.js | 2 - docs/html/search/all_4.js | 3 +- docs/html/search/all_7.js | 2 +- docs/html/search/all_8.js | 3 +- docs/html/search/all_9.js | 6 +- docs/html/search/all_a.js | 7 +- docs/html/search/all_b.js | 6 +- docs/html/search/all_c.js | 5 +- docs/html/search/all_d.js | 7 +- docs/html/search/all_e.js | 7 +- docs/html/search/functions_6.js | 2 +- docs/html/search/functions_7.js | 2 +- docs/html/search/functions_8.js | 5 +- docs/html/search/functions_9.js | 7 +- docs/html/search/functions_a.js | 5 +- docs/html/search/functions_b.js | 4 +- docs/html/search/pages_0.html | 30 ++ docs/html/search/pages_0.js | 4 + docs/html/search/searchdata.js | 11 +- docs/index.html | 15 + docs/latex/Makefile | 23 -- docs/latex/annotated.tex | 15 - docs/latex/classB15F.tex | 501 ----------------------- docs/latex/classDot.tex | 30 -- docs/latex/classDriverException.eps | 197 --------- docs/latex/classDriverException.tex | 38 -- docs/latex/classPlottyFile.tex | 102 ----- docs/latex/classTimeoutException.eps | 197 --------- docs/latex/classTimeoutException.tex | 41 -- docs/latex/classUSART.tex | 273 ------------- docs/latex/classUSARTException.eps | 197 --------- docs/latex/classUSARTException.tex | 38 -- docs/latex/classView.eps | 213 ---------- docs/latex/classView.tex | 78 ---- docs/latex/classViewInfo.eps | 203 ---------- docs/latex/classViewInfo.tex | 64 --- docs/latex/classViewMonitor.eps | 203 ---------- docs/latex/classViewMonitor.tex | 43 -- docs/latex/classViewPromt.eps | 197 --------- docs/latex/classViewPromt.tex | 85 ---- docs/latex/classViewSelection.eps | 197 --------- docs/latex/classViewSelection.tex | 52 --- docs/latex/doxygen.sty | 571 --------------------------- docs/latex/hierarchy.tex | 21 - docs/latex/refman.tex | 189 --------- 56 files changed, 131 insertions(+), 3889 deletions(-) create mode 100644 docs/README.md create mode 100644 docs/html/search/pages_0.html create mode 100644 docs/html/search/pages_0.js create mode 100644 docs/index.html delete mode 100644 docs/latex/Makefile delete mode 100644 docs/latex/annotated.tex delete mode 100644 docs/latex/classB15F.tex delete mode 100644 docs/latex/classDot.tex delete mode 100644 docs/latex/classDriverException.eps delete mode 100644 docs/latex/classDriverException.tex delete mode 100644 docs/latex/classPlottyFile.tex delete mode 100644 docs/latex/classTimeoutException.eps delete mode 100644 docs/latex/classTimeoutException.tex delete mode 100644 docs/latex/classUSART.tex delete mode 100644 docs/latex/classUSARTException.eps delete mode 100644 docs/latex/classUSARTException.tex delete mode 100644 docs/latex/classView.eps delete mode 100644 docs/latex/classView.tex delete mode 100644 docs/latex/classViewInfo.eps delete mode 100644 docs/latex/classViewInfo.tex delete mode 100644 docs/latex/classViewMonitor.eps delete mode 100644 docs/latex/classViewMonitor.tex delete mode 100644 docs/latex/classViewPromt.eps delete mode 100644 docs/latex/classViewPromt.tex delete mode 100644 docs/latex/classViewSelection.eps delete mode 100644 docs/latex/classViewSelection.tex delete mode 100644 docs/latex/doxygen.sty delete mode 100644 docs/latex/hierarchy.tex delete mode 100644 docs/latex/refman.tex diff --git a/control/examples/pegel/main.cpp b/control/examples/pegel/main.cpp index 960b8ad..2487217 100644 --- a/control/examples/pegel/main.cpp +++ b/control/examples/pegel/main.cpp @@ -11,7 +11,7 @@ int main() B15F& drv = B15F::getInstance(); PlottyFile pf; - uint16_t ba[1024]; + uint16_t buf[1024]; const uint16_t sample_count = 1024; const uint16_t delta = 1; @@ -30,12 +30,12 @@ int main() uint8_t curve = 0; - drv.analogSequence(0, &ba[0], 0, 1, nullptr, 0, 0, delta, sample_count); + drv.analogSequence(0, &buf[0], 0, 1, nullptr, 0, 0, delta, sample_count); for(uint16_t x = 0; x < sample_count * delta; x += delta) { - std::cout << x << " - " << ba[x] << std::endl; - pf.addDot(Dot(x, ba[x], curve)); + std::cout << x << " - " << buf[x] << std::endl; + pf.addDot(Dot(x, buf[x], curve)); } // speichern und plotty starten diff --git a/control/src/drv/b15f.h b/control/src/drv/b15f.h index d183644..dc06e43 100644 --- a/control/src/drv/b15f.h +++ b/control/src/drv/b15f.h @@ -32,12 +32,6 @@ public: * Grundfunktionen des B15F Treibers * *************************************/ - /** - * Initialisiert und testet die Verbindung zum B15 - * \throws DriverException - */ - void init(void); - /** * Versucht die Verbindung zum B15 wiederherzustellen * \throws DriverException @@ -182,7 +176,6 @@ public: uint16_t analogRead(uint8_t channel); /** - * \brief Komplexe Analoge Sequenz * DAC 0 wird auf den Startwert gesetzt und dann schrittweise um Delta inkrementiert. * Für jeden eingestelleten DAC-Wert werden zwei ADCs (channel_a und channel_b) angesprochen und die Werte übermittelt. * Die Werte werden in buffer_a für Kanal a und buffer_b für Kanal b gespeichert. @@ -212,6 +205,12 @@ public: constexpr static uint32_t BAUDRATE = 57600; private: + + /** + * Initialisiert und testet die Verbindung zum B15 + * \throws DriverException + */ + void init(void); USART usart; static B15F* instance; diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..99a8a8d --- /dev/null +++ b/docs/README.md @@ -0,0 +1,3 @@ +# Einführung +Die wichtigste Klasse für die Steuerung des Board 15 ist [B15F](classB15F.html). +Dort befindet sich auch eine Übersicht der verfügbaren Befehle. diff --git a/docs/doxygen-cfg b/docs/doxygen-cfg index edfca4d..629c77c 100644 --- a/docs/doxygen-cfg +++ b/docs/doxygen-cfg @@ -827,7 +827,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = "../control/src" +INPUT = ../control/src README.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -1020,7 +1020,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = +USE_MDFILE_AS_MAINPAGE = README.md #--------------------------------------------------------------------------- # Configuration options related to source browsing @@ -1696,7 +1696,7 @@ EXTRA_SEARCH_MAPPINGS = # If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output. # The default value is: YES. -GENERATE_LATEX = YES +GENERATE_LATEX = NO # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of diff --git a/docs/html/b15f_8cpp_source.html b/docs/html/b15f_8cpp_source.html index f7fbaa7..bf5bcd1 100644 --- a/docs/html/b15f_8cpp_source.html +++ b/docs/html/b15f_8cpp_source.html @@ -70,12 +70,12 @@ $(function() {
b15f.cpp
-
1 #include "b15f.h"
2 
3 B15F* B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 B15F::B15F()
7 {
8  init();
9 }
10 
11 void B15F::init()
12 {
13 
14  std::string device = exec("bash -c 'ls /dev/ttyUSB*'");
15  while(device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos)
16  device.pop_back();
17 
18  if(device.length() == 0)
19  abort("Adapter nicht gefunden");
20 
21  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
22 
23 
24 
25  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
26  usart.setBaudrate(BAUDRATE);
27  usart.openDevice(device);
28  std::cout << "OK" << std::endl;
29 
30 
31 
32  std::cout << PRE << "Teste Verbindung... " << std::flush;
33  uint8_t tries = 3;
34  while(tries--)
35  {
36  // verwerfe Daten, die µC noch hat
37  //discard();
38 
39  if(!testConnection())
40  continue;
41 
42  if(!testIntConv())
43  continue;
44 
45  break;
46  }
47  if(tries == 0)
48  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
49  std::cout << "OK" << std::endl;
50 
51 
52  // Gib board info aus
53  std::vector<std::string> info = getBoardInfo();
54  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl;
55 }
56 
58 {
59  uint8_t tries = RECONNECT_TRIES;
60  while(tries--)
61  {
62  delay_ms(RECONNECT_TIMEOUT);
63  discard();
64 
65  if(testConnection())
66  return;
67  }
68 
69  abort("Verbindung kann nicht repariert werden");
70 }
71 
72 void B15F::discard(void)
73 {
74  try
75  {
76  usart.clearOutputBuffer();
77  for(uint8_t i = 0; i < 16; i++)
78  {
79  usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input)
80  delay_ms(4);
81  }
82  usart.clearInputBuffer();
83  }
84  catch(std::exception& ex)
85  {
86  abort(ex);
87  }
88 }
89 
91 {
92  // erzeuge zufälliges Byte
93  srand(time(NULL));
94  uint8_t dummy = rand() % 256;
95 
96  usart.writeByte(RQ_TEST);
97  usart.writeByte(dummy);
98 
99  uint8_t aw = usart.readByte();
100  uint8_t mirror = usart.readByte();
101 
102  return aw == MSG_OK && mirror == dummy;
103 }
104 
106 {
107  srand(time(NULL));
108  uint16_t dummy = rand() % (0xFFFF / 3);
109 
110  usart.writeByte(RQ_INT);
111  usart.writeInt(dummy);
112 
113  uint16_t aw = usart.readInt();
114  return aw == dummy * 3;
115 }
116 
117 
118 std::vector<std::string> B15F::getBoardInfo(void)
119 {
120  std::vector<std::string> info;
121 
122  usart.writeByte(RQ_INFO);
123 
124  uint8_t n = usart.readByte();
125  while(n--)
126  {
127  uint8_t len = usart.readByte();
128  std::string str;
129 
130  while(len--) {
131  str += static_cast<char>(usart.readByte());
132  }
133 
134  info.push_back(str);
135  }
136 
137  uint8_t aw = usart.readByte();
138  if(aw != MSG_OK)
139  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
140 
141  return info;
142 }
143 
145 {
146  usart.writeByte(RQ_ST);
147 
148  uint8_t aw = usart.readByte();
149  return aw == MSG_OK;
150 }
151 
152 bool B15F::digitalWrite0(uint8_t port)
153 {
154  usart.writeByte(RQ_BA0);
155  usart.writeByte(port);
156 
157  uint8_t aw = usart.readByte();
158  delay_us(10);
159  return aw == MSG_OK;
160 }
161 
162 bool B15F::digitalWrite1(uint8_t port)
163 {
164  usart.writeByte(RQ_BA1);
165  usart.writeByte(port);
166 
167  uint8_t aw = usart.readByte();
168  delay_us(10);
169  return aw == MSG_OK;
170 }
171 
173 {
174  usart.clearInputBuffer();
175  usart.writeByte(RQ_BE0);
176  uint8_t byte = usart.readByte();
177  delay_us(10);
178  return byte;
179 }
180 
182 {
183  usart.clearInputBuffer();
184  usart.writeByte(RQ_BE1);
185  uint8_t byte = usart.readByte();
186  delay_us(10);
187  return byte;
188 }
189 
191 {
192  usart.clearInputBuffer();
193  usart.writeByte(RQ_DSW);
194  uint8_t byte = usart.readByte();
195  delay_us(10);
196  return byte;
197 }
198 
199 bool B15F::analogWrite0(uint16_t value)
200 {
201  usart.writeByte(RQ_AA0);
202  usart.writeInt(value);
203 
204  uint8_t aw = usart.readByte();
205  delay_us(10);
206  return aw == MSG_OK;
207 }
208 
209 bool B15F::analogWrite1(uint16_t value)
210 {
211  usart.writeByte(RQ_AA1);
212  usart.writeInt(value);
213 
214  uint8_t aw = usart.readByte();
215  delay_us(10);
216  return aw == MSG_OK;
217 }
218 
219 uint16_t B15F::analogRead(uint8_t channel)
220 {
221  usart.clearInputBuffer();
222  if(channel > 7)
223  abort("Bad ADC channel: " + std::to_string(channel));
224 
225  uint8_t rq[] = {
226  RQ_ADC,
227  channel
228  };
229 
230  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
231  if(n_sent != sizeof(rq))
232  abort("Sent failed");
233 
234  uint16_t adc = usart.readInt();
235 
236  if(adc > 1023)
237  abort("Bad ADC data detected (1)");
238  return adc;
239 }
240 
241 void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
242 {
243  // check pointers
244  buffer_a += offset_a;
245  buffer_b += offset_b;
246 
247 
248  usart.clearInputBuffer();
249  usart.writeByte(RQ_ADC_DAC_STROKE);
250  usart.writeByte(channel_a);
251  usart.writeByte(channel_b);
252  usart.writeInt(start);
253  usart.writeInt(static_cast<uint16_t>(delta));
254  usart.writeInt(count);
255 
256  for(uint16_t i = 0; i < count; i++)
257  {
258  if(buffer_a)
259  {
260  buffer_a[i] = usart.readInt();
261 
262  if(buffer_a[i] > 1023) // check for broken usart connection
263  abort("Bad ADC data detected (2)");
264  }
265  else
266  {
267  usart.readInt();
268  }
269 
270  if(buffer_b)
271  {
272  buffer_b[i] = usart.readInt();
273 
274  if(buffer_b[i] > 1023) // check for broken usart connection
275  abort("Bad ADC data detected (3)");
276  }
277  else
278  {
279  usart.readInt();
280  }
281  }
282 
283  uint8_t aw = usart.readByte();
284  if(aw != MSG_OK)
285  abort("Sequenz unterbrochen");
286 
287  delay_us(10);
288 }
289 
290 void B15F::delay_ms(uint16_t ms)
291 {
292  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
293 }
294 
295 void B15F::delay_us(uint16_t us)
296 {
297  std::this_thread::sleep_for(std::chrono::microseconds(us));
298 }
299 
301 {
302  if(!instance)
303  instance = new B15F();
304 
305  return *instance;
306 }
307 
308 // https://stackoverflow.com/a/478960
309 std::string B15F::exec(std::string cmd) {
310  std::array<char, 128> buffer;
311  std::string result;
312  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
313  if (!pipe) {
314  throw std::runtime_error("popen() failed!");
315  }
316  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
317  result += buffer.data();
318  }
319  return result;
320 }
321 
322 void B15F::abort(std::string msg)
323 {
324  DriverException ex(msg);
325  abort(ex);
326 }
327 void B15F::abort(std::exception& ex)
328 {
329  if(errorhandler)
330  errorhandler(ex);
331  else
332  {
333  std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
334  std::cout << ex.what() << std::endl;
335  throw DriverException(ex.what());
336  }
337 }
338 
339 void B15F::setAbortHandler(errorhandler_t func)
340 {
341  errorhandler = func;
342 }
+
1 #include "b15f.h"
2 
3 B15F* B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 B15F::B15F()
7 {
8  init();
9 }
10 
11 void B15F::init()
12 {
13 
14  std::string device = exec("bash -c 'ls /dev/ttyUSB*'");
15  while(device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos)
16  device.pop_back();
17 
18  if(device.length() == 0)
19  abort("Adapter nicht gefunden");
20 
21  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
22 
23 
24 
25  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
26  usart.setBaudrate(BAUDRATE);
27  usart.openDevice(device);
28  std::cout << "OK" << std::endl;
29 
30 
31 
32  std::cout << PRE << "Teste Verbindung... " << std::flush;
33  uint8_t tries = 3;
34  while(tries--)
35  {
36  // verwerfe Daten, die µC noch hat
37  //discard();
38 
39  if(!testConnection())
40  continue;
41 
42  if(!testIntConv())
43  continue;
44 
45  break;
46  }
47  if(tries == 0)
48  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
49  std::cout << "OK" << std::endl;
50 
51 
52  // Gib board info aus
53  std::vector<std::string> info = getBoardInfo();
54  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl;
55 }
56 
58 {
59  uint8_t tries = RECONNECT_TRIES;
60  while(tries--)
61  {
62  delay_ms(RECONNECT_TIMEOUT);
63  discard();
64 
65  if(testConnection())
66  return;
67  }
68 
69  abort("Verbindung kann nicht repariert werden");
70 }
71 
72 void B15F::discard(void)
73 {
74  try
75  {
76  usart.clearOutputBuffer();
77  for(uint8_t i = 0; i < 16; i++)
78  {
79  usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input)
80  delay_ms(4);
81  }
82  usart.clearInputBuffer();
83  }
84  catch(std::exception& ex)
85  {
86  abort(ex);
87  }
88 }
89 
91 {
92  // erzeuge zufälliges Byte
93  srand(time(NULL));
94  uint8_t dummy = rand() % 256;
95 
96  usart.writeByte(RQ_TEST);
97  usart.writeByte(dummy);
98 
99  uint8_t aw = usart.readByte();
100  uint8_t mirror = usart.readByte();
101 
102  return aw == MSG_OK && mirror == dummy;
103 }
104 
106 {
107  srand(time(NULL));
108  uint16_t dummy = rand() % (0xFFFF / 3);
109 
110  usart.writeByte(RQ_INT);
111  usart.writeInt(dummy);
112 
113  uint16_t aw = usart.readInt();
114  return aw == dummy * 3;
115 }
116 
117 
118 std::vector<std::string> B15F::getBoardInfo(void)
119 {
120  std::vector<std::string> info;
121 
122  usart.writeByte(RQ_INFO);
123 
124  uint8_t n = usart.readByte();
125  while(n--)
126  {
127  uint8_t len = usart.readByte();
128  std::string str;
129 
130  while(len--) {
131  str += static_cast<char>(usart.readByte());
132  }
133 
134  info.push_back(str);
135  }
136 
137  uint8_t aw = usart.readByte();
138  if(aw != MSG_OK)
139  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
140 
141  return info;
142 }
143 
145 {
146  usart.writeByte(RQ_ST);
147 
148  uint8_t aw = usart.readByte();
149  return aw == MSG_OK;
150 }
151 
152 bool B15F::digitalWrite0(uint8_t port)
153 {
154  usart.writeByte(RQ_BA0);
155  usart.writeByte(port);
156 
157  uint8_t aw = usart.readByte();
158  delay_us(10);
159  return aw == MSG_OK;
160 }
161 
162 bool B15F::digitalWrite1(uint8_t port)
163 {
164  usart.writeByte(RQ_BA1);
165  usart.writeByte(port);
166 
167  uint8_t aw = usart.readByte();
168  delay_us(10);
169  return aw == MSG_OK;
170 }
171 
173 {
174  usart.clearInputBuffer();
175  usart.writeByte(RQ_BE0);
176  uint8_t byte = usart.readByte();
177  delay_us(10);
178  return byte;
179 }
180 
182 {
183  usart.clearInputBuffer();
184  usart.writeByte(RQ_BE1);
185  uint8_t byte = usart.readByte();
186  delay_us(10);
187  return byte;
188 }
189 
191 {
192  usart.clearInputBuffer();
193  usart.writeByte(RQ_DSW);
194  uint8_t byte = usart.readByte();
195  delay_us(10);
196  return byte;
197 }
198 
199 bool B15F::analogWrite0(uint16_t value)
200 {
201  usart.writeByte(RQ_AA0);
202  usart.writeInt(value);
203 
204  uint8_t aw = usart.readByte();
205  delay_us(10);
206  return aw == MSG_OK;
207 }
208 
209 bool B15F::analogWrite1(uint16_t value)
210 {
211  usart.writeByte(RQ_AA1);
212  usart.writeInt(value);
213 
214  uint8_t aw = usart.readByte();
215  delay_us(10);
216  return aw == MSG_OK;
217 }
218 
219 uint16_t B15F::analogRead(uint8_t channel)
220 {
221  usart.clearInputBuffer();
222  if(channel > 7)
223  abort("Bad ADC channel: " + std::to_string(channel));
224 
225  uint8_t rq[] = {
226  RQ_ADC,
227  channel
228  };
229 
230  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
231  if(n_sent != sizeof(rq))
232  abort("Sent failed");
233 
234  uint16_t adc = usart.readInt();
235 
236  if(adc > 1023)
237  abort("Bad ADC data detected (1)");
238  return adc;
239 }
240 
241 void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
242 {
243  // check pointers
244  buffer_a += offset_a;
245  buffer_b += offset_b;
246 
247 
248  usart.clearInputBuffer();
249  usart.writeByte(RQ_ADC_DAC_STROKE);
250  usart.writeByte(channel_a);
251  usart.writeByte(channel_b);
252  usart.writeInt(start);
253  usart.writeInt(static_cast<uint16_t>(delta));
254  usart.writeInt(count);
255 
256  for(uint16_t i = 0; i < count; i++)
257  {
258  if(buffer_a)
259  {
260  buffer_a[i] = usart.readInt();
261 
262  if(buffer_a[i] > 1023) // check for broken usart connection
263  abort("Bad ADC data detected (2)");
264  }
265  else
266  {
267  usart.readInt();
268  }
269 
270  if(buffer_b)
271  {
272  buffer_b[i] = usart.readInt();
273 
274  if(buffer_b[i] > 1023) // check for broken usart connection
275  abort("Bad ADC data detected (3)");
276  }
277  else
278  {
279  usart.readInt();
280  }
281  }
282 
283  uint8_t aw = usart.readByte();
284  if(aw != MSG_OK)
285  abort("Sequenz unterbrochen");
286 
287  delay_us(10);
288 }
289 
290 void B15F::delay_ms(uint16_t ms)
291 {
292  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
293 }
294 
295 void B15F::delay_us(uint16_t us)
296 {
297  std::this_thread::sleep_for(std::chrono::microseconds(us));
298 }
299 
301 {
302  if(!instance)
303  instance = new B15F();
304 
305  return *instance;
306 }
307 
308 // https://stackoverflow.com/a/478960
309 std::string B15F::exec(std::string cmd) {
310  std::array<char, 128> buffer;
311  std::string result;
312  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
313  if (!pipe) {
314  throw std::runtime_error("popen() failed!");
315  }
316  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
317  result += buffer.data();
318  }
319  return result;
320 }
321 
322 void B15F::abort(std::string msg)
323 {
324  DriverException ex(msg);
325  abort(ex);
326 }
327 void B15F::abort(std::exception& ex)
328 {
329  if(errorhandler)
330  errorhandler(ex);
331  else
332  {
333  std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
334  std::cout << ex.what() << std::endl;
335  throw DriverException(ex.what());
336  }
337 }
338 
339 void B15F::setAbortHandler(errorhandler_t func)
340 {
341  errorhandler = func;
342 }
static std::string exec(std::string cmd)
Definition: b15f.cpp:309
uint8_t readByte(void)
Definition: usart.cpp:210
void delay_us(uint16_t us)
Definition: b15f.cpp:295
uint8_t digitalRead0(void)
Definition: b15f.cpp:172
-
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Komplexe Analoge Sequenz DAC 0 wird auf den Startwert gesetzt und dann schrittweise um Delta inkremen...
Definition: b15f.cpp:241
+
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:241
bool testConnection(void)
Definition: b15f.cpp:90
uint8_t readDipSwitch(void)
Definition: b15f.cpp:190
void delay_ms(uint16_t ms)
Definition: b15f.cpp:290
@@ -92,7 +92,6 @@ $(function() {
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:118
void writeByte(uint8_t b)
Definition: usart.cpp:67
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:162
-
void init(void)
Definition: b15f.cpp:11
void discard(void)
Definition: b15f.cpp:72
bool analogWrite0(uint16_t)
Definition: b15f.cpp:199
void openDevice(std::string device)
Definition: usart.cpp:3
diff --git a/docs/html/b15f_8h_source.html b/docs/html/b15f_8h_source.html index 33242e7..4dffe52 100644 --- a/docs/html/b15f_8h_source.html +++ b/docs/html/b15f_8h_source.html @@ -70,11 +70,11 @@ $(function() {
b15f.h
-
1 #ifndef B15F_H
2 #define B15F_H
3 
4 #include <iostream>
5 #include <bits/stdc++.h>
6 #include <string>
7 #include <fstream>
8 #include <cstdlib>
9 #include <chrono>
10 #include <cstdint>
11 #include <vector>
12 
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include <termios.h>
17 #include "usart.h"
18 #include "driverexception.h"
19 #include "timeoutexception.h"
20 
21 typedef std::function<void(std::exception&)> errorhandler_t;
22 
23 
24 class B15F
25 {
26 private:
27  // privater Konstruktor
28  B15F(void);
29 public:
30 
31  /*************************************
32  * Grundfunktionen des B15F Treibers *
33  *************************************/
34 
39  void init(void);
40 
45  void reconnect(void);
46 
51  void discard(void);
52 
57  bool testConnection(void);
58 
63  bool testIntConv(void);
64 
69  std::vector<std::string> getBoardInfo(void);
70 
75  void delay_ms(uint16_t ms);
76 
81  void delay_us(uint16_t us);
82 
87  static B15F& getInstance(void);
88 
93  static std::string exec(std::string cmd);
94 
99  static void abort(std::string msg);
100 
105  static void abort(std::exception& ex);
106 
111  static void setAbortHandler(errorhandler_t func);
112 
113  /*************************************/
114 
115 
116 
117  /*************************
118  * Steuerbefehle für B15 *
119  *************************/
120 
126  bool activateSelfTestMode(void);
127 
133  bool digitalWrite0(uint8_t);
134 
140  bool digitalWrite1(uint8_t);
141 
147  uint8_t digitalRead0(void);
148 
154  uint8_t digitalRead1(void);
155 
161  uint8_t readDipSwitch(void);
162 
168  bool analogWrite0(uint16_t);
169 
175  bool analogWrite1(uint16_t);
176 
182  uint16_t analogRead(uint8_t channel);
183 
200  void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count);
201 
202  /*************************/
203 
204 
205  // CONSTANTS
206  const std::string PRE = "[B15F] ";
207  constexpr static uint8_t MSG_OK = 0xFF;
208  constexpr static uint8_t MSG_FAIL = 0xFE;
209  constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms
210  constexpr static uint16_t WDT_TIMEOUT = 15; // ms
211  constexpr static uint8_t RECONNECT_TRIES = 3;
212  constexpr static uint32_t BAUDRATE = 57600;
213 
214 private:
215 
216  USART usart;
217  static B15F* instance;
218  static errorhandler_t errorhandler;
219 
220  // REQUESTS
221  constexpr static uint8_t RQ_DISC = 0;
222  constexpr static uint8_t RQ_TEST = 1;
223  constexpr static uint8_t RQ_INFO = 2;
224  constexpr static uint8_t RQ_INT = 3;
225  constexpr static uint8_t RQ_ST = 4;
226  constexpr static uint8_t RQ_BA0 = 5;
227  constexpr static uint8_t RQ_BA1 = 6;
228  constexpr static uint8_t RQ_BE0 = 7;
229  constexpr static uint8_t RQ_BE1 = 8;
230  constexpr static uint8_t RQ_DSW = 9;
231  constexpr static uint8_t RQ_AA0 = 10;
232  constexpr static uint8_t RQ_AA1 = 11;
233  constexpr static uint8_t RQ_ADC = 12;
234  constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
235 };
236 
237 #endif // B15F_H
+
1 #ifndef B15F_H
2 #define B15F_H
3 
4 #include <iostream>
5 #include <bits/stdc++.h>
6 #include <string>
7 #include <fstream>
8 #include <cstdlib>
9 #include <chrono>
10 #include <cstdint>
11 #include <vector>
12 
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include <termios.h>
17 #include "usart.h"
18 #include "driverexception.h"
19 #include "timeoutexception.h"
20 
21 typedef std::function<void(std::exception&)> errorhandler_t;
22 
23 
24 class B15F
25 {
26 private:
27  // privater Konstruktor
28  B15F(void);
29 public:
30 
31  /*************************************
32  * Grundfunktionen des B15F Treibers *
33  *************************************/
34 
39  void reconnect(void);
40 
45  void discard(void);
46 
51  bool testConnection(void);
52 
57  bool testIntConv(void);
58 
63  std::vector<std::string> getBoardInfo(void);
64 
69  void delay_ms(uint16_t ms);
70 
75  void delay_us(uint16_t us);
76 
81  static B15F& getInstance(void);
82 
87  static std::string exec(std::string cmd);
88 
93  static void abort(std::string msg);
94 
99  static void abort(std::exception& ex);
100 
105  static void setAbortHandler(errorhandler_t func);
106 
107  /*************************************/
108 
109 
110 
111  /*************************
112  * Steuerbefehle für B15 *
113  *************************/
114 
120  bool activateSelfTestMode(void);
121 
127  bool digitalWrite0(uint8_t);
128 
134  bool digitalWrite1(uint8_t);
135 
141  uint8_t digitalRead0(void);
142 
148  uint8_t digitalRead1(void);
149 
155  uint8_t readDipSwitch(void);
156 
162  bool analogWrite0(uint16_t);
163 
169  bool analogWrite1(uint16_t);
170 
176  uint16_t analogRead(uint8_t channel);
177 
193  void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count);
194 
195  /*************************/
196 
197 
198  // CONSTANTS
199  const std::string PRE = "[B15F] ";
200  constexpr static uint8_t MSG_OK = 0xFF;
201  constexpr static uint8_t MSG_FAIL = 0xFE;
202  constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms
203  constexpr static uint16_t WDT_TIMEOUT = 15; // ms
204  constexpr static uint8_t RECONNECT_TRIES = 3;
205  constexpr static uint32_t BAUDRATE = 57600;
206 
207 private:
208 
213  void init(void);
214 
215  USART usart;
216  static B15F* instance;
217  static errorhandler_t errorhandler;
218 
219  // REQUESTS
220  constexpr static uint8_t RQ_DISC = 0;
221  constexpr static uint8_t RQ_TEST = 1;
222  constexpr static uint8_t RQ_INFO = 2;
223  constexpr static uint8_t RQ_INT = 3;
224  constexpr static uint8_t RQ_ST = 4;
225  constexpr static uint8_t RQ_BA0 = 5;
226  constexpr static uint8_t RQ_BA1 = 6;
227  constexpr static uint8_t RQ_BE0 = 7;
228  constexpr static uint8_t RQ_BE1 = 8;
229  constexpr static uint8_t RQ_DSW = 9;
230  constexpr static uint8_t RQ_AA0 = 10;
231  constexpr static uint8_t RQ_AA1 = 11;
232  constexpr static uint8_t RQ_ADC = 12;
233  constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
234 };
235 
236 #endif // B15F_H
static std::string exec(std::string cmd)
Definition: b15f.cpp:309
void delay_us(uint16_t us)
Definition: b15f.cpp:295
uint8_t digitalRead0(void)
Definition: b15f.cpp:172
-
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Komplexe Analoge Sequenz DAC 0 wird auf den Startwert gesetzt und dann schrittweise um Delta inkremen...
Definition: b15f.cpp:241
+
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:241
bool testConnection(void)
Definition: b15f.cpp:90
uint8_t readDipSwitch(void)
Definition: b15f.cpp:190
void delay_ms(uint16_t ms)
Definition: b15f.cpp:290
@@ -88,7 +88,6 @@ $(function() {
bool activateSelfTestMode(void)
Definition: b15f.cpp:144
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:118
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:162
-
void init(void)
Definition: b15f.cpp:11
void discard(void)
Definition: b15f.cpp:72
bool analogWrite0(uint16_t)
Definition: b15f.cpp:199
uint8_t digitalRead1(void)
Definition: b15f.cpp:181
diff --git a/docs/html/classB15F-members.html b/docs/html/classB15F-members.html index cd747d3..6ad79a3 100644 --- a/docs/html/classB15F-members.html +++ b/docs/html/classB15F-members.html @@ -87,18 +87,17 @@ $(function() { exec(std::string cmd)B15Fstatic getBoardInfo(void)B15F getInstance(void)B15Fstatic - init(void)B15F - MSG_FAIL (defined in B15F)B15Fstatic - MSG_OK (defined in B15F)B15Fstatic - PRE (defined in B15F)B15F - readDipSwitch(void)B15F - reconnect(void)B15F - RECONNECT_TIMEOUT (defined in B15F)B15Fstatic - RECONNECT_TRIES (defined in B15F)B15Fstatic - setAbortHandler(errorhandler_t func)B15Fstatic - testConnection(void)B15F - testIntConv(void)B15F - WDT_TIMEOUT (defined in B15F)B15Fstatic + MSG_FAIL (defined in B15F)B15Fstatic + MSG_OK (defined in B15F)B15Fstatic + PRE (defined in B15F)B15F + readDipSwitch(void)B15F + reconnect(void)B15F + RECONNECT_TIMEOUT (defined in B15F)B15Fstatic + RECONNECT_TRIES (defined in B15F)B15Fstatic + setAbortHandler(errorhandler_t func)B15Fstatic + testConnection(void)B15F + testIntConv(void)B15F + WDT_TIMEOUT (defined in B15F)B15Fstatic