This commit is contained in:
Tristan Krause 2019-06-25 11:07:06 +02:00
parent 61ee69dc84
commit 7b2e5aa1ef
71 changed files with 1276 additions and 188 deletions

View file

@ -7,7 +7,7 @@ errorhandler_t B15F::errorhandler = nullptr;
/*************************************
* Grundfunktionen des B15F Treibers *
*************************************/
B15F &B15F::getInstance(void)
{
if (!instance)
@ -204,7 +204,7 @@ bool B15F::activateSelfTestMode()
}
bool B15F::digitalWrite0(uint8_t port)
{
{
uint8_t rq[] =
{
RQ_DIGITAL_WRITE_0,
@ -270,9 +270,9 @@ uint8_t B15F::readDipSwitch()
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
reverse(aw); // DIP Schalter muss invertiert werden!
return aw;
}
@ -528,7 +528,7 @@ uint16_t* B15F::getInterruptCounterOffset()
/**********************
* Private Funktionen *
* Private Funktionen *
**********************/
B15F::B15F()

View file

@ -0,0 +1,584 @@
#include "b15f.h"
B15F *B15F::instance = nullptr;
errorhandler_t B15F::errorhandler = nullptr;
/*************************************
* Grundfunktionen des B15F Treibers *
*************************************/
B15F &B15F::getInstance(void)
{
if (!instance)
instance = new B15F();
return *instance;
}
void B15F::reconnect()
{
uint8_t tries = RECONNECT_TRIES;
while (tries--)
{
delay_ms(RECONNECT_TIMEOUT);
discard();
if (testConnection())
return;
}
abort("Verbindung kann nicht repariert werden");
}
void B15F::discard(void)
{
try
{
uint8_t rq[] =
{
RQ_DISCARD
};
usart.clearOutputBuffer();
for (uint8_t i = 0; i < 16; i++)
{
usart.transmit(&rq[0], 0, sizeof(rq)); // sende discard Befehl (verwerfe input)
delay_ms(4);
}
usart.clearInputBuffer();
}
catch (std::exception &ex)
{
abort(ex);
}
}
bool B15F::testConnection()
{
// erzeuge zufälliges Byte
srand(time(NULL));
uint8_t dummy = rand() % 256;
uint8_t rq[] =
{
RQ_TEST,
dummy
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw[2];
usart.receive(&aw[0], 0, sizeof(aw));
return aw[0] == MSG_OK && aw[1] == dummy;
}
bool B15F::testIntConv()
{
srand(time(NULL));
uint16_t dummy = rand() % (0xFFFF / 3);
uint8_t rq[] =
{
RQ_INT_TEST,
static_cast<uint8_t >(dummy & 0xFF),
static_cast<uint8_t >(dummy >> 8)
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint16_t aw;
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
return aw == dummy * 3;
}
std::vector<std::string> B15F::getBoardInfo(void)
{
std::vector<std::string> info;
uint8_t rq[] =
{
RQ_INFO
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t n;
usart.receive(&n, 0, sizeof(n));
while (n--)
{
uint8_t len;
usart.receive(&len, 0, sizeof(len));
char str[len + 1];
str[len] = '\0';
usart.receive(reinterpret_cast<uint8_t *>(&str[0]), 0, len);
info.push_back(std::string(str));
}
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
if (aw != MSG_OK)
abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
return info;
}
void B15F::delay_ms(uint16_t ms)
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
void B15F::delay_us(uint16_t us)
{
std::this_thread::sleep_for(std::chrono::microseconds(us));
}
void B15F::reverse(uint8_t& b)
{
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
}
// https://stackoverflow.com/a/478960
std::string B15F::exec(std::string cmd)
{
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
if (!pipe)
{
throw std::runtime_error("popen() failed!");
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
{
result += buffer.data();
}
return result;
}
void B15F::abort(std::string msg)
{
DriverException ex(msg);
abort(ex);
}
void B15F::abort(std::exception &ex)
{
if (errorhandler)
errorhandler(ex);
else
{
std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
std::cout << ex.what() << std::endl;
throw DriverException(ex.what());
}
}
void B15F::setAbortHandler(errorhandler_t func)
{
errorhandler = func;
}
/*************************************/
/*************************
* Steuerbefehle für B15 *
*************************/
bool B15F::activateSelfTestMode()
{
uint8_t rq[] =
{
RQ_SELF_TEST
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw == MSG_OK;
}
bool B15F::digitalWrite0(uint8_t port)
{
uint8_t rq[] =
{
RQ_DIGITAL_WRITE_0,
port
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw == MSG_OK;
}
bool B15F::digitalWrite1(uint8_t port)
{
uint8_t rq[] =
{
RQ_DIGITAL_WRITE_1,
port
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw == MSG_OK;
}
uint8_t B15F::digitalRead0()
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_DIGITAL_READ_0
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw;
}
uint8_t B15F::digitalRead1()
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_DIGITAL_READ_1
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw;
}
uint8_t B15F::readDipSwitch()
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_READ_DIP_SWITCH
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
reverse(aw); // DIP Schalter muss invertiert werden!
return aw;
}
bool B15F::analogWrite0(uint16_t value)
{
uint8_t rq[] =
{
RQ_ANALOG_WRITE_0,
static_cast<uint8_t >(value & 0xFF),
static_cast<uint8_t >(value >> 8)
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw == MSG_OK;
}
bool B15F::analogWrite1(uint16_t value)
{
uint8_t rq[] =
{
RQ_ANALOG_WRITE_1,
static_cast<uint8_t >(value & 0xFF),
static_cast<uint8_t >(value >> 8)
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw == MSG_OK;
}
uint16_t B15F::analogRead(uint8_t channel)
{
usart.clearInputBuffer();
if (channel > 7)
abort("Bad ADC channel: " + std::to_string(channel));
uint8_t rq[] =
{
RQ_ANALOG_READ,
channel
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint16_t aw;
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
if (aw > 1023)
abort("Bad ADC data detected (1)");
return aw;
}
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)
{
// prepare pointers
buffer_a += offset_a;
buffer_b += offset_b;
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_ADC_DAC_STROKE,
channel_a,
channel_b,
static_cast<uint8_t >(start & 0xFF),
static_cast<uint8_t >(start >> 8),
static_cast<uint8_t >(delta & 0xFF),
static_cast<uint8_t >(delta >> 8),
static_cast<uint8_t >(count & 0xFF),
static_cast<uint8_t >(count >> 8)
};
usart.transmit(&rq[0], 0, sizeof(rq));
for (uint16_t i = 0; i < count; i++)
{
if (buffer_a)
{
usart.receive(reinterpret_cast<uint8_t *>(&buffer_a[i]), 0, 2);
if (buffer_a[i] > 1023) // check for broken usart connection
abort("Bad ADC data detected (2)");
}
else
{
usart.drop(2);
}
if (buffer_b)
{
usart.receive(reinterpret_cast<uint8_t *>(&buffer_b[i]), 0, 2);
if (buffer_b[i] > 1023) // check for broken usart connection
abort("Bad ADC data detected (3)");
}
else
{
usart.drop(2);
}
}
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
if(aw != MSG_OK)
abort("Sequenz unterbrochen");
}
uint8_t B15F::pwmSetFrequency(uint32_t freq)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_PWM_SET_FREQ,
static_cast<uint8_t>((freq >> 0) & 0xFF),
static_cast<uint8_t>((freq >> 8) & 0xFF),
static_cast<uint8_t>((freq >> 16) & 0xFF),
static_cast<uint8_t>((freq >> 24) & 0xFF)
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw;
}
bool B15F::pwmSetValue(uint8_t value)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_PWM_SET_VALUE,
value
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw == MSG_OK;
}
bool B15F::setMem8(volatile uint8_t* adr, uint8_t val)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_SET_MEM_8,
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
val
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw == val;
}
uint8_t B15F::getMem8(volatile uint8_t* adr)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_GET_MEM_8,
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw;
usart.receive(&aw, 0, sizeof(aw));
return aw;
}
bool B15F::setMem16(volatile uint16_t* adr, uint16_t val)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_SET_MEM_16,
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
static_cast<uint8_t >(val & 0xFF),
static_cast<uint8_t >(val >> 8)
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint16_t aw;
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
return aw == val;
}
uint16_t B15F::getMem16(volatile uint16_t* adr)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_GET_MEM_16,
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint16_t aw;
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
return aw;
}
bool B15F::setRegister(volatile uint8_t* adr, uint8_t val)
{
return setMem8(adr, val);
}
uint8_t B15F::getRegister(volatile uint8_t* adr)
{
return getMem8(adr);
}
uint16_t* B15F::getInterruptCounterOffset()
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_COUNTER_OFFSET
};
usart.transmit(&rq[0], 0, sizeof(rq));
uint16_t aw;
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
return reinterpret_cast<uint16_t*>(aw);
}
/*************************/
/**********************
* Private Funktionen *
**********************/
B15F::B15F()
{
init();
}
void B15F::init()
{
std::string device = exec("bash -c 'ls /dev/ttyUSB*'");
while (device.find(' ') != std::string::npos || device.find('\n') != std::string::npos ||
device.find('\t') != std::string::npos)
device.pop_back();
if (device.length() == 0)
abort("Adapter nicht gefunden");
std::cout << PRE << "Verwende Adapter: " << device << std::endl;
std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
usart.setBaudrate(BAUDRATE);
usart.openDevice(device);
std::cout << "OK" << std::endl;
std::cout << PRE << "Teste Verbindung... " << std::flush;
uint8_t tries = 3;
while (tries--)
{
// verwerfe Daten, die µC noch hat
//discard();
if (!testConnection())
continue;
if (!testIntConv())
continue;
break;
}
if (tries == 0)
abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
std::cout << "OK" << std::endl;
// Gib board info aus
std::vector<std::string> info = getBoardInfo();
std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")"
<< std::endl;
}

