io Funktionen ok

This commit is contained in:
Tristan Krause 2019-03-26 16:27:21 +01:00
parent 95015a030e
commit 8cbd8a1a12
4 changed files with 97 additions and 17 deletions

View file

@ -35,17 +35,26 @@ void B15F::init()
// Verbindungstest muss dreimal erfolgreich sein
std::cout << PRE << "Teste Verbindung... " << std::flush;
for(uint8_t i = 0; i < 3; i++)
{
if(!testConnection())
{
throw DriverException("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
}
}
std::cout << "OK" << std::endl;
std::cout << "int: " << testIntConv() << std::endl;
std::cout << "int: " << testIntConv() << std::endl;
std::cout << "int: " << testIntConv() << std::endl;
std::cout << PRE << "Teste Integer Konvertierung... " << std::flush;
for(uint8_t i = 0; i < 3; i++)
if(!testIntConv())
throw DriverException("Konvertierung fehlgeschlagen.");
std::cout << "OK" << std::endl;
while(1)
{
for(uint16_t i = 0; i < 1024; )
{
i = analogeEingabe(0);
analogeAusgabe0(i);
delay(0);
}
}
}
@ -86,6 +95,65 @@ bool B15F::testIntConv()
return aw == dummy * 3;
}
bool B15F::digitaleAusgabe0(uint8_t port)
{
writeByte(RQ_BA0);
writeByte(port);
uint8_t aw = readByte();
return aw == MSG_OK;
}
bool B15F::digitaleAusgabe1(uint8_t port)
{
writeByte(RQ_BA1);
writeByte(port);
uint8_t aw = readByte();
return aw == MSG_OK;
}
uint8_t B15F::digitaleEingabe0()
{
writeByte(RQ_BE0);
return readByte();
}
uint8_t B15F::digitaleEingabe1()
{
writeByte(RQ_BE1);
return readByte();
}
bool B15F::analogeAusgabe0(uint16_t value)
{
writeByte(RQ_AA0);
writeInt(value);
uint8_t aw = readByte();
return aw == MSG_OK;
}
bool B15F::analogeAusgabe1(uint16_t value)
{
writeByte(RQ_AA1);
writeInt(value);
uint8_t aw = readByte();
return aw == MSG_OK;
}
uint16_t B15F::analogeEingabe(uint8_t channel)
{
writeByte(RQ_ADC);
writeByte(channel);
return readInt();
}
void B15F::writeByte(uint8_t b)
{
if(write(usart, &b, 1) != 1)
@ -109,13 +177,6 @@ uint8_t B15F::readByte()
int n = read(usart, &b, 1);
if (n > 0)
return static_cast<uint8_t>(b);
/*else if(n < -1)
{
std::string msg = "Fehler bei der seriellen Verbindung. (Code: ";
msg += std::to_string(n);
msg += ")";
throw DriverException(msg);
}*/
end = std::chrono::steady_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();

View file

@ -19,18 +19,30 @@ class B15F
private:
B15F(void); // privater Konstruktor
public:
// Grundfunktionen
void init(void);
void discard(void);
bool testConnection(void);
bool testIntConv(void);
// Board Befehle
inline bool digitaleAusgabe0(uint8_t);
inline bool digitaleAusgabe1(uint8_t);
inline uint8_t digitaleEingabe0(void);
inline uint8_t digitaleEingabe1(void);
inline bool analogeAusgabe0(uint16_t);
inline bool analogeAusgabe1(uint16_t);
inline uint16_t analogeEingabe(uint8_t);
// Serielle Verbindung
inline void writeByte(uint8_t);
inline void writeInt(uint16_t);
inline uint8_t readByte(void);
inline uint16_t readInt(void);
void delay(uint16_t);
void delay(uint16_t);
static B15F& getInstance(void);
private:
@ -40,17 +52,24 @@ private:
static B15F* instance;
// CONSTANTS
// CONSTANTS
const std::string PRE = "[B15F] ";
const std::string SERIAL_DEVICE = "/dev/ttyUSB0";
constexpr static uint8_t MSG_OK = 0xFF;
constexpr static uint8_t MSG_FAIL = 0xFE;
// REQUESTS
// 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_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;
};
#endif // B15F_h

Binary file not shown.

BIN
main

Binary file not shown.