B15F
Board 15 Famulus Edition
backup.cpp
1 
2 void USART::writeByte(uint8_t b)
3 {
4  int sent = write(file_desc, &b, 1);
5  if (sent != 1)
6  {
7  std::cout << "WARNUNG: Fehler beim Senden (" << sent << "): writeByte(), wiederhole..." << std::endl;
8  usleep(100000);
9  sent = write(file_desc, &b, 1);
10  if (sent != 1)
11  throw USARTException("Fehler beim Senden: writeByte()");
12  }
13 
14 }
15 
16 void USART::writeInt(uint16_t d)
17 {
18  int sent = write(file_desc, reinterpret_cast<char *>(&d), 2);
19  if (sent != 2)
20  throw USARTException("Fehler beim Senden: writeInt()");
21 }
22 
23 void USART::writeU32(uint32_t w)
24 {
25  int sent = write(file_desc, reinterpret_cast<char *>(&w), 4);
26  if (sent != 4)
27  throw USARTException("Fehler beim Senden: writeU32()");
28 }
29 
30 uint8_t USART::readByte(void)
31 {
32  char b;
33  auto start = std::chrono::steady_clock::now();
34  auto end = start;
35  uint16_t elapsed = 0;
36  while (elapsed < timeout * 100)
37  {
38  int code = read(file_desc, &b, 1);
39  if (code > 0)
40  return static_cast<uint8_t>(b);
41 
42  end = std::chrono::steady_clock::now();
43  elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
44  }
45 
46  throw TimeoutException("Verbindung unterbrochen.", timeout);
47 }
48 
49 uint16_t USART::readInt(void)
50 {
51  return readByte() | readByte() << 8;
52 }
USARTException
Definition: usartexception.h:9
TimeoutException
Definition: timeoutexception.h:9