auto reconnect
This commit is contained in:
parent
8cbd8a1a12
commit
a3e9e1ce27
139
drv/b15f.cpp
139
drv/b15f.cpp
|
@ -48,16 +48,41 @@ void B15F::init()
|
|||
|
||||
while(1)
|
||||
{
|
||||
for(uint16_t i = 0; i < 1024; )
|
||||
digitaleAusgabe0(0xFF);
|
||||
digitaleAusgabe0(0x00);
|
||||
//analogeEingabe(0);
|
||||
/*for(uint16_t i = 0; i < 1024; )
|
||||
{
|
||||
i = analogeEingabe(0);
|
||||
analogeAusgabe0(i);
|
||||
delay(0);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void B15F::reconnect()
|
||||
{
|
||||
std::cout << PRE << "Verbindung unterbrochen, stelle Verbindung neu her: " << std::flush;
|
||||
|
||||
uint8_t tries = RECONNECT_TRIES;
|
||||
while(tries--)
|
||||
{
|
||||
delay(RECONNECT_TIMEOUT);
|
||||
|
||||
discard();
|
||||
|
||||
if(testConnection())
|
||||
{
|
||||
std::cout << "OK" << std::endl << std::flush;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
throw DriverException("Verbindung kann nicht repariert werden");
|
||||
}
|
||||
|
||||
void B15F::discard(void)
|
||||
{
|
||||
for(uint8_t i = 0; i < 8; i++)
|
||||
|
@ -99,57 +124,113 @@ bool B15F::testIntConv()
|
|||
|
||||
bool B15F::digitaleAusgabe0(uint8_t port)
|
||||
{
|
||||
writeByte(RQ_BA0);
|
||||
writeByte(port);
|
||||
|
||||
uint8_t aw = readByte();
|
||||
return aw == MSG_OK;
|
||||
try
|
||||
{
|
||||
writeByte(RQ_BA0);
|
||||
writeByte(port);
|
||||
|
||||
uint8_t aw = readByte();
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
catch(DriverException& de)
|
||||
{
|
||||
reconnect();
|
||||
return digitaleAusgabe0(port);
|
||||
}
|
||||
}
|
||||
|
||||
bool B15F::digitaleAusgabe1(uint8_t port)
|
||||
{
|
||||
writeByte(RQ_BA1);
|
||||
writeByte(port);
|
||||
|
||||
uint8_t aw = readByte();
|
||||
return aw == MSG_OK;
|
||||
try
|
||||
{
|
||||
writeByte(RQ_BA1);
|
||||
writeByte(port);
|
||||
|
||||
uint8_t aw = readByte();
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
catch(DriverException& de)
|
||||
{
|
||||
reconnect();
|
||||
return digitaleAusgabe1(port);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t B15F::digitaleEingabe0()
|
||||
{
|
||||
writeByte(RQ_BE0);
|
||||
return readByte();
|
||||
try
|
||||
{
|
||||
writeByte(RQ_BE0);
|
||||
return readByte();
|
||||
}
|
||||
catch(DriverException& de)
|
||||
{
|
||||
reconnect();
|
||||
return digitaleEingabe0();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t B15F::digitaleEingabe1()
|
||||
{
|
||||
writeByte(RQ_BE1);
|
||||
return readByte();
|
||||
try
|
||||
{
|
||||
writeByte(RQ_BE1);
|
||||
return readByte();
|
||||
}
|
||||
catch(DriverException& de)
|
||||
{
|
||||
reconnect();
|
||||
return digitaleEingabe1();
|
||||
}
|
||||
}
|
||||
|
||||
bool B15F::analogeAusgabe0(uint16_t value)
|
||||
{
|
||||
writeByte(RQ_AA0);
|
||||
writeInt(value);
|
||||
|
||||
uint8_t aw = readByte();
|
||||
return aw == MSG_OK;
|
||||
try
|
||||
{
|
||||
writeByte(RQ_AA0);
|
||||
writeInt(value);
|
||||
|
||||
uint8_t aw = readByte();
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
catch(DriverException& de)
|
||||
{
|
||||
reconnect();
|
||||
return analogeAusgabe0(value);
|
||||
}
|
||||
}
|
||||
|
||||
bool B15F::analogeAusgabe1(uint16_t value)
|
||||
{
|
||||
writeByte(RQ_AA1);
|
||||
writeInt(value);
|
||||
|
||||
uint8_t aw = readByte();
|
||||
return aw == MSG_OK;
|
||||
try
|
||||
{
|
||||
writeByte(RQ_AA1);
|
||||
writeInt(value);
|
||||
|
||||
uint8_t aw = readByte();
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
catch(DriverException& de)
|
||||
{
|
||||
reconnect();
|
||||
return analogeAusgabe1(value);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t B15F::analogeEingabe(uint8_t channel)
|
||||
{
|
||||
writeByte(RQ_ADC);
|
||||
writeByte(channel);
|
||||
return readInt();
|
||||
try
|
||||
{
|
||||
writeByte(RQ_ADC);
|
||||
writeByte(channel);
|
||||
return readInt();
|
||||
}
|
||||
catch(DriverException& de)
|
||||
{
|
||||
reconnect();
|
||||
return analogeEingabe(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ private:
|
|||
public:
|
||||
// Grundfunktionen
|
||||
void init(void);
|
||||
void reconnect(void);
|
||||
void discard(void);
|
||||
bool testConnection(void);
|
||||
bool testIntConv(void);
|
||||
|
@ -57,6 +58,8 @@ private:
|
|||
const std::string SERIAL_DEVICE = "/dev/ttyUSB0";
|
||||
constexpr static uint8_t MSG_OK = 0xFF;
|
||||
constexpr static uint8_t MSG_FAIL = 0xFE;
|
||||
constexpr static uint16_t RECONNECT_TIMEOUT = 32; // ms
|
||||
constexpr static uint8_t RECONNECT_TRIES = 3;
|
||||
|
||||
// REQUESTS
|
||||
constexpr static uint8_t RQ_DISC = 0;
|
||||
|
|
BIN
drv/b15f.o
BIN
drv/b15f.o
Binary file not shown.
Loading…
Reference in a new issue