3 B15F* B15F::instance =
nullptr;
4 errorhandler_t B15F::errorhandler =
nullptr;
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)
18 if(device.length() == 0)
19 abort(
"Adapter nicht gefunden");
21 std::cout <<
PRE <<
"Verwende Adapter: " << device << std::endl;
25 std::cout <<
PRE <<
"Stelle Verbindung mit Adapter her... " << std::flush;
28 std::cout <<
"OK" << std::endl;
32 std::cout <<
PRE <<
"Teste Verbindung... " << std::flush;
48 abort(
"Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
49 std::cout <<
"OK" << std::endl;
54 std::cout <<
PRE <<
"AVR Firmware Version: " << info[0] <<
" um " << info[1] <<
" Uhr (" << info[2] <<
")" << std::endl;
69 abort(
"Verbindung kann nicht repariert werden");
77 for(uint8_t i = 0; i < 16; i++)
79 usart.writeByte(RQ_DISC);
84 catch(std::exception& ex)
94 uint8_t dummy = rand() % 256;
96 usart.writeByte(RQ_TEST);
97 usart.writeByte(dummy);
99 uint8_t aw = usart.readByte();
100 uint8_t mirror = usart.readByte();
102 return aw ==
MSG_OK && mirror == dummy;
108 uint16_t dummy = rand() % (0xFFFF / 3);
110 usart.writeByte(RQ_INT);
111 usart.writeInt(dummy);
113 uint16_t aw = usart.readInt();
114 return aw == dummy * 3;
120 std::vector<std::string> info;
122 usart.writeByte(RQ_INFO);
124 uint8_t n = usart.readByte();
127 uint8_t len = usart.readByte();
132 str += static_cast<char>(usart.readByte());
138 uint8_t aw = usart.readByte();
140 abort(
"Board Info fehlerhalft: code " + std::to_string((
int) aw));
147 usart.writeByte(RQ_ST);
149 uint8_t aw = usart.readByte();
155 usart.writeByte(RQ_BA0);
156 usart.writeByte(port);
158 uint8_t aw = usart.readByte();
165 usart.writeByte(RQ_BA1);
166 usart.writeByte(port);
168 uint8_t aw = usart.readByte();
176 usart.writeByte(RQ_BE0);
177 uint8_t
byte = usart.readByte();
185 usart.writeByte(RQ_BE1);
186 uint8_t
byte = usart.readByte();
194 usart.writeByte(RQ_DSW);
195 uint8_t
byte = usart.readByte();
202 usart.writeByte(RQ_AA0);
203 usart.writeInt(value);
205 uint8_t aw = usart.readByte();
212 usart.writeByte(RQ_AA1);
213 usart.writeInt(value);
215 uint8_t aw = usart.readByte();
224 abort(
"Bad ADC channel: " + std::to_string(channel));
232 usart.
transmit(&rq[0], 0,
sizeof(rq));
234 uint16_t adc = usart.readInt();
237 abort(
"Bad ADC data detected (1)");
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)
244 buffer_a += offset_a;
245 buffer_b += offset_b;
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);
256 for(uint16_t i = 0; i < count; i++)
260 buffer_a[i] = usart.readInt();
262 if(buffer_a[i] > 1023)
263 abort(
"Bad ADC data detected (2)");
272 buffer_b[i] = usart.readInt();
274 if(buffer_b[i] > 1023)
275 abort(
"Bad ADC data detected (3)");
283 uint8_t aw = usart.readByte();
285 abort(
"Sequenz unterbrochen");
297 static_cast<uint8_t>((freq >> 0) & 0xFF),
298 static_cast<uint8_t>((freq >> 8) & 0xFF),
299 static_cast<uint8_t>((freq >> 16) & 0xFF),
300 static_cast<uint8_t>((freq >> 24) & 0xFF)
303 usart.
transmit(&rq[0], 0,
sizeof(rq));
305 uint8_t
byte = usart.readByte();
320 usart.
transmit(&rq[0], 0,
sizeof(rq));
322 uint8_t aw = usart.readByte();
338 usart.
transmit(&rq[0], 0,
sizeof(rq));
340 uint8_t
byte = usart.readByte();
355 usart.
transmit(&rq[0], 0,
sizeof(rq));
357 uint8_t aw = usart.readByte();
365 std::this_thread::sleep_for(std::chrono::milliseconds(ms));
370 std::this_thread::sleep_for(std::chrono::microseconds(us));
376 instance =
new B15F();
384 std::array<char, 128> buffer;
386 std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(),
"r"), pclose);
389 throw std::runtime_error(
"popen() failed!");
391 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr)
393 result += buffer.data();
409 std::cerr <<
"NOTICE: B15F::errorhandler not set" << std::endl;
410 std::cout << ex.what() << std::endl;