View file

@ -43,7 +43,7 @@ public:
* @throws DriverException
*/
static B15F& getInstance(void);
/**
* Versucht die Verbindung zum B15 wiederherzustellen
* \throws DriverException
@ -85,7 +85,7 @@ public:
* \param us Verzögerung in Microsekunden
*/
void delay_us(uint16_t us);
/**
* Invertiert das Bitmuster eines Bytes
* z.B.: 10100001 --> 10000101
@ -273,7 +273,7 @@ public:
* \return Wert des Registers
*/
uint8_t getRegister(volatile uint8_t* adr);
/**
* Liefert die Adresse des ersten Interrupt Counters (BASISR).
* \return Adresse (in der MCU)
@ -298,7 +298,7 @@ private:
* Privater Konstruktor
*/
B15F(void);
/**
* Initialisiert und testet die Verbindung zum B15
* \throws DriverException

313
control/src/drv/b15f.h.orig Normal file
View file

@ -0,0 +1,313 @@
#ifndef B15F_H
#define B15F_H
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <fstream>
#include <cstdlib>
#include <chrono>
#include <cstdint>
#include <vector>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <termios.h>
#include "requests.h"
#include "usart.h"
#include "driverexception.h"
#include "timeoutexception.h"
// wichtig für die Register-Zugriffe
#define _AVR_IO_H_ 1 // Erzwinge die Inklusion
#include "/usr/lib/avr/include/avr/sfr_defs.h"
#include "/usr/lib/avr/include/avr/iom1284p.h"
typedef std::function<void(std::exception&)> errorhandler_t;
/*! main driver class */
class B15F
{
public:
/*************************************
* Grundfunktionen des B15F Treibers *
*************************************/
/**
* Liefert eine Referenz zur aktuellen Treiber-Instanz, die Verbindung wird gegebenenfalls automatisch hergestellt.
* @throws DriverException
*/
static B15F& getInstance(void);
/**
* Versucht die Verbindung zum B15 wiederherzustellen
* \throws DriverException
*/
void reconnect(void);
/**
* Verwirft Daten im USART Puffer auf dieser Maschine und B15
* \throws DriverException
*/
void discard(void);
/**
* Testet die USART Verbindung auf Funktion
* \throws DriverException
*/
bool testConnection(void);
/**
* Testet die Integer Konvertierung der USART Verbindung
* \throws DriverException
*/
bool testIntConv(void);
/**
* Liefert Informationen zur aktuellen Firmware des B15
* \throws DriverException
*/
std::vector<std::string> getBoardInfo(void);
/**
* Lässt den Treiber für eine angegebene Zeit pausieren
* \param ms Verzögerung in Millisekunden
*/
void delay_ms(uint16_t ms);
/**
* Lässt den Treiber für eine angegebene Zeit pausieren
* \param us Verzögerung in Microsekunden
*/
void delay_us(uint16_t us);
/**
* Invertiert das Bitmuster eines Bytes
* z.B.: 10100001 --> 10000101
* \param b Byte, das invertiert wird
*/
void reverse(uint8_t& b);
/**
* Führt ein Befehl auf dieser Maschine aus und liefert stdout zurück
* \param cmd Der Befehl
*/
static std::string exec(std::string cmd);
/**
* Multithread sicherer Abbruch des B15F-Treibers
* \param msg Beschreibung der Abbruchursache
*/
static void abort(std::string msg);
/**
* Multithread sicherer Abbruch des B15F-Treibers
* \param ex Exception als Abbruchursache
*/
static void abort(std::exception& ex);
/**
* Setzt eine Fehlerbehandlungsroutine für den Treiberabbruch (abort)
* \param func Funktion, die Exception als Parameter bekommt
*/
static void setAbortHandler(errorhandler_t func);
/*************************************/
/*************************
* Steuerbefehle für B15 *
*************************/
/**
* Versetzt das Board in den Selbsttest-Modus
* WICHTIG: Es darf dabei nichts an den Klemmen angeschlossen sein!
* \throws DriverException
*/
bool activateSelfTestMode(void);
/**
* Setzt den Wert des digitalen Ausgabeports 0
* \param port Wert für gesamten Port
* \throws DriverException
*/
bool digitalWrite0(uint8_t);
/**
* Setzt den Wert des digitalen Ausgabeports 1
* \param port Wert für gesamten Port
* \throws DriverException
*/
bool digitalWrite1(uint8_t);
/**
* Liest den Wert des digitalen Eingabeports 0
* \return Wert für gesamten Port
* \throws DriverException
*/
uint8_t digitalRead0(void);
/**
* Liest den Wert des digitalen Eingabeports 1
* \return Wert für gesamten Port
* \throws DriverException
*/
uint8_t digitalRead1(void);
/**
* Liest den Wert des digitalen Eingabeports, an dem der DIP-switch angeschlossen ist (S7)
* \return Wert für gesamten Port
* \throws DriverException
*/
uint8_t readDipSwitch(void);
/**
* Setzt den Wert des Digital-Analog-Converters (DAC / DAU) 0
* \param port 10-Bit Wert
* \throws DriverException
*/
bool analogWrite0(uint16_t port);
/**
* Setzt den Wert des Digital-Analog-Converters (DAC / DAU) 1
* \param port 10-Bit Wert
* \throws DriverException
*/
bool analogWrite1(uint16_t port);
/**
* Liest den Wert des Analog-Digital-Converters (ADC / ADU)
* \param channel Kanalwahl von 0 - 7
* \throws DriverException
*/
uint16_t analogRead(uint8_t channel);
/**
* 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.
* \param channel_a Auswahl des ADC a, von 0 - 7
* \param buffer_a Speichertort für Werte des Kanals a
* \param offset_a Anzahl an Werten des Kanals a, die im Speicher übersprungen werden sollen
* \param channel_b Auswahl des ADC b, von 0 - 7
* \param buffer_b Speichertort für Werte des Kanals b
* \param offset_b Anzahl an Werten des Kanals b, die im Speicher übersprungen werden
* \param start Startwert des DACs
* \param delta Schrittweite, mit welcher der DAC inkrementiert wird
* \param count Anzahl an Inkrementierungen
* \throws DriverException
*/
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);
/**
* Setzt die Register so, dass näherungsweise die gewünschte Frequenz erzeugt wird.
* Ist freq == 0 wird PWM deaktiviert.
* Standardfrequenz: 31300 (empfohlen, da dann TOP == 255)
* \param freq PWM Frequenz
* \return Top Wert des PWM Value für die gesetzte Frequenz
* \throws DriverException
*/
uint8_t pwmSetFrequency(uint32_t freq);
/**
* Setzt den PWM Wert.
* \param value PWM Wert [0..0xFF]
* \throws DriverException
*/
bool pwmSetValue(uint8_t value);
/**
* Setzt direkt den Wert einer MCU Speicherzelle der Größe 8 Bit.
* Diese kann ein Register oder RAM-Daten sein.
* *Wichtig:* bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen!
* \param adr Speicheradresse
* \param val Neuer Wert für die Zelle
* \return true, falls Vorgang erfolgreich
*/
bool setMem8(volatile uint8_t* adr, uint8_t val);
/**
* Liefert den Wert einer MCU Speicherzelle der Größe 8 Bit.
* Diese kann ein Register oder RAM-Daten sein.
* \param adr Speicheradresse
* \return Wert der Speicherzelle
*/
uint8_t getMem8(volatile uint8_t* adr);
/**
* Setzt direkt den Wert einer MCU Speicherzelle der Größe 16 Bit.
* Diese kann ein Register oder RAM-Daten sein.
* *Wichtig:* bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen!
* \param adr Speicheradresse
* \param val Neuer Wert für die Zelle
* \return true, falls Vorgang erfolgreich
*/
bool setMem16(volatile uint16_t* adr, uint16_t val);
/**
* Liefert den Wert einer MCU Speicherzelle der Größe 16 Bit.
* Diese kann ein Register oder RAM-Daten sein.
* \param adr Speicheradresse
* \return Wert der Speicherzelle
*/
uint16_t getMem16(volatile uint16_t* adr);
/**
* Diese Funktion ist ein Alias für setMem8().
* *Wichtig:* bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen!
* \param adr Speicheradresse
* \param val Neuer Wert für das Register
* \return true, falls Vorgang erfolgreich
*/
bool setRegister(volatile uint8_t* adr, uint8_t val);
/**
* Diese Funktion ist ein Alias für getMem8().
* \param adr Speicheradresse
* \return Wert des Registers
*/
uint8_t getRegister(volatile uint8_t* adr);
/**
* Liefert die Adresse des ersten Interrupt Counters (BASISR).
* \return Adresse (in der MCU)
*/
uint16_t* getInterruptCounterOffset(void);
/*************************/
// CONSTANTS
const std::string PRE = "[B15F] "; //!< B15F stdout prefix
constexpr static uint8_t MSG_OK = 0xFF; //!< Value to acknowledge a received command
constexpr static uint8_t MSG_FAIL = 0xFE; //!< Value to reject a received command
constexpr static uint16_t RECONNECT_TIMEOUT = 64; //!< Time in ms after which a reconnect attempt aborts
constexpr static uint16_t WDT_TIMEOUT = 15; //!< Time in ms after which the watch dog timer resets the MCU
constexpr static uint8_t RECONNECT_TRIES = 3; //!< Maximum count of reconnect attempts after which the driver stops
constexpr static uint32_t BAUDRATE = 57600; //!< USART baudrate for communication with the MCU
private:
/**
* Privater Konstruktor
*/
B15F(void);
/**
* Initialisiert und testet die Verbindung zum B15
* \throws DriverException
*/
void init(void);
USART usart;
static B15F* instance;
static errorhandler_t errorhandler;
};
#endif // B15F_H

View file

@ -23,28 +23,29 @@ constexpr static uint8_t RQ_SET_MEM_16 = 18;
constexpr static uint8_t RQ_GET_MEM_16 = 19;
constexpr static uint8_t RQ_COUNTER_OFFSET = 20;
uint8_t const rq_len[] = {
1 /* RQ_DISCARD */,
1 /* RQ_TEST */ + 1 /* test byte */,
1 /* RQ_INFO */,
1 /* RQ_INT_TEST */ + 1 /* test int high low */ + 1 /* test int high high */,
1 /* RQ_SELF_TEST */,
1 /* RQ_DIGITAL_WRITE_0 */ + 1 /* port value */,
1 /* RQ_DIGITAL_WRITE_1 */ + 1 /* port value */,
1 /* RQ_DIGITAL_READ_0 */,
1 /* RQ_DIGITAL_READ_1 */,
1 /* RQ_READ_DIP_SWITCH */,
1 /* RQ_ANALOG_WRITE_0 */ + 1 /* test int high low */ + 1 /* test int high high */,
1 /* RQ_ANALOG_WRITE_1 */ + 1 /* test int high low */ + 1 /* test int high high */,
1 /* RQ_ANALOG_READ */ + 1 /* adc channel */,
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 */,
1 /* RQ_PWM_SET_FREQ */ + 1 /* freq low low */ + 1 /* freq low high */ + 1 /* freq high low */ + 1 /* freq high high */,
1 /* RQ_PWM_SET_VALUE */ + 1 /* pwm value */,
1 /* RQ_SET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value (8-bit) */,
1 /* RQ_GET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */,
1 /* RQ_SET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value low */ + 1 /* memory value high */,
1 /* RQ_GET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */,
1 /* RQ_COUNTER_OFFSET */,
uint8_t const rq_len[] =
{
1 /* RQ_DISCARD */,
1 /* RQ_TEST */ + 1 /* test byte */,
1 /* RQ_INFO */,
1 /* RQ_INT_TEST */ + 1 /* test int high low */ + 1 /* test int high high */,
1 /* RQ_SELF_TEST */,
1 /* RQ_DIGITAL_WRITE_0 */ + 1 /* port value */,
1 /* RQ_DIGITAL_WRITE_1 */ + 1 /* port value */,
1 /* RQ_DIGITAL_READ_0 */,
1 /* RQ_DIGITAL_READ_1 */,
1 /* RQ_READ_DIP_SWITCH */,
1 /* RQ_ANALOG_WRITE_0 */ + 1 /* test int high low */ + 1 /* test int high high */,
1 /* RQ_ANALOG_WRITE_1 */ + 1 /* test int high low */ + 1 /* test int high high */,
1 /* RQ_ANALOG_READ */ + 1 /* adc channel */,
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 */,
1 /* RQ_PWM_SET_FREQ */ + 1 /* freq low low */ + 1 /* freq low high */ + 1 /* freq high low */ + 1 /* freq high high */,
1 /* RQ_PWM_SET_VALUE */ + 1 /* pwm value */,
1 /* RQ_SET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value (8-bit) */,
1 /* RQ_GET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */,
1 /* RQ_SET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value low */ + 1 /* memory value high */,
1 /* RQ_GET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */,
1 /* RQ_COUNTER_OFFSET */,
};
#endif // REQUESTS_H

View file

@ -0,0 +1,50 @@
#ifndef REQUESTS_H
#define REQUESTS_H
constexpr static uint8_t RQ_DISCARD = 0;
constexpr static uint8_t RQ_TEST = 1;
constexpr static uint8_t RQ_INFO = 2;
constexpr static uint8_t RQ_INT_TEST = 3;
constexpr static uint8_t RQ_SELF_TEST = 4;
constexpr static uint8_t RQ_DIGITAL_WRITE_0 = 5;
constexpr static uint8_t RQ_DIGITAL_WRITE_1 = 6;
constexpr static uint8_t RQ_DIGITAL_READ_0 = 7;
constexpr static uint8_t RQ_DIGITAL_READ_1 = 8;
constexpr static uint8_t RQ_READ_DIP_SWITCH = 9;
constexpr static uint8_t RQ_ANALOG_WRITE_0 = 10;
constexpr static uint8_t RQ_ANALOG_WRITE_1 = 11;
constexpr static uint8_t RQ_ANALOG_READ = 12;
constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
constexpr static uint8_t RQ_PWM_SET_FREQ = 14;
constexpr static uint8_t RQ_PWM_SET_VALUE = 15;
constexpr static uint8_t RQ_SET_MEM_8 = 16;
constexpr static uint8_t RQ_GET_MEM_8 = 17;
constexpr static uint8_t RQ_SET_MEM_16 = 18;
constexpr static uint8_t RQ_GET_MEM_16 = 19;
constexpr static uint8_t RQ_COUNTER_OFFSET = 20;
uint8_t const rq_len[] = {
1 /* RQ_DISCARD */,
1 /* RQ_TEST */ + 1 /* test byte */,
1 /* RQ_INFO */,
1 /* RQ_INT_TEST */ + 1 /* test int high low */ + 1 /* test int high high */,
1 /* RQ_SELF_TEST */,
1 /* RQ_DIGITAL_WRITE_0 */ + 1 /* port value */,
1 /* RQ_DIGITAL_WRITE_1 */ + 1 /* port value */,
1 /* RQ_DIGITAL_READ_0 */,
1 /* RQ_DIGITAL_READ_1 */,
1 /* RQ_READ_DIP_SWITCH */,
1 /* RQ_ANALOG_WRITE_0 */ + 1 /* test int high low */ + 1 /* test int high high */,
1 /* RQ_ANALOG_WRITE_1 */ + 1 /* test int high low */ + 1 /* test int high high */,
1 /* RQ_ANALOG_READ */ + 1 /* adc channel */,
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 */,
1 /* RQ_PWM_SET_FREQ */ + 1 /* freq low low */ + 1 /* freq low high */ + 1 /* freq high low */ + 1 /* freq high high */,
1 /* RQ_PWM_SET_VALUE */ + 1 /* pwm value */,
1 /* RQ_SET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value (8-bit) */,
1 /* RQ_GET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */,
1 /* RQ_SET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value low */ + 1 /* memory value high */,
1 /* RQ_GET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */,
1 /* RQ_COUNTER_OFFSET */,
};
#endif // REQUESTS_H