From d7179914ad822dee3bb5df4ff606fffb7792a404 Mon Sep 17 00:00:00 2001 From: Tristan Krause Date: Fri, 28 Jun 2019 14:21:10 +0200 Subject: [PATCH] =?UTF-8?q?versionspr=C3=BCfung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/src/Makefile | 16 ++-- control/src/commit_hash.h | 4 + control/src/drv/b15f.cpp | 12 ++- control/src/drv/b15f.h | 1 + docs/html/annotated.html | 2 +- docs/html/b15f_8cpp_source.html | 16 ++-- docs/html/b15f_8h_source.html | 20 ++--- docs/html/classB15F-members.html | 2 +- docs/html/classB15F.html | 4 +- docs/html/classDot-members.html | 2 +- docs/html/classDot.html | 2 +- docs/html/classDriverException-members.html | 2 +- docs/html/classDriverException.html | 2 +- docs/html/classPlottyFile-members.html | 2 +- docs/html/classPlottyFile.html | 2 +- docs/html/classTimeoutException-members.html | 2 +- docs/html/classTimeoutException.html | 2 +- docs/html/classUSART-members.html | 2 +- docs/html/classUSART.html | 2 +- docs/html/classUSARTException-members.html | 2 +- docs/html/classUSARTException.html | 2 +- docs/html/classView-members.html | 2 +- docs/html/classView.html | 2 +- docs/html/classViewInfo-members.html | 2 +- docs/html/classViewInfo.html | 2 +- docs/html/classViewMonitor-members.html | 2 +- docs/html/classViewMonitor.html | 2 +- docs/html/classViewPromt-members.html | 2 +- docs/html/classViewPromt.html | 2 +- docs/html/classViewSelection-members.html | 2 +- docs/html/classViewSelection.html | 2 +- docs/html/classes.html | 2 +- docs/html/cli_8cpp_source.html | 2 +- docs/html/commit__hash_8h_source.html | 77 +++++++++++++++++++ .../dir_1788f8309b1a812dcb800a185471cf6c.html | 2 +- .../dir_587c94d866dbb2f408f78cf41f9b2f8d.html | 2 +- docs/html/dot_8cpp_source.html | 2 +- docs/html/dot_8h_source.html | 2 +- docs/html/driverexception_8h_source.html | 2 +- docs/html/files.html | 3 +- docs/html/functions.html | 2 +- docs/html/functions_func.html | 2 +- docs/html/functions_vars.html | 2 +- docs/html/hierarchy.html | 2 +- docs/html/index.html | 2 +- docs/html/plottyfile_8cpp_source.html | 2 +- docs/html/plottyfile_8h_source.html | 2 +- docs/html/requests_8h_source.html | 2 +- docs/html/timeoutexception_8h_source.html | 2 +- docs/html/ui_8cpp_source.html | 6 +- docs/html/ui_8h_source.html | 2 +- docs/html/usart_8cpp_source.html | 2 +- docs/html/usart_8h_source.html | 2 +- docs/html/usartexception_8h_source.html | 2 +- docs/html/view_8cpp_source.html | 2 +- docs/html/view_8h_source.html | 2 +- docs/html/view__info_8cpp_source.html | 2 +- docs/html/view__info_8h_source.html | 2 +- docs/html/view__monitor_8cpp_source.html | 4 +- docs/html/view__monitor_8h_source.html | 2 +- docs/html/view__promt_8cpp_source.html | 2 +- docs/html/view__promt_8h_source.html | 2 +- docs/html/view__selection_8cpp_source.html | 2 +- docs/html/view__selection_8h_source.html | 2 +- firmware/Makefile | 2 +- firmware/boardinfo.h | 2 + firmware/commit_hash.h | 2 +- firmware/request_handlers.cpp | 3 +- 68 files changed, 189 insertions(+), 89 deletions(-) create mode 100644 control/src/commit_hash.h create mode 100644 docs/html/commit__hash_8h_source.html diff --git a/control/src/Makefile b/control/src/Makefile index 62cfdac..cd8c2b7 100644 --- a/control/src/Makefile +++ b/control/src/Makefile @@ -42,7 +42,7 @@ OBJECTS_CLI = cli.o ui/view.o ui/view_selection.o ui/view_promt.o ui/view_info all: drv cli -drv: $(OBJECTS_DRV) $(OUT_TMP_DRV) +drv: commit_hash $(OBJECTS_DRV) $(OUT_TMP_DRV) cli: drv $(OBJECTS_CLI) @@ -55,6 +55,11 @@ doc: style @echo "Creating documentation with doxygen..." $(PATH_DOXYGEN) doxygen-cfg @echo problems found: `($(PATH_DOXYGEN) doxygen-cfg 3>&2 2>&1 1>&3) 2>/dev/null | wc -l` + +$(OUT_TMP_DRV): + @echo "Linking driver library..." + @mkdir -p ../lib + $(PATH_COMPILER) $(CFLAGS) $(OBJECTS_DRV) -shared -o $(OUT_TMP_DRV) $(LDFLAGS_CLI_DRV) style: @echo "Formatting source code with astyle..." @@ -87,10 +92,9 @@ clean: -rm -rf $(OUT_DOC) -find . -type f -name '*.orig' -delete +commit_hash: + @echo "Updating commit hash..." + @bash -c 'echo -e "#ifndef COMMIT_HASH_H\n#define COMMIT_HASH_H\nconst char COMMIT_HASH[] = \"`git log --pretty=format:'%H' -n 1`\";\n#endif // COMMIT_HASH_H" > commit_hash.h' + .cpp.o: $(PATH_COMPILER) $(CFLAGS) -c $< -o $@ - -$(OUT_TMP_DRV): - @echo "Linking driver library..." - @mkdir -p ../lib - $(PATH_COMPILER) $(CFLAGS) $(OBJECTS_DRV) -shared -o $(OUT_TMP_DRV) $(LDFLAGS_CLI_DRV) diff --git a/control/src/commit_hash.h b/control/src/commit_hash.h new file mode 100644 index 0000000..3db50b6 --- /dev/null +++ b/control/src/commit_hash.h @@ -0,0 +1,4 @@ +#ifndef COMMIT_HASH_H +#define COMMIT_HASH_H +const char COMMIT_HASH[] = "ae6920cdf9fed20780ed671c86150b00283c67b6"; +#endif // COMMIT_HASH_H diff --git a/control/src/drv/b15f.cpp b/control/src/drv/b15f.cpp index 7d9aabe..f0f9eb1 100644 --- a/control/src/drv/b15f.cpp +++ b/control/src/drv/b15f.cpp @@ -119,8 +119,8 @@ std::vector B15F::getBoardInfo(void) usart.receive(&len, 0, sizeof(len)); char str[len + 1]; - str[len] = '\0'; usart.receive(reinterpret_cast(&str[0]), 0, len); + str[len] = '\0'; info.push_back(std::string(str)); } @@ -686,4 +686,14 @@ void B15F::init() std::vector info = getBoardInfo(); std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl; + + // Überprüfe Version + std::string& avr_commit_hash = info[3]; + if(avr_commit_hash.compare(COMMIT_HASH)) + { + std::cout << PRE << "Unterschiedliche commit hashes: " << std::endl; + std::cout << std::string(PRE.length(), ' ') << "AVR: " << avr_commit_hash << std::endl; + std::cout << std::string(PRE.length(), ' ') << "Control: " << COMMIT_HASH << std::endl << std::endl; + abort("Versionen inkompatibel. Bitte Software aktualisieren!"); + } } diff --git a/control/src/drv/b15f.h b/control/src/drv/b15f.h index 53d649e..5fea77e 100644 --- a/control/src/drv/b15f.h +++ b/control/src/drv/b15f.h @@ -15,6 +15,7 @@ #include #include +#include "../commit_hash.h" #include "requests.h" #include "usart.h" #include "driverexception.h" diff --git a/docs/html/annotated.html b/docs/html/annotated.html index 017eeb2..128f191 100644 --- a/docs/html/annotated.html +++ b/docs/html/annotated.html @@ -85,7 +85,7 @@ $(function() { diff --git a/docs/html/b15f_8cpp_source.html b/docs/html/b15f_8cpp_source.html index 6fe33f8..7ed6251 100644 --- a/docs/html/b15f_8cpp_source.html +++ b/docs/html/b15f_8cpp_source.html @@ -70,7 +70,7 @@ $(function() {
b15f.cpp
-
1 #include "b15f.h"
2 
3 B15F *B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 
7 /*************************************
8  * Grundfunktionen des B15F Treibers *
9  *************************************/
10 
12 {
13  if (!instance)
14  instance = new B15F();
15 
16  return *instance;
17 }
18 
19 void B15F::reconnect()
20 {
21  uint8_t tries = RECONNECT_TRIES;
22  while (tries--)
23  {
25  discard();
26 
27  try
28  {
30  return; // no exceptionm means success
31  }
32  catch(DriverException& eDE)
33  {
34  // discard exception
35  }
36  }
37 
38  abort("Verbindung kann nicht repariert werden");
39 }
40 
41 void B15F::discard(void)
42 {
43  try
44  {
45  uint8_t rq[] =
46  {
47  RQ_DISCARD
48  };
49 
50  usart.clearOutputBuffer();
51  for (uint8_t i = 0; i < 16; i++)
52  {
53  usart.transmit(&rq[0], 0, sizeof(rq)); // sende discard Befehl (verwerfe input)
54  delay_ms(4);
55  }
56  usart.clearInputBuffer();
57  }
58  catch (std::exception &ex)
59  {
60  abort(ex);
61  }
62 }
63 
65 {
66  // erzeuge zufälliges Byte
67  srand(time(NULL));
68  uint8_t dummy = rand() % 256;
69 
70  uint8_t rq[] =
71  {
72  RQ_TEST,
73  dummy
74  };
75  usart.transmit(&rq[0], 0, sizeof(rq));
76 
77  uint8_t aw[2];
78  usart.receive(&aw[0], 0, sizeof(aw));
79 
80  assertCode(aw[0], MSG_OK);
81  assertCode(aw[1], dummy);
82 }
83 
84 void B15F::testIntConv()
85 {
86  srand(time(NULL));
87  uint16_t dummy = rand() % (0xFFFF / 3);
88 
89  uint8_t rq[] =
90  {
91  RQ_INT_TEST,
92  static_cast<uint8_t >(dummy & 0xFF),
93  static_cast<uint8_t >(dummy >> 8)
94  };
95  usart.transmit(&rq[0], 0, sizeof(rq));
96 
97  uint16_t aw;
98  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
99 
100  assertCode(aw, dummy * 3);
101 }
102 
103 
104 std::vector<std::string> B15F::getBoardInfo(void)
105 {
106  std::vector<std::string> info;
107 
108  uint8_t rq[] =
109  {
110  RQ_INFO
111  };
112  usart.transmit(&rq[0], 0, sizeof(rq));
113 
114  uint8_t n;
115  usart.receive(&n, 0, sizeof(n));
116  while (n--)
117  {
118  uint8_t len;
119  usart.receive(&len, 0, sizeof(len));
120 
121  char str[len + 1];
122  str[len] = '\0';
123  usart.receive(reinterpret_cast<uint8_t *>(&str[0]), 0, len);
124 
125  info.push_back(std::string(str));
126  }
127 
128  uint8_t aw;
129  usart.receive(&aw, 0, sizeof(aw));
130  if (aw != MSG_OK)
131  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
132 
133  return info;
134 }
135 
136 void B15F::delay_ms(uint16_t ms)
137 {
138  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
139 }
140 
141 void B15F::delay_us(uint16_t us)
142 {
143  std::this_thread::sleep_for(std::chrono::microseconds(us));
144 }
145 
146 void B15F::reverse(uint8_t& b)
147 {
148  b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
149  b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
150  b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
151 }
152 
153 // https://stackoverflow.com/a/478960
154 std::string B15F::exec(std::string cmd)
155 {
156  std::array<char, 128> buffer;
157  std::string result;
158  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
159  if (!pipe)
160  {
161  throw std::runtime_error("popen() failed!");
162  }
163  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
164  {
165  result += buffer.data();
166  }
167  return result;
168 }
169 
170 void B15F::abort(std::string msg)
171 {
172  DriverException ex(msg);
173  abort(ex);
174 }
175 
176 void B15F::abort(std::exception &ex)
177 {
178  if (errorhandler)
179  errorhandler(ex);
180  else
181  {
182  std::cout << ex.what() << std::endl;
183  throw DriverException(ex.what());
184  }
185 }
186 
187 void B15F::setAbortHandler(errorhandler_t func)
188 {
189  errorhandler = func;
190 }
191 
192 /*************************************/
193 
194 
195 
196 /*************************
197  * Steuerbefehle für B15 *
198  *************************/
199 
201 {
202  uint8_t rq[] =
203  {
204  RQ_SELF_TEST
205  };
206 
207  assertRequestLength(rq, RQ_SELF_TEST);
208  usart.transmit(&rq[0], 0, sizeof(rq));
209 
210  uint8_t aw;
211  usart.receive(&aw, 0, sizeof(aw));
212  assertCode(aw, MSG_OK);
213 }
214 
215 void B15F::digitalWrite0(uint8_t port)
216 {
217  uint8_t rq[] =
218  {
219  RQ_DIGITAL_WRITE_0,
220  port
221  };
222 
223  assertRequestLength(rq, RQ_DIGITAL_WRITE_0);
224  usart.transmit(&rq[0], 0, sizeof(rq));
225 
226  uint8_t aw;
227  usart.receive(&aw, 0, sizeof(aw));
228  assertCode(aw, MSG_OK);
229 }
230 
231 void B15F::digitalWrite1(uint8_t port)
232 {
233  uint8_t rq[] =
234  {
235  RQ_DIGITAL_WRITE_1,
236  port
237  };
238 
239  assertRequestLength(rq, RQ_DIGITAL_WRITE_1);
240  usart.transmit(&rq[0], 0, sizeof(rq));
241 
242  uint8_t aw;
243  usart.receive(&aw, 0, sizeof(aw));
244  assertCode(aw, MSG_OK);
245 }
246 
247 uint8_t B15F::digitalRead0()
248 {
249  usart.clearInputBuffer();
250  uint8_t rq[] =
251  {
252  RQ_DIGITAL_READ_0
253  };
254 
255  assertRequestLength(rq, RQ_DIGITAL_READ_0);
256  usart.transmit(&rq[0], 0, sizeof(rq));
257 
258  uint8_t aw;
259  usart.receive(&aw, 0, sizeof(aw));
260  return aw;
261 }
262 
263 uint8_t B15F::digitalRead1()
264 {
265  usart.clearInputBuffer();
266  uint8_t rq[] =
267  {
268  RQ_DIGITAL_READ_1
269  };
270 
271  assertRequestLength(rq, RQ_DIGITAL_READ_1);
272  usart.transmit(&rq[0], 0, sizeof(rq));
273 
274  uint8_t aw;
275  usart.receive(&aw, 0, sizeof(aw));
276  return aw;
277 }
278 
279 uint8_t B15F::readDipSwitch()
280 {
281  usart.clearInputBuffer();
282  uint8_t rq[] =
283  {
284  RQ_READ_DIP_SWITCH
285  };
286 
287  assertRequestLength(rq, RQ_READ_DIP_SWITCH);
288  usart.transmit(&rq[0], 0, sizeof(rq));
289 
290  uint8_t aw;
291  usart.receive(&aw, 0, sizeof(aw));
292 
293  reverse(aw); // DIP Schalter muss invertiert werden!
294 
295  return aw;
296 }
297 
298 void B15F::analogWrite0(uint16_t value)
299 {
300  uint8_t rq[] =
301  {
302  RQ_ANALOG_WRITE_0,
303  static_cast<uint8_t >(value & 0xFF),
304  static_cast<uint8_t >(value >> 8)
305  };
306 
307  assertRequestLength(rq, RQ_ANALOG_WRITE_0);
308  usart.transmit(&rq[0], 0, sizeof(rq));
309 
310  uint8_t aw;
311  usart.receive(&aw, 0, sizeof(aw));
312  assertCode(aw, MSG_OK);
313 }
314 
315 void B15F::analogWrite1(uint16_t value)
316 {
317  uint8_t rq[] =
318  {
319  RQ_ANALOG_WRITE_1,
320  static_cast<uint8_t >(value & 0xFF),
321  static_cast<uint8_t >(value >> 8)
322  };
323 
324  assertRequestLength(rq, RQ_ANALOG_WRITE_1);
325  usart.transmit(&rq[0], 0, sizeof(rq));
326 
327  uint8_t aw;
328  usart.receive(&aw, 0, sizeof(aw));
329  assertCode(aw, MSG_OK);
330 }
331 
332 uint16_t B15F::analogRead(uint8_t channel)
333 {
334  usart.clearInputBuffer();
335  if (channel > 7)
336  abort("Bad ADC channel: " + std::to_string(channel));
337 
338  uint8_t rq[] =
339  {
340  RQ_ANALOG_READ,
341  channel
342  };
343 
344  assertRequestLength(rq, RQ_ANALOG_READ);
345  usart.transmit(&rq[0], 0, sizeof(rq));
346 
347  uint16_t aw;
348  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
349 
350  if (aw > 1023)
351  abort("Bad ADC data detected (1)");
352  return aw;
353 }
354 
355 void B15F::analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b,
356  uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
357 {
358  // prepare pointers
359  buffer_a += offset_a;
360  buffer_b += offset_b;
361 
362 
363  usart.clearInputBuffer();
364  uint8_t rq[] =
365  {
366  RQ_ADC_DAC_STROKE,
367  channel_a,
368  channel_b,
369  static_cast<uint8_t >(start & 0xFF),
370  static_cast<uint8_t >(start >> 8),
371  static_cast<uint8_t >(delta & 0xFF),
372  static_cast<uint8_t >(delta >> 8),
373  static_cast<uint8_t >(count & 0xFF),
374  static_cast<uint8_t >(count >> 8)
375  };
376 
377  assertRequestLength(rq, RQ_ADC_DAC_STROKE);
378  usart.transmit(&rq[0], 0, sizeof(rq));
379 
380  for (uint16_t i = 0; i < count; i++)
381  {
382  if (buffer_a)
383  {
384  usart.receive(reinterpret_cast<uint8_t *>(&buffer_a[i]), 0, 2);
385 
386  if (buffer_a[i] > 1023) // check for broken usart connection
387  abort("Bad ADC data detected (2)");
388  }
389  else
390  {
391  usart.drop(2);
392  }
393 
394  if (buffer_b)
395  {
396  usart.receive(reinterpret_cast<uint8_t *>(&buffer_b[i]), 0, 2);
397 
398  if (buffer_b[i] > 1023) // check for broken usart connection
399  abort("Bad ADC data detected (3)");
400  }
401  else
402  {
403  usart.drop(2);
404  }
405  }
406 
407  uint8_t aw;
408  usart.receive(&aw, 0, sizeof(aw));
409  assertCode(aw, MSG_OK);
410 }
411 
412 uint8_t B15F::pwmSetFrequency(uint32_t freq)
413 {
414  usart.clearInputBuffer();
415 
416  uint8_t rq[] =
417  {
418  RQ_PWM_SET_FREQ,
419  static_cast<uint8_t>((freq >> 0) & 0xFF),
420  static_cast<uint8_t>((freq >> 8) & 0xFF),
421  static_cast<uint8_t>((freq >> 16) & 0xFF),
422  static_cast<uint8_t>((freq >> 24) & 0xFF)
423  };
424 
425  assertRequestLength(rq, RQ_PWM_SET_FREQ);
426  usart.transmit(&rq[0], 0, sizeof(rq));
427 
428  uint8_t aw;
429  usart.receive(&aw, 0, sizeof(aw));
430  return aw;
431 }
432 
433 void B15F::pwmSetValue(uint8_t value)
434 {
435  usart.clearInputBuffer();
436 
437  uint8_t rq[] =
438  {
439  RQ_PWM_SET_VALUE,
440  value
441  };
442 
443  assertRequestLength(rq, RQ_PWM_SET_VALUE);
444  usart.transmit(&rq[0], 0, sizeof(rq));
445 
446  uint8_t aw;
447  usart.receive(&aw, 0, sizeof(aw));
448  assertCode(aw, MSG_OK);
449 }
450 
451 void B15F::setMem8(volatile uint8_t* adr, uint8_t val)
452 {
453  usart.clearInputBuffer();
454 
455  uint8_t rq[] =
456  {
457  RQ_SET_MEM_8,
458  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
459  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
460  val
461  };
462 
463  assertRequestLength(rq, RQ_SET_MEM_8);
464  usart.transmit(&rq[0], 0, sizeof(rq));
465 
466  uint8_t aw;
467  usart.receive(&aw, 0, sizeof(aw));
468  assertCode(aw, MSG_OK);
469 }
470 
471 uint8_t B15F::getMem8(volatile uint8_t* adr)
472 {
473  usart.clearInputBuffer();
474 
475  uint8_t rq[] =
476  {
477  RQ_GET_MEM_8,
478  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
479  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
480  };
481 
482  assertRequestLength(rq, RQ_GET_MEM_8);
483  usart.transmit(&rq[0], 0, sizeof(rq));
484 
485  uint8_t aw;
486  usart.receive(&aw, 0, sizeof(aw));
487  return aw;
488 }
489 
490 void B15F::setMem16(volatile uint16_t* adr, uint16_t val)
491 {
492  usart.clearInputBuffer();
493 
494  uint8_t rq[] =
495  {
496  RQ_SET_MEM_16,
497  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
498  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
499  static_cast<uint8_t >(val & 0xFF),
500  static_cast<uint8_t >(val >> 8)
501  };
502 
503  assertRequestLength(rq, RQ_SET_MEM_16);
504  usart.transmit(&rq[0], 0, sizeof(rq));
505 
506  uint16_t aw;
507  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
508  assertCode(aw, MSG_OK);
509 }
510 
511 uint16_t B15F::getMem16(volatile uint16_t* adr)
512 {
513  usart.clearInputBuffer();
514 
515  uint8_t rq[] =
516  {
517  RQ_GET_MEM_16,
518  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
519  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
520  };
521 
522  assertRequestLength(rq, RQ_GET_MEM_16);
523  usart.transmit(&rq[0], 0, sizeof(rq));
524 
525  uint16_t aw;
526  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
527  return aw;
528 }
529 
530 void B15F::setRegister(volatile uint8_t* adr, uint8_t val)
531 {
532  setMem8(adr, val);
533 }
534 
535 uint8_t B15F::getRegister(volatile uint8_t* adr)
536 {
537  return getMem8(adr);
538 }
539 
541 {
542  usart.clearInputBuffer();
543 
544  uint8_t rq[] =
545  {
546  RQ_COUNTER_OFFSET
547  };
548 
549  assertRequestLength(rq, RQ_COUNTER_OFFSET);
550  usart.transmit(&rq[0], 0, sizeof(rq));
551 
552  uint16_t aw;
553  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
554  return reinterpret_cast<uint16_t*>(aw);
555 }
556 
557 void B15F::setServoEnabled(void)
558 {
559  usart.clearInputBuffer();
560 
561  uint8_t rq[] =
562  {
563  RQ_SERVO_ENABLE
564  };
565 
566  assertRequestLength(rq, RQ_SERVO_ENABLE);
567  usart.transmit(&rq[0], 0, sizeof(rq));
568 
569  uint8_t aw;
570  usart.receive(&aw, 0, sizeof(aw));
571  assertCode(aw, MSG_OK);
572 }
573 
574 void B15F::setServoDisabled(void)
575 {
576  usart.clearInputBuffer();
577 
578  uint8_t rq[] =
579  {
580  RQ_SERVO_DISABLE
581  };
582 
583  assertRequestLength(rq, RQ_SERVO_DISABLE);
584  usart.transmit(&rq[0], 0, sizeof(rq));
585 
586  uint8_t aw;
587  usart.receive(&aw, 0, sizeof(aw));
588  assertCode(aw, MSG_OK);
589 }
590 
591 void B15F::setServoPosition(uint16_t pos)
592 {
593  if(pos > 19000)
594  throw DriverException("Impulslänge ist zu lang: " + std::to_string(pos));
595 
596  usart.clearInputBuffer();
597 
598  uint8_t rq[] =
599  {
600  RQ_SERVO_SET_POS,
601  static_cast<uint8_t >(pos & 0xFF),
602  static_cast<uint8_t >(pos >> 8)
603  };
604 
605  assertRequestLength(rq, RQ_SERVO_SET_POS);
606  usart.transmit(&rq[0], 0, sizeof(rq));
607 
608  uint8_t aw;
609  usart.receive(&aw, 0, sizeof(aw));
610  assertCode(aw, MSG_OK);
611 }
612 
613 /*************************/
614 
615 
616 /**********************
617  * Private Funktionen *
618  **********************/
619 
620 B15F::B15F()
621 {
622  init();
623 }
624 
625 
626 void B15F::init()
627 {
628 
629 #ifdef __arm__
630  // Raspberry Pi serial interface
631  std::string device = exec("bash -c 'ls /dev/ttyAMA* 2> /dev/null'");
632 #else
633  // normal PC serial interface
634  std::string device = exec("bash -c 'ls /dev/ttyUSB* 2> /dev/null'");
635 #endif
636 
637  while (device.find(' ') != std::string::npos || device.find('\n') != std::string::npos ||
638  device.find('\t') != std::string::npos)
639  device.pop_back();
640 
641  if (device.length() == 0)
642  abort("Adapter nicht gefunden");
643 
644  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
645 
646 
647  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
648  usart.setBaudrate(BAUDRATE);
649  usart.openDevice(device);
650  std::cout << "OK" << std::endl;
651 
652 
653  std::cout << PRE << "Teste Verbindung... " << std::flush;
654  int tries = 4;
655  while (--tries)
656  {
657  discard();
658 
659  try
660  {
661  testConnection();
662  }
663  catch(DriverException& eDE)
664  {
665  continue;
666  }
667 
668  try
669  {
670  testIntConv();
671  }
672  catch(DriverException& eDE)
673  {
674  continue;
675  }
676 
677  break;
678  }
679  if (!tries)
680  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
681 
682  std::cout << "OK" << std::endl;
683 
684 
685  // Gib board info aus
686  std::vector<std::string> info = getBoardInfo();
687  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")"
688  << std::endl;
689 }
+
1 #include "b15f.h"
2 
3 B15F *B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 
7 /*************************************
8  * Grundfunktionen des B15F Treibers *
9  *************************************/
10 
12 {
13  if (!instance)
14  instance = new B15F();
15 
16  return *instance;
17 }
18 
19 void B15F::reconnect()
20 {
21  uint8_t tries = RECONNECT_TRIES;
22  while (tries--)
23  {
25  discard();
26 
27  try
28  {
30  return; // no exceptionm means success
31  }
32  catch(DriverException& eDE)
33  {
34  // discard exception
35  }
36  }
37 
38  abort("Verbindung kann nicht repariert werden");
39 }
40 
41 void B15F::discard(void)
42 {
43  try
44  {
45  uint8_t rq[] =
46  {
47  RQ_DISCARD
48  };
49 
50  usart.clearOutputBuffer();
51  for (uint8_t i = 0; i < 16; i++)
52  {
53  usart.transmit(&rq[0], 0, sizeof(rq)); // sende discard Befehl (verwerfe input)
54  delay_ms(4);
55  }
56  usart.clearInputBuffer();
57  }
58  catch (std::exception &ex)
59  {
60  abort(ex);
61  }
62 }
63 
65 {
66  // erzeuge zufälliges Byte
67  srand(time(NULL));
68  uint8_t dummy = rand() % 256;
69 
70  uint8_t rq[] =
71  {
72  RQ_TEST,
73  dummy
74  };
75  usart.transmit(&rq[0], 0, sizeof(rq));
76 
77  uint8_t aw[2];
78  usart.receive(&aw[0], 0, sizeof(aw));
79 
80  assertCode(aw[0], MSG_OK);
81  assertCode(aw[1], dummy);
82 }
83 
84 void B15F::testIntConv()
85 {
86  srand(time(NULL));
87  uint16_t dummy = rand() % (0xFFFF / 3);
88 
89  uint8_t rq[] =
90  {
91  RQ_INT_TEST,
92  static_cast<uint8_t >(dummy & 0xFF),
93  static_cast<uint8_t >(dummy >> 8)
94  };
95  usart.transmit(&rq[0], 0, sizeof(rq));
96 
97  uint16_t aw;
98  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
99 
100  assertCode(aw, dummy * 3);
101 }
102 
103 
104 std::vector<std::string> B15F::getBoardInfo(void)
105 {
106  std::vector<std::string> info;
107 
108  uint8_t rq[] =
109  {
110  RQ_INFO
111  };
112  usart.transmit(&rq[0], 0, sizeof(rq));
113 
114  uint8_t n;
115  usart.receive(&n, 0, sizeof(n));
116  while (n--)
117  {
118  uint8_t len;
119  usart.receive(&len, 0, sizeof(len));
120 
121  char str[len + 1];
122  usart.receive(reinterpret_cast<uint8_t *>(&str[0]), 0, len);
123  str[len] = '\0';
124 
125  info.push_back(std::string(str));
126  }
127 
128  uint8_t aw;
129  usart.receive(&aw, 0, sizeof(aw));
130  if (aw != MSG_OK)
131  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
132 
133  return info;
134 }
135 
136 void B15F::delay_ms(uint16_t ms)
137 {
138  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
139 }
140 
141 void B15F::delay_us(uint16_t us)
142 {
143  std::this_thread::sleep_for(std::chrono::microseconds(us));
144 }
145 
146 void B15F::reverse(uint8_t& b)
147 {
148  b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
149  b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
150  b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
151 }
152 
153 // https://stackoverflow.com/a/478960
154 std::string B15F::exec(std::string cmd)
155 {
156  std::array<char, 128> buffer;
157  std::string result;
158  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
159  if (!pipe)
160  {
161  throw std::runtime_error("popen() failed!");
162  }
163  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
164  {
165  result += buffer.data();
166  }
167  return result;
168 }
169 
170 void B15F::abort(std::string msg)
171 {
172  DriverException ex(msg);
173  abort(ex);
174 }
175 
176 void B15F::abort(std::exception &ex)
177 {
178  if (errorhandler)
179  errorhandler(ex);
180  else
181  {
182  std::cout << ex.what() << std::endl;
183  throw DriverException(ex.what());
184  }
185 }
186 
187 void B15F::setAbortHandler(errorhandler_t func)
188 {
189  errorhandler = func;
190 }
191 
192 /*************************************/
193 
194 
195 
196 /*************************
197  * Steuerbefehle für B15 *
198  *************************/
199 
201 {
202  uint8_t rq[] =
203  {
204  RQ_SELF_TEST
205  };
206 
207  assertRequestLength(rq, RQ_SELF_TEST);
208  usart.transmit(&rq[0], 0, sizeof(rq));
209 
210  uint8_t aw;
211  usart.receive(&aw, 0, sizeof(aw));
212  assertCode(aw, MSG_OK);
213 }
214 
215 void B15F::digitalWrite0(uint8_t port)
216 {
217  uint8_t rq[] =
218  {
219  RQ_DIGITAL_WRITE_0,
220  port
221  };
222 
223  assertRequestLength(rq, RQ_DIGITAL_WRITE_0);
224  usart.transmit(&rq[0], 0, sizeof(rq));
225 
226  uint8_t aw;
227  usart.receive(&aw, 0, sizeof(aw));
228  assertCode(aw, MSG_OK);
229 }
230 
231 void B15F::digitalWrite1(uint8_t port)
232 {
233  uint8_t rq[] =
234  {
235  RQ_DIGITAL_WRITE_1,
236  port
237  };
238 
239  assertRequestLength(rq, RQ_DIGITAL_WRITE_1);
240  usart.transmit(&rq[0], 0, sizeof(rq));
241 
242  uint8_t aw;
243  usart.receive(&aw, 0, sizeof(aw));
244  assertCode(aw, MSG_OK);
245 }
246 
247 uint8_t B15F::digitalRead0()
248 {
249  usart.clearInputBuffer();
250  uint8_t rq[] =
251  {
252  RQ_DIGITAL_READ_0
253  };
254 
255  assertRequestLength(rq, RQ_DIGITAL_READ_0);
256  usart.transmit(&rq[0], 0, sizeof(rq));
257 
258  uint8_t aw;
259  usart.receive(&aw, 0, sizeof(aw));
260  return aw;
261 }
262 
263 uint8_t B15F::digitalRead1()
264 {
265  usart.clearInputBuffer();
266  uint8_t rq[] =
267  {
268  RQ_DIGITAL_READ_1
269  };
270 
271  assertRequestLength(rq, RQ_DIGITAL_READ_1);
272  usart.transmit(&rq[0], 0, sizeof(rq));
273 
274  uint8_t aw;
275  usart.receive(&aw, 0, sizeof(aw));
276  return aw;
277 }
278 
279 uint8_t B15F::readDipSwitch()
280 {
281  usart.clearInputBuffer();
282  uint8_t rq[] =
283  {
284  RQ_READ_DIP_SWITCH
285  };
286 
287  assertRequestLength(rq, RQ_READ_DIP_SWITCH);
288  usart.transmit(&rq[0], 0, sizeof(rq));
289 
290  uint8_t aw;
291  usart.receive(&aw, 0, sizeof(aw));
292 
293  reverse(aw); // DIP Schalter muss invertiert werden!
294 
295  return aw;
296 }
297 
298 void B15F::analogWrite0(uint16_t value)
299 {
300  uint8_t rq[] =
301  {
302  RQ_ANALOG_WRITE_0,
303  static_cast<uint8_t >(value & 0xFF),
304  static_cast<uint8_t >(value >> 8)
305  };
306 
307  assertRequestLength(rq, RQ_ANALOG_WRITE_0);
308  usart.transmit(&rq[0], 0, sizeof(rq));
309 
310  uint8_t aw;
311  usart.receive(&aw, 0, sizeof(aw));
312  assertCode(aw, MSG_OK);
313 }
314 
315 void B15F::analogWrite1(uint16_t value)
316 {
317  uint8_t rq[] =
318  {
319  RQ_ANALOG_WRITE_1,
320  static_cast<uint8_t >(value & 0xFF),
321  static_cast<uint8_t >(value >> 8)
322  };
323 
324  assertRequestLength(rq, RQ_ANALOG_WRITE_1);
325  usart.transmit(&rq[0], 0, sizeof(rq));
326 
327  uint8_t aw;
328  usart.receive(&aw, 0, sizeof(aw));
329  assertCode(aw, MSG_OK);
330 }
331 
332 uint16_t B15F::analogRead(uint8_t channel)
333 {
334  usart.clearInputBuffer();
335  if (channel > 7)
336  abort("Bad ADC channel: " + std::to_string(channel));
337 
338  uint8_t rq[] =
339  {
340  RQ_ANALOG_READ,
341  channel
342  };
343 
344  assertRequestLength(rq, RQ_ANALOG_READ);
345  usart.transmit(&rq[0], 0, sizeof(rq));
346 
347  uint16_t aw;
348  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
349 
350  if (aw > 1023)
351  abort("Bad ADC data detected (1)");
352  return aw;
353 }
354 
355 void B15F::analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b,
356  uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
357 {
358  // prepare pointers
359  buffer_a += offset_a;
360  buffer_b += offset_b;
361 
362 
363  usart.clearInputBuffer();
364  uint8_t rq[] =
365  {
366  RQ_ADC_DAC_STROKE,
367  channel_a,
368  channel_b,
369  static_cast<uint8_t >(start & 0xFF),
370  static_cast<uint8_t >(start >> 8),
371  static_cast<uint8_t >(delta & 0xFF),
372  static_cast<uint8_t >(delta >> 8),
373  static_cast<uint8_t >(count & 0xFF),
374  static_cast<uint8_t >(count >> 8)
375  };
376 
377  assertRequestLength(rq, RQ_ADC_DAC_STROKE);
378  usart.transmit(&rq[0], 0, sizeof(rq));
379 
380  for (uint16_t i = 0; i < count; i++)
381  {
382  if (buffer_a)
383  {
384  usart.receive(reinterpret_cast<uint8_t *>(&buffer_a[i]), 0, 2);
385 
386  if (buffer_a[i] > 1023) // check for broken usart connection
387  abort("Bad ADC data detected (2)");
388  }
389  else
390  {
391  usart.drop(2);
392  }
393 
394  if (buffer_b)
395  {
396  usart.receive(reinterpret_cast<uint8_t *>(&buffer_b[i]), 0, 2);
397 
398  if (buffer_b[i] > 1023) // check for broken usart connection
399  abort("Bad ADC data detected (3)");
400  }
401  else
402  {
403  usart.drop(2);
404  }
405  }
406 
407  uint8_t aw;
408  usart.receive(&aw, 0, sizeof(aw));
409  assertCode(aw, MSG_OK);
410 }
411 
412 uint8_t B15F::pwmSetFrequency(uint32_t freq)
413 {
414  usart.clearInputBuffer();
415 
416  uint8_t rq[] =
417  {
418  RQ_PWM_SET_FREQ,
419  static_cast<uint8_t>((freq >> 0) & 0xFF),
420  static_cast<uint8_t>((freq >> 8) & 0xFF),
421  static_cast<uint8_t>((freq >> 16) & 0xFF),
422  static_cast<uint8_t>((freq >> 24) & 0xFF)
423  };
424 
425  assertRequestLength(rq, RQ_PWM_SET_FREQ);
426  usart.transmit(&rq[0], 0, sizeof(rq));
427 
428  uint8_t aw;
429  usart.receive(&aw, 0, sizeof(aw));
430  return aw;
431 }
432 
433 void B15F::pwmSetValue(uint8_t value)
434 {
435  usart.clearInputBuffer();
436 
437  uint8_t rq[] =
438  {
439  RQ_PWM_SET_VALUE,
440  value
441  };
442 
443  assertRequestLength(rq, RQ_PWM_SET_VALUE);
444  usart.transmit(&rq[0], 0, sizeof(rq));
445 
446  uint8_t aw;
447  usart.receive(&aw, 0, sizeof(aw));
448  assertCode(aw, MSG_OK);
449 }
450 
451 void B15F::setMem8(volatile uint8_t* adr, uint8_t val)
452 {
453  usart.clearInputBuffer();
454 
455  uint8_t rq[] =
456  {
457  RQ_SET_MEM_8,
458  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
459  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
460  val
461  };
462 
463  assertRequestLength(rq, RQ_SET_MEM_8);
464  usart.transmit(&rq[0], 0, sizeof(rq));
465 
466  uint8_t aw;
467  usart.receive(&aw, 0, sizeof(aw));
468  assertCode(aw, MSG_OK);
469 }
470 
471 uint8_t B15F::getMem8(volatile uint8_t* adr)
472 {
473  usart.clearInputBuffer();
474 
475  uint8_t rq[] =
476  {
477  RQ_GET_MEM_8,
478  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
479  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
480  };
481 
482  assertRequestLength(rq, RQ_GET_MEM_8);
483  usart.transmit(&rq[0], 0, sizeof(rq));
484 
485  uint8_t aw;
486  usart.receive(&aw, 0, sizeof(aw));
487  return aw;
488 }
489 
490 void B15F::setMem16(volatile uint16_t* adr, uint16_t val)
491 {
492  usart.clearInputBuffer();
493 
494  uint8_t rq[] =
495  {
496  RQ_SET_MEM_16,
497  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
498  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
499  static_cast<uint8_t >(val & 0xFF),
500  static_cast<uint8_t >(val >> 8)
501  };
502 
503  assertRequestLength(rq, RQ_SET_MEM_16);
504  usart.transmit(&rq[0], 0, sizeof(rq));
505 
506  uint16_t aw;
507  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
508  assertCode(aw, MSG_OK);
509 }
510 
511 uint16_t B15F::getMem16(volatile uint16_t* adr)
512 {
513  usart.clearInputBuffer();
514 
515  uint8_t rq[] =
516  {
517  RQ_GET_MEM_16,
518  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
519  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
520  };
521 
522  assertRequestLength(rq, RQ_GET_MEM_16);
523  usart.transmit(&rq[0], 0, sizeof(rq));
524 
525  uint16_t aw;
526  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
527  return aw;
528 }
529 
530 void B15F::setRegister(volatile uint8_t* adr, uint8_t val)
531 {
532  setMem8(adr, val);
533 }
534 
535 uint8_t B15F::getRegister(volatile uint8_t* adr)
536 {
537  return getMem8(adr);
538 }
539 
541 {
542  usart.clearInputBuffer();
543 
544  uint8_t rq[] =
545  {
546  RQ_COUNTER_OFFSET
547  };
548 
549  assertRequestLength(rq, RQ_COUNTER_OFFSET);
550  usart.transmit(&rq[0], 0, sizeof(rq));
551 
552  uint16_t aw;
553  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
554  return reinterpret_cast<uint16_t*>(aw);
555 }
556 
557 void B15F::setServoEnabled(void)
558 {
559  usart.clearInputBuffer();
560 
561  uint8_t rq[] =
562  {
563  RQ_SERVO_ENABLE
564  };
565 
566  assertRequestLength(rq, RQ_SERVO_ENABLE);
567  usart.transmit(&rq[0], 0, sizeof(rq));
568 
569  uint8_t aw;
570  usart.receive(&aw, 0, sizeof(aw));
571  assertCode(aw, MSG_OK);
572 }
573 
574 void B15F::setServoDisabled(void)
575 {
576  usart.clearInputBuffer();
577 
578  uint8_t rq[] =
579  {
580  RQ_SERVO_DISABLE
581  };
582 
583  assertRequestLength(rq, RQ_SERVO_DISABLE);
584  usart.transmit(&rq[0], 0, sizeof(rq));
585 
586  uint8_t aw;
587  usart.receive(&aw, 0, sizeof(aw));
588  assertCode(aw, MSG_OK);
589 }
590 
591 void B15F::setServoPosition(uint16_t pos)
592 {
593  if(pos > 19000)
594  throw DriverException("Impulslänge ist zu lang: " + std::to_string(pos));
595 
596  usart.clearInputBuffer();
597 
598  uint8_t rq[] =
599  {
600  RQ_SERVO_SET_POS,
601  static_cast<uint8_t >(pos & 0xFF),
602  static_cast<uint8_t >(pos >> 8)
603  };
604 
605  assertRequestLength(rq, RQ_SERVO_SET_POS);
606  usart.transmit(&rq[0], 0, sizeof(rq));
607 
608  uint8_t aw;
609  usart.receive(&aw, 0, sizeof(aw));
610  assertCode(aw, MSG_OK);
611 }
612 
613 /*************************/
614 
615 
616 /**********************
617  * Private Funktionen *
618  **********************/
619 
620 B15F::B15F()
621 {
622  init();
623 }
624 
625 
626 void B15F::init()
627 {
628 
629 #ifdef __arm__
630  // Raspberry Pi serial interface
631  std::string device = exec("bash -c 'ls /dev/ttyAMA* 2> /dev/null'");
632 #else
633  // normal PC serial interface
634  std::string device = exec("bash -c 'ls /dev/ttyUSB* 2> /dev/null'");
635 #endif
636 
637  while (device.find(' ') != std::string::npos || device.find('\n') != std::string::npos ||
638  device.find('\t') != std::string::npos)
639  device.pop_back();
640 
641  if (device.length() == 0)
642  abort("Adapter nicht gefunden");
643 
644  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
645 
646 
647  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
648  usart.setBaudrate(BAUDRATE);
649  usart.openDevice(device);
650  std::cout << "OK" << std::endl;
651 
652 
653  std::cout << PRE << "Teste Verbindung... " << std::flush;
654  int tries = 4;
655  while (--tries)
656  {
657  discard();
658 
659  try
660  {
661  testConnection();
662  }
663  catch(DriverException& eDE)
664  {
665  continue;
666  }
667 
668  try
669  {
670  testIntConv();
671  }
672  catch(DriverException& eDE)
673  {
674  continue;
675  }
676 
677  break;
678  }
679  if (!tries)
680  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
681 
682  std::cout << "OK" << std::endl;
683 
684 
685  // Gib board info aus
686  std::vector<std::string> info = getBoardInfo();
687  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")"
688  << std::endl;
689 
690  // Überprüfe Version
691  std::string& avr_commit_hash = info[3];
692  if(avr_commit_hash.compare(COMMIT_HASH))
693  {
694  std::cout << PRE << "Unterschiedliche commit hashes: " << std::endl;
695  std::cout << std::string(PRE.length(), ' ') << "AVR: " << avr_commit_hash << std::endl;
696  std::cout << std::string(PRE.length(), ' ') << "Control: " << COMMIT_HASH << std::endl << std::endl;
697  abort("Versionen inkompatibel. Bitte Software aktualisieren!");
698  }
699 }
void testIntConv(void)
Definition: b15f.cpp:83
void pwmSetValue(uint8_t value)
Definition: b15f.cpp:431
static std::string exec(std::string cmd)
Definition: b15f.cpp:153
@@ -89,7 +89,7 @@ $(function() {
void delay_ms(uint16_t ms)
Definition: b15f.cpp:135
void testConnection(void)
Definition: b15f.cpp:63
static B15F & getInstance(void)
Definition: b15f.cpp:10
-
Definition: b15f.h:37
+
Definition: b15f.h:38
void transmit(uint8_t *buffer, uint16_t offset, uint8_t len)
Definition: usart.cpp:75
static void abort(std::string msg)
Definition: b15f.cpp:169
void receive(uint8_t *buffer, uint16_t offset, uint8_t len)
Definition: usart.cpp:84
@@ -99,29 +99,29 @@ $(function() {
void clearOutputBuffer(void)
Definition: usart.cpp:61
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:330
void activateSelfTestMode(void)
Definition: b15f.cpp:198
-
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:309
+
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:310
void reverse(uint8_t &b)
Definition: b15f.cpp:145
void setBaudrate(uint32_t baudrate)
Definition: usart.cpp:131
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:103
-
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:312
+
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:313
void discard(void)
Definition: b15f.cpp:40
void setRegister(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:528
-
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:310
+
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:311
void openDevice(std::string device)
Definition: usart.cpp:9
uint8_t digitalRead1(void)
Definition: b15f.cpp:261
void reconnect(void)
Definition: b15f.cpp:18
-
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:315
+
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:316
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:186
void drop(uint8_t len)
Definition: usart.cpp:114
void digitalWrite1(uint8_t)
Definition: b15f.cpp:229
void setServoEnabled(void)
Definition: b15f.cpp:555
-
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:314
+
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:315
void setMem8(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:449
void setServoDisabled(void)
Definition: b15f.cpp:572
diff --git a/docs/html/b15f_8h_source.html b/docs/html/b15f_8h_source.html index eea1c74..03bc935 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 
18 #include "requests.h"
19 #include "usart.h"
20 #include "driverexception.h"
21 #include "timeoutexception.h"
22 
23 // wichtig für die Register-Zugriffe
24 #define _AVR_IO_H_ 1 // Erzwinge die Inklusion
25 #include "/usr/lib/avr/include/avr/sfr_defs.h"
26 #include "/usr/lib/avr/include/avr/iom1284p.h"
27 
28 typedef std::function<void(std::exception&)> errorhandler_t;
29 
30 // Wrapper für Codeposition-Ersetzung
31 #define assertCode(code, expectation) assertCodeFunc(code, expectation, &__FUNCTION__[0], &__FILE__[0], __LINE__)
32 #define assertRequestLength(rq, rq_num) assertRequestLengthFunc(rq, rq_num,& __FUNCTION__[0], &__FILE__[0], __LINE__)
33 
34 
37 class B15F
38 {
39 public:
40 
41  /*************************************
42  * Grundfunktionen des B15F Treibers *
43  *************************************/
44 
49  static B15F& getInstance(void);
50 
55  void reconnect(void);
56 
61  void discard(void);
62 
67  void testConnection(void);
68 
73  void testIntConv(void);
74 
79  std::vector<std::string> getBoardInfo(void);
80 
85  void delay_ms(uint16_t ms);
86 
91  void delay_us(uint16_t us);
92 
98  void reverse(uint8_t& b);
99 
104  static std::string exec(std::string cmd);
105 
110  static void abort(std::string msg);
111 
116  static void abort(std::exception& ex);
117 
122  static void setAbortHandler(errorhandler_t func);
123 
124  /*************************************/
125 
126 
127 
128  /*************************
129  * Steuerbefehle für B15 *
130  *************************/
131 
137  void activateSelfTestMode(void);
138 
144  void digitalWrite0(uint8_t);
145 
151  void digitalWrite1(uint8_t);
152 
158  uint8_t digitalRead0(void);
159 
165  uint8_t digitalRead1(void);
166 
172  uint8_t readDipSwitch(void);
173 
179  void analogWrite0(uint16_t port);
180 
186  void analogWrite1(uint16_t port);
187 
193  uint16_t analogRead(uint8_t channel);
194 
210  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);
211 
221  uint8_t pwmSetFrequency(uint32_t freq);
222 
228  void pwmSetValue(uint8_t value);
229 
238  void setMem8(volatile uint8_t* adr, uint8_t val);
239 
246  uint8_t getMem8(volatile uint8_t* adr);
247 
256  void setMem16(volatile uint16_t* adr, uint16_t val);
257 
264  uint16_t getMem16(volatile uint16_t* adr);
265 
273  void setRegister(volatile uint8_t* adr, uint8_t val);
274 
280  uint8_t getRegister(volatile uint8_t* adr);
281 
286  uint16_t* getInterruptCounterOffset(void);
287 
292  void setServoEnabled(void);
293 
298  void setServoDisabled(void);
299 
305  void setServoPosition(uint16_t pos);
306 
307  /*************************/
308 
309 
310  // CONSTANTS
311  const std::string PRE = "[B15F] ";
312  constexpr static uint8_t MSG_OK = 0xFF;
313  constexpr static uint8_t MSG_FAIL = 0xFE;
314  constexpr static uint16_t RECONNECT_TIMEOUT = 64;
315  constexpr static uint16_t WDT_TIMEOUT = 15;
316  constexpr static uint8_t RECONNECT_TRIES = 3;
317  constexpr static uint32_t BAUDRATE = 57600;
318 
319 private:
320 
324  B15F(void);
325 
330  void init(void);
331 
336  template<typename CodeType, typename ExpectationType>
337  void assertCodeFunc(CodeType& code, ExpectationType expectation, const char* func, const char* file, int line) const
338  {
339  if(code != static_cast<CodeType>(expectation))
340  throw DriverException("Ungültige Antwort erhalten: " + std::to_string((int) code) + " (erwartet: " + std::to_string((int) expectation) + ") in " + std::string(func) + ": " + std::string(file) + "#" + std::to_string(line));
341  }
342 
347  template<size_t RequestLength>
348  void assertRequestLengthFunc(uint8_t (&)[RequestLength], uint8_t rq_num, const char* func, const char* file, int line)
349  {
350  if(RequestLength != rq_len[rq_num])
351  throw DriverException("Ungültige Request Länge: " + std::to_string(RequestLength) + " (erwartet: " + std::to_string(rq_len[rq_num]) + ") in " + std::string(func) + ": " + std::string(file) + "#" + std::to_string(line));
352  }
353 
354  USART usart;
355  static B15F* instance;
356  static errorhandler_t errorhandler;
357 };
358 
359 #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 
18 #include "../commit_hash.h"
19 #include "requests.h"
20 #include "usart.h"
21 #include "driverexception.h"
22 #include "timeoutexception.h"
23 
24 // wichtig für die Register-Zugriffe
25 #define _AVR_IO_H_ 1 // Erzwinge die Inklusion
26 #include "/usr/lib/avr/include/avr/sfr_defs.h"
27 #include "/usr/lib/avr/include/avr/iom1284p.h"
28 
29 typedef std::function<void(std::exception&)> errorhandler_t;
30 
31 // Wrapper für Codeposition-Ersetzung
32 #define assertCode(code, expectation) assertCodeFunc(code, expectation, &__FUNCTION__[0], &__FILE__[0], __LINE__)
33 #define assertRequestLength(rq, rq_num) assertRequestLengthFunc(rq, rq_num,& __FUNCTION__[0], &__FILE__[0], __LINE__)
34 
35 
38 class B15F
39 {
40 public:
41 
42  /*************************************
43  * Grundfunktionen des B15F Treibers *
44  *************************************/
45 
50  static B15F& getInstance(void);
51 
56  void reconnect(void);
57 
62  void discard(void);
63 
68  void testConnection(void);
69 
74  void testIntConv(void);
75 
80  std::vector<std::string> getBoardInfo(void);
81 
86  void delay_ms(uint16_t ms);
87 
92  void delay_us(uint16_t us);
93 
99  void reverse(uint8_t& b);
100 
105  static std::string exec(std::string cmd);
106 
111  static void abort(std::string msg);
112 
117  static void abort(std::exception& ex);
118 
123  static void setAbortHandler(errorhandler_t func);
124 
125  /*************************************/
126 
127 
128 
129  /*************************
130  * Steuerbefehle für B15 *
131  *************************/
132 
138  void activateSelfTestMode(void);
139 
145  void digitalWrite0(uint8_t);
146 
152  void digitalWrite1(uint8_t);
153 
159  uint8_t digitalRead0(void);
160 
166  uint8_t digitalRead1(void);
167 
173  uint8_t readDipSwitch(void);
174 
180  void analogWrite0(uint16_t port);
181 
187  void analogWrite1(uint16_t port);
188 
194  uint16_t analogRead(uint8_t channel);
195 
211  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);
212 
222  uint8_t pwmSetFrequency(uint32_t freq);
223 
229  void pwmSetValue(uint8_t value);
230 
239  void setMem8(volatile uint8_t* adr, uint8_t val);
240 
247  uint8_t getMem8(volatile uint8_t* adr);
248 
257  void setMem16(volatile uint16_t* adr, uint16_t val);
258 
265  uint16_t getMem16(volatile uint16_t* adr);
266 
274  void setRegister(volatile uint8_t* adr, uint8_t val);
275 
281  uint8_t getRegister(volatile uint8_t* adr);
282 
287  uint16_t* getInterruptCounterOffset(void);
288 
293  void setServoEnabled(void);
294 
299  void setServoDisabled(void);
300 
306  void setServoPosition(uint16_t pos);
307 
308  /*************************/
309 
310 
311  // CONSTANTS
312  const std::string PRE = "[B15F] ";
313  constexpr static uint8_t MSG_OK = 0xFF;
314  constexpr static uint8_t MSG_FAIL = 0xFE;
315  constexpr static uint16_t RECONNECT_TIMEOUT = 64;
316  constexpr static uint16_t WDT_TIMEOUT = 15;
317  constexpr static uint8_t RECONNECT_TRIES = 3;
318  constexpr static uint32_t BAUDRATE = 57600;
319 
320 private:
321 
325  B15F(void);
326 
331  void init(void);
332 
337  template<typename CodeType, typename ExpectationType>
338  void assertCodeFunc(CodeType& code, ExpectationType expectation, const char* func, const char* file, int line) const
339  {
340  if(code != static_cast<CodeType>(expectation))
341  throw DriverException("Ungültige Antwort erhalten: " + std::to_string((int) code) + " (erwartet: " + std::to_string((int) expectation) + ") in " + std::string(func) + ": " + std::string(file) + "#" + std::to_string(line));
342  }
343 
348  template<size_t RequestLength>
349  void assertRequestLengthFunc(uint8_t (&)[RequestLength], uint8_t rq_num, const char* func, const char* file, int line)
350  {
351  if(RequestLength != rq_len[rq_num])
352  throw DriverException("Ungültige Request Länge: " + std::to_string(RequestLength) + " (erwartet: " + std::to_string(rq_len[rq_num]) + ") in " + std::string(func) + ": " + std::string(file) + "#" + std::to_string(line));
353  }
354 
355  USART usart;
356  static B15F* instance;
357  static errorhandler_t errorhandler;
358 };
359 
360 #endif // B15F_H
void testIntConv(void)
Definition: b15f.cpp:83
void pwmSetValue(uint8_t value)
Definition: b15f.cpp:431
static std::string exec(std::string cmd)
Definition: b15f.cpp:153
-
constexpr static uint8_t MSG_FAIL
Value to reject a received command.
Definition: b15f.h:311
+
constexpr static uint8_t MSG_FAIL
Value to reject a received command.
Definition: b15f.h:312
void analogWrite0(uint16_t port)
Definition: b15f.cpp:296
void setServoPosition(uint16_t pos)
Definition: b15f.cpp:589
void analogWrite1(uint16_t port)
Definition: b15f.cpp:313
@@ -90,34 +90,34 @@ $(function() {
void delay_ms(uint16_t ms)
Definition: b15f.cpp:135
void testConnection(void)
Definition: b15f.cpp:63
static B15F & getInstance(void)
Definition: b15f.cpp:10
-
Definition: b15f.h:37
+
Definition: b15f.h:38
static void abort(std::string msg)
Definition: b15f.cpp:169
uint16_t * getInterruptCounterOffset(void)
Definition: b15f.cpp:538
Definition: usart.h:16
void setMem16(volatile uint16_t *adr, uint16_t val)
Definition: b15f.cpp:488
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:330
void activateSelfTestMode(void)
Definition: b15f.cpp:198
-
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:309
+
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:310
void reverse(uint8_t &b)
Definition: b15f.cpp:145
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:103
-
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:312
+
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:313
void discard(void)
Definition: b15f.cpp:40
void setRegister(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:528
-
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:310
+
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:311
uint8_t digitalRead1(void)
Definition: b15f.cpp:261
-
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:313
+
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:314
void reconnect(void)
Definition: b15f.cpp:18
-
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:315
+
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:316
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:186
void digitalWrite1(uint8_t)
Definition: b15f.cpp:229
void setServoEnabled(void)
Definition: b15f.cpp:555
-
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:314
+
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:315
void setMem8(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:449
void setServoDisabled(void)
Definition: b15f.cpp:572
diff --git a/docs/html/classB15F-members.html b/docs/html/classB15F-members.html index 79a8d50..7b34620 100644 --- a/docs/html/classB15F-members.html +++ b/docs/html/classB15F-members.html @@ -114,7 +114,7 @@ $(function() { diff --git a/docs/html/classB15F.html b/docs/html/classB15F.html index 56a856e..d580ea4 100644 --- a/docs/html/classB15F.html +++ b/docs/html/classB15F.html @@ -188,7 +188,7 @@ constexpr static uint32_t 

Detailed Description

main driver class

-

Definition at line 37 of file b15f.h.

+

Definition at line 38 of file b15f.h.

Member Function Documentation

◆ abort() [1/2]

@@ -1309,7 +1309,7 @@ constexpr static uint32_t  diff --git a/docs/html/classDot-members.html b/docs/html/classDot-members.html index fca0216..78929ea 100644 --- a/docs/html/classDot-members.html +++ b/docs/html/classDot-members.html @@ -76,7 +76,7 @@ $(function() { diff --git a/docs/html/classDot.html b/docs/html/classDot.html index 7be4ec3..bdb8a5d 100644 --- a/docs/html/classDot.html +++ b/docs/html/classDot.html @@ -196,7 +196,7 @@ Public Member Functions diff --git a/docs/html/classDriverException-members.html b/docs/html/classDriverException-members.html index bba03b8..ec8441a 100644 --- a/docs/html/classDriverException-members.html +++ b/docs/html/classDriverException-members.html @@ -77,7 +77,7 @@ $(function() { diff --git a/docs/html/classDriverException.html b/docs/html/classDriverException.html index 6a4fede..f383597 100644 --- a/docs/html/classDriverException.html +++ b/docs/html/classDriverException.html @@ -109,7 +109,7 @@ std::string msg_< diff --git a/docs/html/classPlottyFile-members.html b/docs/html/classPlottyFile-members.html index 0e9a3f4..c8d4758 100644 --- a/docs/html/classPlottyFile-members.html +++ b/docs/html/classPlottyFile-members.html @@ -100,7 +100,7 @@ $(function() { diff --git a/docs/html/classPlottyFile.html b/docs/html/classPlottyFile.html index d0e67ea..9b57520 100644 --- a/docs/html/classPlottyFile.html +++ b/docs/html/classPlottyFile.html @@ -811,7 +811,7 @@ Public Member Functions diff --git a/docs/html/classTimeoutException-members.html b/docs/html/classTimeoutException-members.html index 1843817..305801a 100644 --- a/docs/html/classTimeoutException-members.html +++ b/docs/html/classTimeoutException-members.html @@ -77,7 +77,7 @@ $(function() { diff --git a/docs/html/classTimeoutException.html b/docs/html/classTimeoutException.html index 571bb8c..5c71dbc 100644 --- a/docs/html/classTimeoutException.html +++ b/docs/html/classTimeoutException.html @@ -239,7 +239,7 @@ std::string  diff --git a/docs/html/classUSART-members.html b/docs/html/classUSART-members.html index 5664e4b..318693a 100644 --- a/docs/html/classUSART-members.html +++ b/docs/html/classUSART-members.html @@ -86,7 +86,7 @@ $(function() { diff --git a/docs/html/classUSART.html b/docs/html/classUSART.html index e2e827e..a42fbba 100644 --- a/docs/html/classUSART.html +++ b/docs/html/classUSART.html @@ -523,7 +523,7 @@ Public Member Functions diff --git a/docs/html/classUSARTException-members.html b/docs/html/classUSARTException-members.html index 942feb6..6dd5d3a 100644 --- a/docs/html/classUSARTException-members.html +++ b/docs/html/classUSARTException-members.html @@ -77,7 +77,7 @@ $(function() { diff --git a/docs/html/classUSARTException.html b/docs/html/classUSARTException.html index 482b8fc..484ffb2 100644 --- a/docs/html/classUSARTException.html +++ b/docs/html/classUSARTException.html @@ -239,7 +239,7 @@ std::string  diff --git a/docs/html/classView-members.html b/docs/html/classView-members.html index 04d43af..70d0099 100644 --- a/docs/html/classView-members.html +++ b/docs/html/classView-members.html @@ -89,7 +89,7 @@ $(function() { diff --git a/docs/html/classView.html b/docs/html/classView.html index 4d2c87f..f39cf99 100644 --- a/docs/html/classView.html +++ b/docs/html/classView.html @@ -157,7 +157,7 @@ constexpr static int KEY_E diff --git a/docs/html/classViewInfo-members.html b/docs/html/classViewInfo-members.html index b7c6952..f2b4578 100644 --- a/docs/html/classViewInfo-members.html +++ b/docs/html/classViewInfo-members.html @@ -99,7 +99,7 @@ $(function() { diff --git a/docs/html/classViewInfo.html b/docs/html/classViewInfo.html index 2459ec8..cb495a3 100644 --- a/docs/html/classViewInfo.html +++ b/docs/html/classViewInfo.html @@ -185,7 +185,7 @@ static std::vector< std::string >  diff --git a/docs/html/classViewMonitor-members.html b/docs/html/classViewMonitor-members.html index 65370ff..2b7b8af 100644 --- a/docs/html/classViewMonitor-members.html +++ b/docs/html/classViewMonitor-members.html @@ -103,7 +103,7 @@ $(function() { diff --git a/docs/html/classViewMonitor.html b/docs/html/classViewMonitor.html index 2e53d43..4f68636 100644 --- a/docs/html/classViewMonitor.html +++ b/docs/html/classViewMonitor.html @@ -197,7 +197,7 @@ constexpr static int KEY_E diff --git a/docs/html/classViewPromt-members.html b/docs/html/classViewPromt-members.html index e01d2aa..901e5ce 100644 --- a/docs/html/classViewPromt-members.html +++ b/docs/html/classViewPromt-members.html @@ -105,7 +105,7 @@ $(function() { diff --git a/docs/html/classViewPromt.html b/docs/html/classViewPromt.html index 9fdbd62..0d9f3fc 100644 --- a/docs/html/classViewPromt.html +++ b/docs/html/classViewPromt.html @@ -205,7 +205,7 @@ static std::vector< std::string >  diff --git a/docs/html/classViewSelection-members.html b/docs/html/classViewSelection-members.html index 9800ab4..81f4568 100644 --- a/docs/html/classViewSelection-members.html +++ b/docs/html/classViewSelection-members.html @@ -94,7 +94,7 @@ $(function() { diff --git a/docs/html/classViewSelection.html b/docs/html/classViewSelection.html index e415859..16024cf 100644 --- a/docs/html/classViewSelection.html +++ b/docs/html/classViewSelection.html @@ -172,7 +172,7 @@ static std::vector< std::string >  diff --git a/docs/html/classes.html b/docs/html/classes.html index d92d5c8..6dab3a0 100644 --- a/docs/html/classes.html +++ b/docs/html/classes.html @@ -105,7 +105,7 @@ $(function() { diff --git a/docs/html/cli_8cpp_source.html b/docs/html/cli_8cpp_source.html index 39bb28e..9cc692d 100644 --- a/docs/html/cli_8cpp_source.html +++ b/docs/html/cli_8cpp_source.html @@ -72,7 +72,7 @@ $(function() {
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:186
diff --git a/docs/html/commit__hash_8h_source.html b/docs/html/commit__hash_8h_source.html new file mode 100644 index 0000000..aba4fe5 --- /dev/null +++ b/docs/html/commit__hash_8h_source.html @@ -0,0 +1,77 @@ + + + + + + + +B15F: commit_hash.h Source File + + + + + + + + + +
+
+ + + + + + +
+
B15F +
+
Board 15 Famulus Edition
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
commit_hash.h
+
+
+
1 #ifndef COMMIT_HASH_H
2 #define COMMIT_HASH_H
3 const char COMMIT_HASH[] = "ae6920cdf9fed20780ed671c86150b00283c67b6";
4 #endif // COMMIT_HASH_H
+ + + + diff --git a/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html b/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html index e5adedc..1151164 100644 --- a/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html +++ b/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html @@ -73,7 +73,7 @@ $(function() { diff --git a/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html b/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html index 97b1c33..d410b0a 100644 --- a/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html +++ b/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html @@ -73,7 +73,7 @@ $(function() { diff --git a/docs/html/dot_8cpp_source.html b/docs/html/dot_8cpp_source.html index 2edbd0d..fa948b6 100644 --- a/docs/html/dot_8cpp_source.html +++ b/docs/html/dot_8cpp_source.html @@ -77,7 +77,7 @@ $(function() {
Dot(uint16_t x, uint16_t y, uint8_t curve)
Definition: dot.cpp:3
diff --git a/docs/html/dot_8h_source.html b/docs/html/dot_8h_source.html index 8e0ddf8..4758bd5 100644 --- a/docs/html/dot_8h_source.html +++ b/docs/html/dot_8h_source.html @@ -78,7 +78,7 @@ $(function() {
Dot(uint16_t x, uint16_t y, uint8_t curve)
Definition: dot.cpp:3
diff --git a/docs/html/driverexception_8h_source.html b/docs/html/driverexception_8h_source.html index d409a92..b20aba4 100644 --- a/docs/html/driverexception_8h_source.html +++ b/docs/html/driverexception_8h_source.html @@ -74,7 +74,7 @@ $(function() { diff --git a/docs/html/files.html b/docs/html/files.html index d71382d..3e3e863 100644 --- a/docs/html/files.html +++ b/docs/html/files.html @@ -95,12 +95,13 @@ $(function() {  view_selection.cpp  view_selection.h  cli.cpp + commit_hash.h diff --git a/docs/html/functions.html b/docs/html/functions.html index 4f26cec..45ecb29 100644 --- a/docs/html/functions.html +++ b/docs/html/functions.html @@ -407,7 +407,7 @@ $(function() { diff --git a/docs/html/functions_func.html b/docs/html/functions_func.html index 28f4c88..b1753f7 100644 --- a/docs/html/functions_func.html +++ b/docs/html/functions_func.html @@ -374,7 +374,7 @@ $(function() { diff --git a/docs/html/functions_vars.html b/docs/html/functions_vars.html index e849599..2b14747 100644 --- a/docs/html/functions_vars.html +++ b/docs/html/functions_vars.html @@ -92,7 +92,7 @@ $(function() { diff --git a/docs/html/hierarchy.html b/docs/html/hierarchy.html index 9faa656..59ab9df 100644 --- a/docs/html/hierarchy.html +++ b/docs/html/hierarchy.html @@ -86,7 +86,7 @@ $(function() { diff --git a/docs/html/index.html b/docs/html/index.html index ae3b8d9..a7a3497 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -170,7 +170,7 @@ Dabei gehören Punkte mit dem gleichen Index für curve (uint8_ diff --git a/docs/html/plottyfile_8cpp_source.html b/docs/html/plottyfile_8cpp_source.html index a5959d1..ed97971 100644 --- a/docs/html/plottyfile_8cpp_source.html +++ b/docs/html/plottyfile_8cpp_source.html @@ -101,7 +101,7 @@ $(function() {
std::string getUnitX(void) const
Definition: plottyfile.cpp:105
diff --git a/docs/html/plottyfile_8h_source.html b/docs/html/plottyfile_8h_source.html index 5e4addf..2f93518 100644 --- a/docs/html/plottyfile_8h_source.html +++ b/docs/html/plottyfile_8h_source.html @@ -102,7 +102,7 @@ $(function() {
std::string getUnitX(void) const
Definition: plottyfile.cpp:105
diff --git a/docs/html/requests_8h_source.html b/docs/html/requests_8h_source.html index 4cf0758..ead1fd2 100644 --- a/docs/html/requests_8h_source.html +++ b/docs/html/requests_8h_source.html @@ -73,7 +73,7 @@ $(function() {
1 #ifndef REQUESTS_H
2 #define REQUESTS_H
3 
4 constexpr static uint8_t RQ_DISCARD = 0;
5 constexpr static uint8_t RQ_TEST = 1;
6 constexpr static uint8_t RQ_INFO = 2;
7 constexpr static uint8_t RQ_INT_TEST = 3;
8 constexpr static uint8_t RQ_SELF_TEST = 4;
9 constexpr static uint8_t RQ_DIGITAL_WRITE_0 = 5;
10 constexpr static uint8_t RQ_DIGITAL_WRITE_1 = 6;
11 constexpr static uint8_t RQ_DIGITAL_READ_0 = 7;
12 constexpr static uint8_t RQ_DIGITAL_READ_1 = 8;
13 constexpr static uint8_t RQ_READ_DIP_SWITCH = 9;
14 constexpr static uint8_t RQ_ANALOG_WRITE_0 = 10;
15 constexpr static uint8_t RQ_ANALOG_WRITE_1 = 11;
16 constexpr static uint8_t RQ_ANALOG_READ = 12;
17 constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
18 constexpr static uint8_t RQ_PWM_SET_FREQ = 14;
19 constexpr static uint8_t RQ_PWM_SET_VALUE = 15;
20 constexpr static uint8_t RQ_SET_MEM_8 = 16;
21 constexpr static uint8_t RQ_GET_MEM_8 = 17;
22 constexpr static uint8_t RQ_SET_MEM_16 = 18;
23 constexpr static uint8_t RQ_GET_MEM_16 = 19;
24 constexpr static uint8_t RQ_COUNTER_OFFSET = 20;
25 constexpr static uint8_t RQ_SERVO_ENABLE = 21;
26 constexpr static uint8_t RQ_SERVO_DISABLE = 22;
27 constexpr static uint8_t RQ_SERVO_SET_POS = 23;
28 
29 uint8_t const rq_len[] =
30 {
31  1 /* RQ_DISCARD */,
32  1 /* RQ_TEST */ + 1 /* test byte */,
33  1 /* RQ_INFO */,
34  1 /* RQ_INT_TEST */ + 1 /* test int high low */ + 1 /* test int high high */,
35  1 /* RQ_SELF_TEST */,
36  1 /* RQ_DIGITAL_WRITE_0 */ + 1 /* port value */,
37  1 /* RQ_DIGITAL_WRITE_1 */ + 1 /* port value */,
38  1 /* RQ_DIGITAL_READ_0 */,
39  1 /* RQ_DIGITAL_READ_1 */,
40  1 /* RQ_READ_DIP_SWITCH */,
41  1 /* RQ_ANALOG_WRITE_0 */ + 1 /* test int high low */ + 1 /* test int high high */,
42  1 /* RQ_ANALOG_WRITE_1 */ + 1 /* test int high low */ + 1 /* test int high high */,
43  1 /* RQ_ANALOG_READ */ + 1 /* adc channel */,
44  1 /* RQ_ADC_DAC_STROKE */ + 1 /* channel a */ + 1 /* channel b */ + 1 /* start low */ + 1 /* start high */ + 1 /* delta low */ + 1 /* delta high */ + 1 /* count low */ + 1 /* count high */,
45  1 /* RQ_PWM_SET_FREQ */ + 1 /* freq low low */ + 1 /* freq low high */ + 1 /* freq high low */ + 1 /* freq high high */,
46  1 /* RQ_PWM_SET_VALUE */ + 1 /* pwm value */,
47  1 /* RQ_SET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value (8-bit) */,
48  1 /* RQ_GET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */,
49  1 /* RQ_SET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value low */ + 1 /* memory value high */,
50  1 /* RQ_GET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */,
51  1 /* RQ_COUNTER_OFFSET */,
52  1 /* RQ_SERVO_ENABLE */,
53  1 /* RQ_SERVO_DISABLE */,
54  1 /* RQ_SERVO_SET_POS */ + 1 /* pulse length low */ + 1 /* pulse length high */,
55 };
56 
57 #endif // REQUESTS_H
diff --git a/docs/html/timeoutexception_8h_source.html b/docs/html/timeoutexception_8h_source.html index 8b358d5..d90f97b 100644 --- a/docs/html/timeoutexception_8h_source.html +++ b/docs/html/timeoutexception_8h_source.html @@ -79,7 +79,7 @@ $(function() {
TimeoutException(const std::string &message)
diff --git a/docs/html/ui_8cpp_source.html b/docs/html/ui_8cpp_source.html index 0109508..1fc2ffe 100644 --- a/docs/html/ui_8cpp_source.html +++ b/docs/html/ui_8cpp_source.html @@ -78,17 +78,17 @@ $(function() {
void delay_ms(uint16_t ms)
Definition: b15f.cpp:135
static B15F & getInstance(void)
Definition: b15f.cpp:10
-
Definition: b15f.h:37
+
Definition: b15f.h:38
void activateSelfTestMode(void)
Definition: b15f.cpp:198
void discard(void)
Definition: b15f.cpp:40
-
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:313
+
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:314
void reconnect(void)
Definition: b15f.cpp:18
void digitalWrite1(uint8_t)
Definition: b15f.cpp:229
diff --git a/docs/html/ui_8h_source.html b/docs/html/ui_8h_source.html index 890bb4d..71973f2 100644 --- a/docs/html/ui_8h_source.html +++ b/docs/html/ui_8h_source.html @@ -73,7 +73,7 @@ $(function() {
1 #ifndef UI_H
2 #define UI_H
3 
4 #include <vector>
5 #include "view_selection.h"
6 #include "view_info.h"
7 #include "view_monitor.h"
8 #include "view_promt.h"
9 
10 void show_main(int);
11 void input(int);
12 void view_back(int);
13 void finish(int);
14 void cleanup();
15 
16 void show_info(int);
17 void show_monitor(int);
18 void show_invalid_port_input(int);
19 void show_invalid_dac_input(int);
20 void write_digital_output0(int);
21 void write_digital_output1(int);
22 void write_analog_output0(int);
23 void write_analog_output1(int);
24 void show_digital_output0(int);
25 void show_digital_output1(int);
26 void show_analog_output0(int);
27 void show_analog_output1(int);
28 
29 // selftest group
30 void show_selftest_info(int);
31 void start_selftest(int);
32 void stop_selftest(int);
33 
34 
35 extern std::vector<View*> win_stack;
36 extern std::thread t_refresh;
37 
38 #endif // UI_H
diff --git a/docs/html/usart_8cpp_source.html b/docs/html/usart_8cpp_source.html index 1cc26b2..8d124eb 100644 --- a/docs/html/usart_8cpp_source.html +++ b/docs/html/usart_8cpp_source.html @@ -88,7 +88,7 @@ $(function() { diff --git a/docs/html/usart_8h_source.html b/docs/html/usart_8h_source.html index b847786..ec51fc3 100644 --- a/docs/html/usart_8h_source.html +++ b/docs/html/usart_8h_source.html @@ -88,7 +88,7 @@ $(function() {
void flushOutputBuffer(void)
Definition: usart.cpp:68
diff --git a/docs/html/usartexception_8h_source.html b/docs/html/usartexception_8h_source.html index bf102da..e8e2276 100644 --- a/docs/html/usartexception_8h_source.html +++ b/docs/html/usartexception_8h_source.html @@ -79,7 +79,7 @@ $(function() {
virtual ~USARTException()=default
diff --git a/docs/html/view_8cpp_source.html b/docs/html/view_8cpp_source.html index 14d6b2b..8fd19fd 100644 --- a/docs/html/view_8cpp_source.html +++ b/docs/html/view_8cpp_source.html @@ -74,7 +74,7 @@ $(function() {
static void abort(std::string msg)
Definition: b15f.cpp:169
diff --git a/docs/html/view_8h_source.html b/docs/html/view_8h_source.html index 1e5c0bb..8fd1c07 100644 --- a/docs/html/view_8h_source.html +++ b/docs/html/view_8h_source.html @@ -74,7 +74,7 @@ $(function() {
Definition: view.h:19
diff --git a/docs/html/view__info_8cpp_source.html b/docs/html/view__info_8cpp_source.html index 2d56171..e0693bd 100644 --- a/docs/html/view__info_8cpp_source.html +++ b/docs/html/view__info_8cpp_source.html @@ -73,7 +73,7 @@ $(function() {
1 #include "view_info.h"
2 
3 ViewInfo::ViewInfo()
4 {
5  calls.push_back(nullptr);
6 }
7 
8 void ViewInfo::setText(std::string text)
9 {
10  this->text = text;
11 }
12 
13 void ViewInfo::setLabelClose(std::string label)
14 {
15  this->label_close = label;
16 }
17 
18 void ViewInfo::setCall(call_t call)
19 {
20  calls[0] = call;
21 }
22 
23 void ViewInfo::draw()
24 {
25  int li = 0;
26  for(std::string line : str_split(text, "\n"))
27  mvwprintw(win, text_offset_y + li++, text_offset_x, "%s", line.c_str());
28 
29  close_offset_x = (width - label_close.length()) / 2;
30  close_offset_y = height - 2;
31 
32  wattron(win, A_REVERSE);
33  mvwprintw(win, close_offset_y, close_offset_x, "%s", label_close.c_str());
34  wattroff(win, A_REVERSE);
35 }
36 
37 call_t ViewInfo::keypress(int& key)
38 {
39  switch(key)
40  {
41 
42  case KEY_MOUSE:
43  {
44  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
45  MEVENT event;
46  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
47  {
48  size_t column = start_x + close_offset_x;
49  size_t row = start_y + close_offset_y;
50  size_t mouse_x = event.x, mouse_y = event.y;
51  if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
52  key = -1; // do return from view
53  }
54  break;
55  }
56  case KEY_ENT:
57  key = -1; // do return from view
58  break;
59  default:
60  break;
61  }
62  return calls[0];
63 }
diff --git a/docs/html/view__info_8h_source.html b/docs/html/view__info_8h_source.html index 1403ab3..5112fd6 100644 --- a/docs/html/view__info_8h_source.html +++ b/docs/html/view__info_8h_source.html @@ -75,7 +75,7 @@ $(function() {
Definition: view.h:19
diff --git a/docs/html/view__monitor_8cpp_source.html b/docs/html/view__monitor_8cpp_source.html index 17571f0..b55c1cc 100644 --- a/docs/html/view__monitor_8cpp_source.html +++ b/docs/html/view__monitor_8cpp_source.html @@ -76,7 +76,7 @@ $(function() {
uint8_t readDipSwitch(void)
Definition: b15f.cpp:277
void delay_ms(uint16_t ms)
Definition: b15f.cpp:135
static B15F & getInstance(void)
Definition: b15f.cpp:10
-
Definition: b15f.h:37
+
Definition: b15f.h:38
static void abort(std::string msg)
Definition: b15f.cpp:169
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:330
uint8_t digitalRead1(void)
Definition: b15f.cpp:261
@@ -84,7 +84,7 @@ $(function() { diff --git a/docs/html/view__monitor_8h_source.html b/docs/html/view__monitor_8h_source.html index f324039..2f6e776 100644 --- a/docs/html/view__monitor_8h_source.html +++ b/docs/html/view__monitor_8h_source.html @@ -75,7 +75,7 @@ $(function() { diff --git a/docs/html/view__promt_8cpp_source.html b/docs/html/view__promt_8cpp_source.html index ab046ac..94bbc03 100644 --- a/docs/html/view__promt_8cpp_source.html +++ b/docs/html/view__promt_8cpp_source.html @@ -73,7 +73,7 @@ $(function() {
1 #include "view_promt.h"
2 
3 void ViewPromt::draw()
4 {
5  curs_set(1); // show cursor
6 
7  int li = text_offset_y;
8  int ci = 0;
9  for(std::string line : str_split(message + input, "\n"))
10  {
11  mvwprintw(win, ++li, text_offset_x, "%s", line.c_str());
12  ci = line.length() + text_offset_x;
13  }
14 
15  button_offset_x = (width - label_cancel.length() - sep.length() - label_confirm.length()) / 2;
16  button_offset_y = height - text_offset_y;
17 
18  if(selection == 0)
19  {
20  wattron(win, A_REVERSE);
21  mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str());
22  wattroff(win, A_REVERSE);
23  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str());
24  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
25  }
26  else
27  {
28  mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str());
29  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str());
30  wattron(win, A_REVERSE);
31  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
32  wattroff(win, A_REVERSE);
33  }
34  wmove(win, li, ci);
35 }
36 
37 void ViewPromt::setMessage(std::string message)
38 {
39  this->message = message;
40 }
41 
42 void ViewPromt::setConfirm(std::string name, std::function<void(int)> call)
43 {
44  label_confirm = name;
45  call_confirm = call;
46 }
47 
48 void ViewPromt::setCancel(std::string name, bool cancelable)
49 {
50  label_cancel = name;
51  this->cancelable = cancelable;
52 }
53 
54 std::string ViewPromt::getInput()
55 {
56  return input;
57 }
58 
59 std::function<void(int)> ViewPromt::keypress(int& key)
60 {
61  std::function<void(int)> ret = nullptr;
62  switch(key)
63  {
64  case KEY_BACKSPACE:
65  if(input.length())
66  input.pop_back();
67  break;
68  case '\t':
69  case KEY_LEFT:
70  case KEY_RIGHT:
71  selection = (selection + 1 ) % 2;
72  break;
73  case KEY_MOUSE:
74  {
75  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
76  MEVENT event;
77  bool hit = false;
78  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
79  {
80  size_t column_start = start_x + button_offset_x;
81  size_t row_start = start_y + button_offset_y;
82  size_t mouse_x = event.x, mouse_y = event.y;
83  if(mouse_y == row_start)
84  {
85  if(cancelable && mouse_x >= column_start && mouse_x < column_start + label_cancel.length())
86  {
87  if(selection == 0 || event.bstate & BUTTON1_DOUBLE_CLICKED)
88  hit = true;
89  selection = 0;
90  }
91  if(mouse_x >= column_start + label_cancel.length() + sep.length() && mouse_x < column_start + label_cancel.length() + sep.length() + label_confirm.length())
92  {
93  if(selection == 1 || event.bstate & BUTTON1_DOUBLE_CLICKED)
94  hit = true;
95  selection = 1;
96  }
97  }
98  }
99  if(!hit)
100  break;
101 
102  // fall through to next case
103  [[fallthrough]];
104  }
105  case KEY_ENT:
106  if(selection == 0) // exit
107  key = -1; // do return from view
108  else
109  ret = call_confirm;
110  break;
111  default:
112  break;
113  }
114 
115  if(key >= ' ' && key <= '~')
116  input += (char) key;
117 
118  if(key != KEY_ENT)
119  repaint();
120  return ret;
121 }
diff --git a/docs/html/view__promt_8h_source.html b/docs/html/view__promt_8h_source.html index 408c19a..20ee5d7 100644 --- a/docs/html/view__promt_8h_source.html +++ b/docs/html/view__promt_8h_source.html @@ -75,7 +75,7 @@ $(function() { diff --git a/docs/html/view__selection_8cpp_source.html b/docs/html/view__selection_8cpp_source.html index 786df89..f00faf6 100644 --- a/docs/html/view__selection_8cpp_source.html +++ b/docs/html/view__selection_8cpp_source.html @@ -73,7 +73,7 @@ $(function() {
1 #include "view_selection.h"
2 
3 void ViewSelection::draw()
4 {
5  //curs_set(0); // hide cursor
6  for(size_t i = 0; i < choices.size(); i++)
7  {
8  if(selection == i)
9  wattron(win, A_REVERSE);
10  mvwprintw(win, i + choice_offset_y, choice_offset_x, "%s", choices[i].c_str());
11  if(selection == i)
12  wattroff(win, A_REVERSE);
13  }
14 }
15 
16 void ViewSelection::addChoice(std::string name, call_t call)
17 {
18  choices.push_back(name);
19  calls.push_back(call);
20 }
21 
22 call_t ViewSelection::keypress(int& key)
23 {
24  call_t ret = nullptr;
25  switch(key)
26  {
27  case KEY_UP:
28  do
29  selection = (selection - 1 + choices.size()) % choices.size();
30  while(!choices[selection].length() && choices.size());
31  break;
32 
33  case '\t':
34  case KEY_DOWN:
35  do
36  selection = (selection + 1) % choices.size();
37  while(!choices[selection].length() && choices.size());
38  break;
39 
40  case KEY_MOUSE:
41  {
42  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
43  MEVENT event;
44  bool hit = false;
45  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
46  {
47  size_t column_start = start_x + choice_offset_x;
48  size_t row_start = start_y + choice_offset_y;
49  size_t mouse_x = event.x, mouse_y = event.y;
50  for(size_t i = 0; i < choices.size(); i++)
51  if(choices[i].length() && mouse_y == row_start + i && mouse_x >= column_start && mouse_x < column_start + choices[i].length())
52  {
53  if(selection == i || event.bstate & BUTTON1_DOUBLE_CLICKED)
54  hit = true;
55  selection = i;
56  }
57  }
58  if(!hit)
59  break;
60 
61  // fall through to next case
62  [[fallthrough]];
63  }
64 
65  case KEY_ENT:
66  if(selection == choices.size() - 1) // exit
67  key = -1; // do return from view
68  else
69  ret = calls[selection];
70  break;
71  default:
72  break;
73  }
74  repaint();
75  return ret;
76 }
diff --git a/docs/html/view__selection_8h_source.html b/docs/html/view__selection_8h_source.html index 5853202..e7df8ab 100644 --- a/docs/html/view__selection_8h_source.html +++ b/docs/html/view__selection_8h_source.html @@ -75,7 +75,7 @@ $(function() { diff --git a/firmware/Makefile b/firmware/Makefile index 4ec9c02..d5b62ae 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -55,7 +55,7 @@ upload: b15f checkfuses commit_hash: @echo "Updating commit hash..." - @echo -e "#ifndef COMMIT_HASH_H\n#define COMMIT_HASH_H\nconstexpr char* COMMIT_HASH = \"`git log --pretty=format:'%H' -n 1`\";\n#endif // COMMIT_HASH_H" > commit_hash.h + @bash -c 'echo -e "#ifndef COMMIT_HASH_H\n#define COMMIT_HASH_H\nconst char COMMIT_HASH[] = \"`git log --pretty=format:'%H' -n 1`\";\n#endif // COMMIT_HASH_H" > commit_hash.h' .cpp.o: $(COMPILE) -c $< -o $@ diff --git a/firmware/boardinfo.h b/firmware/boardinfo.h index faa03bb..9683ca1 100644 --- a/firmware/boardinfo.h +++ b/firmware/boardinfo.h @@ -1,6 +1,8 @@ #ifndef BOARDINFO_H #define BOARDINFO_H +#include "commit_hash.h" + const char DATE[] = __DATE__; const char TIME[] = __TIME__; const char FSRC[] = __FILE__; diff --git a/firmware/commit_hash.h b/firmware/commit_hash.h index 6671807..3db50b6 100644 --- a/firmware/commit_hash.h +++ b/firmware/commit_hash.h @@ -1,4 +1,4 @@ #ifndef COMMIT_HASH_H #define COMMIT_HASH_H -constexpr char* COMMIT_HASH = "2e29c6fcb5debd952e967adc773d396b7f645450"; +const char COMMIT_HASH[] = "ae6920cdf9fed20780ed671c86150b00283c67b6"; #endif // COMMIT_HASH_H diff --git a/firmware/request_handlers.cpp b/firmware/request_handlers.cpp index ba2f5c1..2192be1 100644 --- a/firmware/request_handlers.cpp +++ b/firmware/request_handlers.cpp @@ -125,10 +125,11 @@ void rqTestConnection() void rqBoardInfo() { usart.initTX(); - usart.writeByte(3); // Anzahl an Strings + usart.writeByte(4); // Anzahl an Strings usart.writeStr(DATE, sizeof(DATE)); usart.writeStr(TIME, sizeof(TIME)); usart.writeStr(FSRC, sizeof(FSRC)); + usart.writeStr(COMMIT_HASH, sizeof(COMMIT_HASH)); usart.writeByte(USART::MSG_OK); usart.flush(); }