# B15F: drv/b15f.h Source File

b15f.h
#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 "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;
class B15F
{
private:
// privater Konstruktor
B15F(void);
public:
/*************************************
* Grundfunktionen des B15F Treibers *
*************************************/
void reconnect(void);
void discard(void);
bool testConnection(void);
bool testIntConv(void);
std::vector<std::string> getBoardInfo(void);
void delay_ms(uint16_t ms);
void delay_us(uint16_t us);
static B15F& getInstance(void);
static std::string exec(std::string cmd);
static void abort(std::string msg);
static void abort(std::exception& ex);
static void setAbortHandler(errorhandler_t func);
/*************************************/
/*************************
* Steuerbefehle für B15 *
*************************/
bool activateSelfTestMode(void);
bool digitalWrite0(uint8_t);
bool digitalWrite1(uint8_t);
uint8_t digitalRead0(void);
uint8_t digitalRead1(void);
uint8_t readDipSwitch(void);
bool analogWrite0(uint16_t port);
bool analogWrite1(uint16_t port);
uint16_t analogRead(uint8_t channel);
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);
uint8_t pwmSetFrequency(uint32_t freq);
bool pwmSetValue(uint8_t value);
bool setRegister(volatile uint8_t* adr, uint8_t val);
uint8_t getRegister(volatile uint8_t* adr);
/*************************/
// CONSTANTS
const std::string PRE = "[B15F] ";
constexpr static uint8_t MSG_OK = 0xFF;
constexpr static uint8_t MSG_FAIL = 0xFE;
constexpr static uint16_t RECONNECT_TIMEOUT = 64;
constexpr static uint16_t WDT_TIMEOUT = 15;
constexpr static uint8_t RECONNECT_TRIES = 3;
constexpr static uint32_t BAUDRATE = 57600;
private:
void init(void);
USART usart;
static B15F* instance;
static errorhandler_t errorhandler;
// REQUESTS
constexpr static uint8_t RQ_DISC = 0;
constexpr static uint8_t RQ_TEST = 1;
constexpr static uint8_t RQ_INFO = 2;
constexpr static uint8_t RQ_INT = 3;
constexpr static uint8_t RQ_ST = 4;
constexpr static uint8_t RQ_BA0 = 5;
constexpr static uint8_t RQ_BA1 = 6;
constexpr static uint8_t RQ_BE0 = 7;
constexpr static uint8_t RQ_BE1 = 8;
constexpr static uint8_t RQ_DSW = 9;
constexpr static uint8_t RQ_AA0 = 10;
constexpr static uint8_t RQ_AA1 = 11;
constexpr static uint8_t RQ_ADC = 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_REG = 16;
constexpr static uint8_t RQ_GET_REG = 17;
};
#endif // B15F_H
B15F::exec
static std::string exec(std::string cmd)
Definition: b15f.cpp:451
B15F::MSG_FAIL
constexpr static uint8_t MSG_FAIL
Value to reject a received command.
Definition: b15f.h:239
B15F::delay_us
void delay_us(uint16_t us)
Definition: b15f.cpp:437
B15F::digitalRead0
uint8_t digitalRead0(void)
Definition: b15f.cpp:207
B15F::pwmSetFrequency
uint8_t pwmSetFrequency(uint32_t freq)
Definition: b15f.cpp:359
B15F::analogSequence
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)
Definition: b15f.cpp:302
B15F::testConnection
bool testConnection(void)
Definition: b15f.cpp:95
B15F::readDipSwitch
uint8_t readDipSwitch(void)
Definition: b15f.cpp:235
B15F::getRegister
uint8_t getRegister(volatile uint8_t *adr)
Definition: b15f.cpp:414
B15F::delay_ms
void delay_ms(uint16_t ms)
Definition: b15f.cpp:432
B15F::getInstance
static B15F & getInstance(void)
Definition: b15f.cpp:442
B15F
Definition: b15f.h:31
B15F::abort
static void abort(std::string msg)
Definition: b15f.cpp:467
USART
Definition: usart.h:16
B15F::analogRead
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:279
B15F::digitalWrite0
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:179
B15F::PRE
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:237
B15F::activateSelfTestMode
bool activateSelfTestMode(void)
Definition: b15f.cpp:166
B15F::getBoardInfo
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:134
B15F::RECONNECT_TIMEOUT
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:240
B15F::analogWrite1
bool analogWrite1(uint16_t port)
Definition: b15f.cpp:264
B15F::digitalWrite1
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:193
B15F::pwmSetValue
bool pwmSetValue(uint8_t value)
Definition: b15f.cpp:379
B15F::discard
void discard(void)
Definition: b15f.cpp:72
B15F::setRegister
bool setRegister(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:396
B15F::MSG_OK
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:238
B15F::digitalRead1
uint8_t digitalRead1(void)
Definition: b15f.cpp:221
B15F::WDT_TIMEOUT
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:241
B15F::reconnect
void reconnect(void)
Definition: b15f.cpp:57
B15F::BAUDRATE
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:243
B15F::setAbortHandler
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:485
B15F::analogWrite0
bool analogWrite0(uint16_t port)
Definition: b15f.cpp:249
B15F::RECONNECT_TRIES
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:242
B15F::testIntConv
bool testIntConv(void)
Definition: b15f.cpp:114