save bevor debug
This commit is contained in:
parent
2a8e3061db
commit
c1564064ac
13
drv/b15f.cpp
13
drv/b15f.cpp
|
@ -4,6 +4,7 @@ B15F* B15F::instance = nullptr;
|
||||||
|
|
||||||
B15F::B15F()
|
B15F::B15F()
|
||||||
{
|
{
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void B15F::init()
|
void B15F::init()
|
||||||
|
@ -262,7 +263,7 @@ uint16_t B15F::analogRead(uint8_t channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool B15F::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)
|
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)
|
||||||
{
|
{
|
||||||
|
|
||||||
discard();
|
discard();
|
||||||
|
@ -280,10 +281,10 @@ bool B15F::analogEingabeSequenz(uint8_t channel_a, uint16_t* buffer_a, uint32_t
|
||||||
if(aw != MSG_OK)
|
if(aw != MSG_OK)
|
||||||
{
|
{
|
||||||
std::cout << PRE << "Out of sync" << std::endl;
|
std::cout << PRE << "Out of sync" << std::endl;
|
||||||
return analogEingabeSequenz(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t block[4];
|
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 = readBlock(&block[0], 0);
|
bool crc_ok = readBlock(&block[0], 0);
|
||||||
|
@ -291,7 +292,7 @@ bool B15F::analogEingabeSequenz(uint8_t channel_a, uint16_t* buffer_a, uint32_t
|
||||||
if (!crc_ok)
|
if (!crc_ok)
|
||||||
{
|
{
|
||||||
std::cout << PRE << "bad crc" << std::endl;
|
std::cout << PRE << "bad crc" << std::endl;
|
||||||
return analogEingabeSequenz(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -304,12 +305,12 @@ bool B15F::analogEingabeSequenz(uint8_t channel_a, uint16_t* buffer_a, uint32_t
|
||||||
return aw;
|
return aw;
|
||||||
|
|
||||||
std::cout << PRE << "Da ging etwas verloren" << std::endl;
|
std::cout << PRE << "Da ging etwas verloren" << std::endl;
|
||||||
return analogEingabeSequenz(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);
|
||||||
}
|
}
|
||||||
catch(DriverException& de)
|
catch(DriverException& de)
|
||||||
{
|
{
|
||||||
reconnect();
|
reconnect();
|
||||||
return analogEingabeSequenz(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
bool analogWrite0(uint16_t);
|
bool analogWrite0(uint16_t);
|
||||||
bool analogWrite1(uint16_t);
|
bool analogWrite1(uint16_t);
|
||||||
uint16_t analogRead(uint8_t);
|
uint16_t analogRead(uint8_t);
|
||||||
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);
|
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);
|
||||||
|
|
||||||
// Serielle Verbindung
|
// Serielle Verbindung
|
||||||
inline void writeByte(uint8_t);
|
inline void writeByte(uint8_t);
|
||||||
|
@ -53,7 +53,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int usart = -1;
|
int usart = -1;
|
||||||
uint16_t timeout = 32; // ms
|
uint16_t timeout = 100; // ms
|
||||||
uint16_t block_timeout = 1; // ms
|
uint16_t block_timeout = 1; // ms
|
||||||
int TEST = 0;
|
int TEST = 0;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ private:
|
||||||
constexpr static uint8_t MSG_FAIL = 0xFE;
|
constexpr static uint8_t MSG_FAIL = 0xFE;
|
||||||
constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms
|
constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms
|
||||||
constexpr static uint8_t RECONNECT_TRIES = 3;
|
constexpr static uint8_t RECONNECT_TRIES = 3;
|
||||||
constexpr static uint32_t BAUDRATE = 115200;
|
constexpr static uint32_t BAUDRATE = 38400;
|
||||||
constexpr static uint8_t CRC7_POLY = 0x91;
|
constexpr static uint8_t CRC7_POLY = 0x91;
|
||||||
|
|
||||||
// REQUESTS
|
// REQUESTS
|
||||||
|
|
BIN
drv/b15f.o
BIN
drv/b15f.o
Binary file not shown.
|
@ -189,3 +189,10 @@ void PlottyFile::writeToFile(std::string filename)
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlottyFile::startPlotty(std::string filename)
|
||||||
|
{
|
||||||
|
int code = system(("./plotty --in " + filename).c_str());
|
||||||
|
if(code)
|
||||||
|
throw std::runtime_error("Fehler beim Aufruf von plotty");
|
||||||
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
std::string getDescPara(void) const;
|
std::string getDescPara(void) const;
|
||||||
|
|
||||||
void writeToFile(std::string filename);
|
void writeToFile(std::string filename);
|
||||||
|
void startPlotty(std::string filename);
|
||||||
private:
|
private:
|
||||||
void prepStr(std::string& str, uint8_t len);
|
void prepStr(std::string& str, uint8_t len);
|
||||||
|
|
||||||
|
|
BIN
drv/plottyfile.o
BIN
drv/plottyfile.o
Binary file not shown.
89
main.cpp
89
main.cpp
|
@ -2,11 +2,11 @@
|
||||||
#include "drv/b15f.h"
|
#include "drv/b15f.h"
|
||||||
#include "drv/plottyfile.h"
|
#include "drv/plottyfile.h"
|
||||||
|
|
||||||
PlottyFile pf;
|
|
||||||
|
|
||||||
void kennlinieErsterQuadrant()
|
void kennlinieErsterQuadrant()
|
||||||
{
|
{
|
||||||
B15F& drv = B15F::getInstance();
|
B15F& drv = B15F::getInstance();
|
||||||
|
PlottyFile pf;
|
||||||
|
|
||||||
uint16_t ba[1024];
|
uint16_t ba[1024];
|
||||||
uint16_t bb[1024];
|
uint16_t bb[1024];
|
||||||
|
@ -34,7 +34,7 @@ void kennlinieErsterQuadrant()
|
||||||
{
|
{
|
||||||
drv.analogWrite1(u_gs);
|
drv.analogWrite1(u_gs);
|
||||||
|
|
||||||
drv.analogEingabeSequenz(0, &ba[0], 0, 1, &bb[0], 0, 0, delta, sample_count);
|
drv.analogSequence(0, &ba[0], 0, 1, &bb[0], 0, 0, delta, sample_count);
|
||||||
drv.delay(10);
|
drv.delay(10);
|
||||||
drv.discard();
|
drv.discard();
|
||||||
drv.delay(10);
|
drv.delay(10);
|
||||||
|
@ -48,11 +48,16 @@ void kennlinieErsterQuadrant()
|
||||||
|
|
||||||
curve++;
|
curve++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// speichern und plotty starten
|
||||||
|
pf.writeToFile("test_plot");
|
||||||
|
pf.startPlotty("test_plot");
|
||||||
}
|
}
|
||||||
|
|
||||||
void kennlinieZweiterQuadrant()
|
void kennlinieZweiterQuadrant()
|
||||||
{
|
{
|
||||||
B15F& drv = B15F::getInstance();
|
B15F& drv = B15F::getInstance();
|
||||||
|
PlottyFile pf;
|
||||||
|
|
||||||
uint16_t ba[1024];
|
uint16_t ba[1024];
|
||||||
uint16_t bb[1024];
|
uint16_t bb[1024];
|
||||||
|
@ -81,7 +86,7 @@ void kennlinieZweiterQuadrant()
|
||||||
{
|
{
|
||||||
drv.analogWrite1(u_gs);
|
drv.analogWrite1(u_gs);
|
||||||
|
|
||||||
drv.analogEingabeSequenz(0, &ba[0], 0, 1, &bb[0], 0, 0, delta, sample_count);
|
drv.analogSequence(0, &ba[0], 0, 1, &bb[0], 0, 0, delta, sample_count);
|
||||||
|
|
||||||
curve = 0;
|
curve = 0;
|
||||||
for(uint16_t k = 0; k < sample_count + 1; k++)
|
for(uint16_t k = 0; k < sample_count + 1; k++)
|
||||||
|
@ -95,28 +100,74 @@ void kennlinieZweiterQuadrant()
|
||||||
}
|
}
|
||||||
std::cout << "u_gs: " << u_gs << std::endl;
|
std::cout << "u_gs: " << u_gs << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// speichern und plotty starten
|
||||||
|
pf.writeToFile("test_plot");
|
||||||
|
pf.startPlotty("test_plot");
|
||||||
|
}
|
||||||
|
|
||||||
|
void beispielFunktionen()
|
||||||
|
{
|
||||||
|
B15F& drv = B15F::getInstance();
|
||||||
|
|
||||||
|
/*
|
||||||
|
for(uint16_t i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
drv.digitalWrite0(i);
|
||||||
|
drv.delay(50);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
uint16_t schwelle_unten = 1023;
|
||||||
|
for(uint16_t i = 0; i < 1024; i++)
|
||||||
|
{
|
||||||
|
drv.analogWrite0(i);
|
||||||
|
drv.delay(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);
|
||||||
|
drv.delay(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_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()
|
||||||
{
|
{
|
||||||
B15F& drv = B15F::getInstance();
|
|
||||||
drv.init();
|
|
||||||
|
|
||||||
int n = 0;
|
beispielFunktionen();
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
uint16_t ba[1024];
|
|
||||||
uint16_t bb[1024];
|
|
||||||
drv.analogEingabeSequenz(0, &ba[0], 0, 1, &bb[0], 0, 0, 1, 1023);
|
|
||||||
|
|
||||||
std::cout << n++ << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// speichern und plotty starten
|
|
||||||
pf.writeToFile("test_plot");
|
|
||||||
int code = system("./plotty --in test_plot");
|
|
||||||
if(code)
|
|
||||||
std::cout << "Fehler beim plotty Aufruf" << std::endl;
|
|
||||||
|
|
||||||
std::cout << "Schluss." << std::endl;
|
std::cout << "Schluss." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue