Lauffaehig, aber unzuverlaessig

This commit is contained in:
Tristan Krause 2019-03-29 13:35:06 +01:00
parent 32cd811744
commit 01f1fa844f
8 changed files with 76 additions and 75 deletions

View file

@ -15,6 +15,7 @@ void B15F::init()
usart.openDevice(SERIAL_DEVICE); usart.openDevice(SERIAL_DEVICE);
std::cout << "OK" << std::endl; std::cout << "OK" << std::endl;
delay_ms(1); delay_ms(1);
std::cout << PRE << "Teste Verbindung... " << std::flush; std::cout << PRE << "Teste Verbindung... " << std::flush;
@ -39,7 +40,6 @@ void B15F::init()
// Gib board info aus // Gib board info aus
std::vector<std::string> info = getBoardInfo(); std::vector<std::string> info = getBoardInfo();
std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl; std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl;
} }
void B15F::reconnect() void B15F::reconnect()
@ -123,7 +123,7 @@ std::vector<std::string> B15F::getBoardInfo(void)
uint8_t aw = usart.readByte(); uint8_t aw = usart.readByte();
if(aw != MSG_OK) if(aw != MSG_OK)
throw DriverException("Board Info fehlerhalft"); throw DriverException("Board Info fehlerhalft: code " + std::to_string((int) aw));
return info; return info;
} }
@ -185,6 +185,9 @@ uint16_t B15F::analogRead(uint8_t channel)
bool B15F::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) bool B15F::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)
{ {
buffer_a += offset_a;
buffer_b += offset_b;
usart.writeByte(RQ_ADC_DAC_STROKE); usart.writeByte(RQ_ADC_DAC_STROKE);
usart.writeByte(channel_a); usart.writeByte(channel_a);
usart.writeByte(channel_b); usart.writeByte(channel_b);
@ -198,20 +201,22 @@ bool B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset
throw DriverException("Out of sync"); throw DriverException("Out of sync");
} }
uint8_t block[5]; // 4 Datenbyte + crc //uint8_t block[5]; // 4 Datenbyte + crc
for(uint16_t i = 0; i < count; i++) for(uint16_t i = 0; i < count; i++)
{ {
bool crc_ok = usart.readBlock(&block[0], 0); /*bool crc_ok = usart.readBlock(&block[0], 0);
if (!crc_ok) if (!crc_ok)
{ {
std::cout << PRE << "bad crc" << std::endl; std::cout << PRE << "bad crc" << std::endl;
return analogSequence(channel_a, buffer_a, offset_a, channel_b, buffer_b, offset_b, start, delta, count); return analogSequence(channel_a, buffer_a, offset_a, channel_b, buffer_b, offset_b, start, delta, count);
} }*/
buffer_a[i] = usart.readInt();
buffer_b[i] = usart.readInt();
//std::cout << buffer_a[i] << " - " << buffer_b[i] << std::endl;
/*buffer_a[i] = ((uint16_t) block[0]) | (((uint16_t) block[1]) << 8);
buffer_a[offset_a + i] = ((uint16_t) block[0]) | (((uint16_t) block[1]) << 8); buffer_b[i] = ((uint16_t) block[2]) | (((uint16_t) block[3]) << 8);*/
buffer_b[offset_b + i] = ((uint16_t) block[2]) | (((uint16_t) block[3]) << 8);
} }
aw = usart.readByte(); aw = usart.readByte();

Binary file not shown.

View file

@ -51,6 +51,7 @@ void USART::clearOutputBuffer()
void USART::writeByte(uint8_t b) void USART::writeByte(uint8_t b)
{ {
//std::cout << "write(): " << (int) b << std::endl;
if(write(file_desc, &b, 1) != 1) if(write(file_desc, &b, 1) != 1)
throw USARTException("Fehler beim Senden: writeByte()"); throw USARTException("Fehler beim Senden: writeByte()");
} }
@ -60,6 +61,38 @@ void USART::writeInt(uint16_t d)
if(write(file_desc, reinterpret_cast<char*>(&d), 2) != 2) if(write(file_desc, reinterpret_cast<char*>(&d), 2) != 2)
throw USARTException("Fehler beim Senden: writeInt()"); throw USARTException("Fehler beim Senden: writeInt()");
} }
void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len)
{
buffer += offset;
uint8_t crc = 0;
writeByte(len);
while(len--)
{
writeByte(*buffer);
crc ^= *buffer;
for (uint8_t i = 0; i < 8; i++)
{
if (crc & 1)
crc ^= CRC7_POLY;
crc >>= 1;
}
buffer++;
}
writeByte(crc);
writeByte(0x80); // Stoppzeichen für Block
uint8_t aw = readByte();
if(aw != 0xFF)
{
std::cout << "Ende Gelände" << std::endl;
}
}
uint8_t USART::readByte(void) uint8_t USART::readByte(void)
{ {

View file

@ -65,8 +65,19 @@ public:
*/ */
void writeInt(uint16_t d); void writeInt(uint16_t d);
/**
* Empfängt ein Byte über die USART Schnittstelle
* \throws USARTException
*/
uint8_t readByte(void); uint8_t readByte(void);
/**
* Empfängt ein Integer über die USART Schnittstelle
* \throws USARTException
*/
uint16_t readInt(void); uint16_t readInt(void);
void writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len);
bool readBlock(uint8_t* buffer, uint16_t offset); bool readBlock(uint8_t* buffer, uint16_t offset);
/*************************************/ /*************************************/

Binary file not shown.

BIN
main

Binary file not shown.

View file

@ -108,86 +108,38 @@ void kennlinieZweiterQuadrant()
pf.startPlotty("test_plot"); pf.startPlotty("test_plot");
} }
void beispielFunktionen() void testFunktionen()
{ {
B15F& drv = B15F::getInstance(); B15F& drv = B15F::getInstance();
for(uint16_t i = 0; i < 256; i++) drv.digitalWrite0(0xFF);
{ drv.analogWrite0(128);
drv.digitalWrite0(i); std::cout << (int) drv.digitalRead0() << std::endl;;
drv.delay_ms(100); std::cout << "adc: " << (int) drv.analogRead(4) << std::endl;
}
drv.digitalWrite0(0x00);
drv.analogWrite0(0);
std::cout << (int) drv.digitalRead0() << std::endl;;
std::cout << "adc: " << (int) drv.analogRead(4) << std::endl;
drv.digitalWrite0(0xFF);
drv.analogWrite0(255);
std::cout << (int) drv.digitalRead0() << std::endl;
std::cout << "adc: " << (int) drv.analogRead(4) << std::endl;
uint16_t a[1024];
uint16_t b[1024];
drv.analogSequence(0, &a[0], 0, 1, &b[0], 0, 0, 1, 1024);
while(1)
{
for(double d = 0; d < M_PI*2; d += .1)
{
uint16_t v = (sin(d) * 511 + 511);
drv.analogWrite0(v);
}
}
uint16_t schwelle_unten = 1023;
for(uint16_t i = 0; i < 1024; i++)
{
drv.analogWrite0(i);
drv.delay_ms(1);
if(drv.digitalRead0() & 0x01)
{
drv.discard();
uint16_t val = drv.analogRead(0);
if(val > 1023)
{
std::cout << "Fehler: " << val << std::endl;
continue;
}
if(val < schwelle_unten)
schwelle_unten = val;
}
}
std::cout << "OK" << std::endl;
uint16_t schwelle_oben = 0;
for(uint16_t i = 1023; i > 0; i--)
{
drv.analogWrite0(i);
if(!(drv.digitalRead0() & 0x01))
{
drv.discard();
uint16_t val = drv.analogRead(0);
if(val > 1023)
{
std::cout << "Fehler: " << val << std::endl;
continue;
}
if(val > schwelle_oben)
schwelle_oben = val;
}
}
std::cout << "Schwelle für low: " << schwelle_unten << std::endl;
std::cout << "Schwelle für high: " << schwelle_oben << std::endl;
std::cout << "Verbotene Zone: " << (schwelle_oben - schwelle_unten) << std::endl;
} }
int main() int main()
{ {
beispielFunktionen(); kennlinieZweiterQuadrant();
//USART usart;
//usart.openDevice("/dev/ttyUSB0");
//usart.writeByte(5);
std::cout << "Schluss." << std::endl; std::cout << "Schluss." << std::endl;
} }

BIN
main.o

Binary file not shown.