B15F
Board 15 Famulus Edition
|
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++)
84 catch(std::exception& ex)
94 uint8_t dummy = rand() % 256;
102 return aw ==
MSG_OK && mirror == dummy;
108 uint16_t dummy = rand() % (0xFFFF / 3);
114 return aw == dummy * 3;
120 std::vector<std::string> info;
132 str += static_cast<char>(usart.
readByte());
140 abort(
"Board Info fehlerhalft: code " + std::to_string((
int) aw));
224 abort(
"Bad ADC channel: " + std::to_string(channel));
232 int n_sent = usart.write_timeout(&rq[0], 0,
sizeof(rq), 1000);
233 if(n_sent !=
sizeof(rq))
234 abort(
"Sent failed");
236 uint16_t adc = usart.
readInt();
239 abort(
"Bad ADC data detected (1)");
243 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)
246 buffer_a += offset_a;
247 buffer_b += offset_b;
255 usart.
writeInt(static_cast<uint16_t>(delta));
258 for(uint16_t i = 0; i < count; i++)
264 if(buffer_a[i] > 1023)
265 abort(
"Bad ADC data detected (2)");
276 if(buffer_b[i] > 1023)
277 abort(
"Bad ADC data detected (3)");
287 abort(
"Sequenz unterbrochen");
294 std::this_thread::sleep_for(std::chrono::milliseconds(ms));
299 std::this_thread::sleep_for(std::chrono::microseconds(us));
305 instance =
new B15F();
313 std::array<char, 128> buffer;
315 std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(),
"r"), pclose);
318 throw std::runtime_error(
"popen() failed!");
320 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr)
322 result += buffer.data();
338 std::cerr <<
"NOTICE: B15F::errorhandler not set" << std::endl;
339 std::cout << ex.what() << std::endl;
static std::string exec(std::string cmd)
void delay_us(uint16_t us)
uint8_t digitalRead0(void)
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)
bool testConnection(void)
uint8_t readDipSwitch(void)
void delay_ms(uint16_t ms)
static B15F & getInstance(void)
static void abort(std::string msg)
void clearInputBuffer(void)
void clearOutputBuffer(void)
uint16_t analogRead(uint8_t channel)
bool digitalWrite0(uint8_t)
const std::string PRE
B15F stdout prefix.
void setBaudrate(uint32_t baudrate)
bool activateSelfTestMode(void)
std::vector< std::string > getBoardInfo(void)
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
bool analogWrite1(uint16_t port)
void writeByte(uint8_t b)
bool digitalWrite1(uint8_t)
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
void openDevice(std::string device)
uint8_t digitalRead1(void)
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
static void setAbortHandler(errorhandler_t func)
bool analogWrite0(uint16_t port)
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
void writeInt(uint16_t d)