b15f/drv/b15f.h

96 lines
2.3 KiB
C
Raw Normal View History

2019-03-28 14:22:06 +00:00
#ifndef B15F_H
#define B15F_H
2019-03-26 08:57:01 +00:00
#include <iostream>
2019-03-26 10:35:20 +00:00
#include <bits/stdc++.h>
#include <string>
#include <fstream>
#include <cstdlib>
2019-03-26 12:28:29 +00:00
#include <chrono>
2019-03-26 10:35:20 +00:00
#include <cstdint>
2019-03-27 14:48:24 +00:00
#include <vector>
2019-03-26 10:35:20 +00:00
#include <unistd.h>
2019-03-26 12:28:29 +00:00
#include <fcntl.h>
2019-03-28 12:45:16 +00:00
#include <sys/ioctl.h>
2019-03-26 12:28:29 +00:00
#include <termios.h>
2019-03-29 10:38:11 +00:00
#include "usart.h"
2019-03-26 10:35:20 +00:00
#include "driverexception.h"
2019-03-29 10:12:31 +00:00
#include "timeoutexception.h"
2019-03-26 10:35:20 +00:00
2019-03-26 08:57:01 +00:00
class B15F
{
private:
B15F(void); // privater Konstruktor
public:
2019-03-26 15:27:21 +00:00
// Grundfunktionen
2019-03-26 08:57:01 +00:00
void init(void);
2019-03-27 08:18:21 +00:00
void reconnect(void);
2019-03-26 14:02:41 +00:00
void discard(void);
2019-03-26 10:35:20 +00:00
bool testConnection(void);
2019-03-26 14:02:41 +00:00
bool testIntConv(void);
2019-03-27 14:48:24 +00:00
std::vector<std::string> getBoardInfo(void);
2019-03-26 12:28:29 +00:00
2019-03-26 15:27:21 +00:00
// Board Befehle
2019-03-28 15:04:38 +00:00
bool digitalWrite0(uint8_t);
bool digitalWrite1(uint8_t);
uint8_t digitalRead0(void);
uint8_t digitalRead1(void);
bool analogWrite0(uint16_t);
bool analogWrite1(uint16_t);
uint16_t analogRead(uint8_t);
2019-03-29 07:32:11 +00:00
bool 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);
2019-03-26 15:27:21 +00:00
2019-03-29 10:12:31 +00:00
/**
* Lässt den Treiber für eine angegebene Zeit pausieren
* \param ms Verzögerung in Millisekunden
*/
void delay_ms(uint16_t ms);
2019-03-26 12:28:29 +00:00
2019-03-29 10:12:31 +00:00
/**
* Lässt den Treiber für eine angegebene Zeit pausieren
* \param us Verzögerung in Microsekunden
*/
void delay_us(uint16_t us);
2019-03-26 10:35:20 +00:00
2019-03-29 10:12:31 +00:00
/**
* Liefert eine Referenz zur aktuellen Treiber-Instanz
* @throws DriverException
*/
2019-03-26 08:57:01 +00:00
static B15F& getInstance(void);
private:
2019-03-29 10:12:31 +00:00
uint16_t timeout = 1000; // ms
2019-03-28 14:22:06 +00:00
uint16_t block_timeout = 1; // ms
2019-03-29 10:38:11 +00:00
USART usart;
2019-03-26 10:35:20 +00:00
2019-03-26 08:57:01 +00:00
static B15F* instance;
2019-03-29 10:12:31 +00:00
2019-03-26 10:35:20 +00:00
2019-03-26 15:27:21 +00:00
// CONSTANTS
2019-03-26 12:28:29 +00:00
const std::string PRE = "[B15F] ";
2019-03-26 10:35:20 +00:00
const std::string SERIAL_DEVICE = "/dev/ttyUSB0";
2019-03-28 14:22:06 +00:00
constexpr static uint8_t MSG_OK = 0xFF;
constexpr static uint8_t MSG_FAIL = 0xFE;
constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms
constexpr static uint8_t RECONNECT_TRIES = 3;
2019-03-29 10:12:31 +00:00
constexpr static uint32_t BAUDRATE = 115200;
2019-03-26 14:02:41 +00:00
2019-03-26 15:27:21 +00:00
// REQUESTS
2019-03-26 14:02:41 +00:00
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;
2019-03-26 15:27:21 +00:00
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_AA0 = 9;
constexpr static uint8_t RQ_AA1 = 10;
constexpr static uint8_t RQ_ADC = 11;
2019-03-27 09:33:16 +00:00
constexpr static uint8_t RQ_ADC_DAC_STROKE = 12;
2019-03-26 08:57:01 +00:00
};
2019-03-28 14:22:06 +00:00
#endif // B15F_H