b15f/drv/b15f.h

87 lines
2.2 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-26 10:35:20 +00:00
#include "driverexception.h"
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-27 09:33:16 +00:00
bool digitaleAusgabe0(uint8_t);
bool digitaleAusgabe1(uint8_t);
uint8_t digitaleEingabe0(void);
uint8_t digitaleEingabe1(void);
bool analogeAusgabe0(uint16_t);
bool analogeAusgabe1(uint16_t);
uint16_t analogeEingabe(uint8_t);
2019-03-27 09:49:08 +00:00
bool analogEingabeSequenz(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
// Serielle Verbindung
2019-03-26 12:28:29 +00:00
inline void writeByte(uint8_t);
inline void writeInt(uint16_t);
inline uint8_t readByte(void);
inline uint16_t readInt(void);
2019-03-28 14:22:06 +00:00
inline bool readBlock(uint8_t* buffer, uint16_t offset);
2019-03-26 12:28:29 +00:00
2019-03-26 10:35:20 +00:00
2019-03-26 15:27:21 +00:00
void delay(uint16_t);
2019-03-26 08:57:01 +00:00
static B15F& getInstance(void);
private:
2019-03-26 12:28:29 +00:00
int usart = -1;
2019-03-28 14:22:06 +00:00
uint16_t timeout = 200; // ms
uint16_t block_timeout = 1; // ms
2019-03-26 10:35:20 +00:00
2019-03-26 08:57:01 +00:00
static B15F* instance;
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-27 10:45:14 +00:00
constexpr static uint32_t BAUDRATE = 115200;
2019-03-28 14:22:06 +00:00
constexpr static uint8_t CRC7_POLY = 0x91;
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