plottyfile done

This commit is contained in:
Tristan Krause 2019-03-28 09:38:35 +01:00
parent 71b156aa6f
commit f59e1d4de8
13 changed files with 235 additions and 64 deletions

View file

@ -1,7 +1,9 @@
#include "dot.h"
Dot::Dot(uint16_t x, uint16_t y, DotColor color) : x(x), y(y), color(color)
Dot::Dot(uint16_t x, uint16_t y, uint8_t curve) : x(x), y(y), curve(curve)
{
if(curve >= 64)
throw std::range_error("Kurvenindex muss im Bereich [0, 63] liegen");
}
uint16_t Dot::getX() const
@ -14,7 +16,7 @@ uint16_t Dot::getY() const
return y;
}
DotColor Dot::getColor(void) const
uint8_t Dot::getCurve(void) const
{
return color;
return curve;
}

View file

@ -2,24 +2,19 @@
#define DOT_H
#include <cstdint>
enum DotColor
{
PURPLE = 0,
GREEN = 32,
};
#include <stdexcept>
class Dot
{
public:
Dot(uint16_t x, uint16_t y, DotColor color);
Dot(uint16_t x, uint16_t y, uint8_t curve);
uint16_t getX(void) const;
uint16_t getY(void) const;
DotColor getColor(void) const;
uint8_t getCurve(void) const;
private:
uint16_t x, y;
DotColor color;
uint8_t curve;
};

BIN
drv/dot.o

Binary file not shown.

View file

@ -5,6 +5,131 @@ void PlottyFile::addDot(Dot& dot)
dots.push_back(dot);
}
void PlottyFile::addDot(Dot dot)
{
dots.push_back(dot);
}
void PlottyFile::setFunctionType(FunctionType function_type)
{
this->function_type = function_type;
}
void PlottyFile::setQuadrant(uint8_t quadrant)
{
this->quadrant = quadrant;
}
void PlottyFile::setRefX(uint16_t ref_x)
{
this->ref_x = ref_x;
}
void PlottyFile::setRefY(uint16_t ref_y)
{
this->ref_y = ref_y;
}
void PlottyFile::setParaFirstCurve(uint16_t para_first)
{
this->para_first = para_first;
}
void PlottyFile::setParaStepWidth(uint16_t para_stepwidth)
{
this->para_stepwidth = para_stepwidth;
}
void PlottyFile::setUnitX(std::string unit_x)
{
this->unit_x = unit_x;
}
void PlottyFile::setDescX(std::string desc_x)
{
this->desc_x = desc_x;
}
void PlottyFile::setUnitY(std::string unit_y)
{
this->unit_y = unit_y;
}
void PlottyFile::setDescY(std::string desc_y)
{
this->desc_y = desc_y;
}
void PlottyFile::setUnitPara(std::string unit_para)
{
this->unit_para = unit_para;
}
void PlottyFile::setDescPara(std::string desc_para)
{
this->desc_para = desc_para;
}
FunctionType PlottyFile::getFunctionType() const
{
return function_type;
}
uint8_t PlottyFile::getQuadrant() const
{
return quadrant;
}
uint16_t PlottyFile::getRefX() const
{
return ref_x;
}
uint16_t PlottyFile::getRefY() const
{
return ref_y;
}
uint16_t PlottyFile::getParaFirstCurve() const
{
return para_first;
}
uint16_t PlottyFile::getParaStepWidth() const
{
return para_stepwidth;
}
std::string PlottyFile::getUnitX() const
{
return unit_x;
}
std::string PlottyFile::getDescX() const
{
return desc_x;
}
std::string PlottyFile::getUnitY() const
{
return unit_y;
}
std::string PlottyFile::getDescY() const
{
return desc_y;
}
std::string PlottyFile::getUnitPara() const
{
return unit_para;
}
std::string PlottyFile::getDescPara() const
{
return desc_para;
}
void PlottyFile::prepStr(std::string& str, uint8_t len)
{
if(str.length() > len)
@ -18,41 +143,23 @@ void PlottyFile::prepStr(std::string& str, uint8_t len)
}
void PlottyFile::writeToFile(std::string filename)
{
command = 0x1D;
title = "HTWK-HWLab";
filetype = "MD";
version = 1;
subversion = 0;
function_type = 'C';
quadrant = 1;
ref_x = 5000;
ref_y = 50;
para_first = 1;
para_stepwidth = 1;
unit_x = "Unit X";
desc_x = "Desc X";
unit_y = "Unit Y";
desc_y = "Desc Y";
unit_para = "Unit P";
desc_para = "Desc P";
prepStr(title, 10);
prepStr(unit_x, 10);
prepStr(desc_x, 20);
prepStr(unit_y, 10);
prepStr(desc_y, 20);
prepStr(unit_para, 10);
prepStr(desc_para, 20);
{
prepStr(unit_x, STR_LEN_SHORT);
prepStr(desc_x, STR_LEN_LARGE);
prepStr(unit_y, STR_LEN_SHORT);
prepStr(desc_y, STR_LEN_LARGE);
prepStr(unit_para, STR_LEN_SHORT);
prepStr(desc_para, STR_LEN_LARGE);
std::ofstream file(filename);
// write file header
file.write(reinterpret_cast<char*>(&command), 1);
file.write(title.c_str(), title.length());
file.write(filetype.c_str(), 2);
file.write(head.c_str(), head.length());
file.write(filetype.c_str(), filetype.length());
file.write(reinterpret_cast<char*>(&version), 2);
file.write(reinterpret_cast<char*>(&subversion), 2);
file.write(reinterpret_cast<char*>(&function_type), 1);
file.put(static_cast<uint8_t>(function_type));
file.write(reinterpret_cast<char*>(&quadrant), 1);
file.write(reinterpret_cast<char*>(&ref_x), 2);
file.write(reinterpret_cast<char*>(&ref_y), 2);
@ -66,12 +173,13 @@ void PlottyFile::writeToFile(std::string filename)
file.write(desc_para.c_str(), desc_para.length());
file.write(reinterpret_cast<const char*>(&eof), 1);
// make sure header size is 256 Byte
while(file.tellp() < 256)
file.put(0);
for(Dot& dot : dots)
{
file.put((dot.getX() >> 8) | (static_cast<uint8_t>(dot.getColor()) << 2));
file.put((dot.getX() >> 8) | (static_cast<uint8_t>(dot.getCurve()) << 2));
file.put(dot.getX() & 0xFF);
file.put(dot.getY() >> 8);
file.put(dot.getY() & 0xFF);

View file

@ -7,27 +7,62 @@
#include <vector>
#include "dot.h"
enum FunctionType
{
CurveFamily = 'S',
Curve = 'C',
Level = 'P'
};
class PlottyFile
{
public:
void addDot(Dot& dot);
void addDot(Dot dot);
void setFunctionType(FunctionType);
void setQuadrant(uint8_t);
void setRefX(uint16_t);
void setRefY(uint16_t);
void setParaFirstCurve(uint16_t);
void setParaStepWidth(uint16_t);
void setUnitX(std::string);
void setDescX(std::string);
void setUnitY(std::string);
void setDescY(std::string);
void setUnitPara(std::string);
void setDescPara(std::string);
FunctionType getFunctionType(void) const;
uint8_t getQuadrant(void) const;
uint16_t getRefX(void) const;
uint16_t getRefY(void) const;
uint16_t getParaFirstCurve(void) const;
uint16_t getParaStepWidth(void) const;
std::string getUnitX(void) const;
std::string getDescX(void) const;
std::string getUnitY(void) const;
std::string getDescY(void) const;
std::string getUnitPara(void) const;
std::string getDescPara(void) const;
void writeToFile(std::string filename);
private:
void prepStr(std::string& str, uint8_t len);
std::vector<Dot> dots;
int8_t command;
std::string title;
std::string filetype;
int16_t version;
int16_t subversion;
uint8_t function_type;
uint8_t quadrant;
uint16_t ref_x;
uint16_t ref_y;
uint16_t para_first;
uint16_t para_stepwidth;
int8_t command = 0x1D;
const std::string head = "HTWK-HWLab";
const std::string filetype = "MD";
int16_t version = 1;
int16_t subversion = 0;
FunctionType function_type = FunctionType::Curve;
uint8_t quadrant = 1;
uint16_t ref_x = 1023;
uint16_t ref_y = 1023;
uint16_t para_first = 1;
uint16_t para_stepwidth = 1;
std::string unit_x;
std::string desc_x;
std::string unit_y;
@ -35,6 +70,9 @@ private:
std::string unit_para;
std::string desc_para;
const uint8_t eof = 0xD;
constexpr static uint8_t STR_LEN_SHORT = 10;
constexpr static uint8_t STR_LEN_LARGE = 20;
};
#endif // PLOTTYFILE_H

Binary file not shown.

View file

@ -2,12 +2,13 @@ set margin 10,10
unset key
set grid
set title ''
set xlabel 'Desc X [Unit X]'
set ylabel 'Desc Y [Unit Y]'
set xrange [0:5000]
set yrange [0:50]
set label at 4995,49 'Desc P [Unit P] = 1' left
set xlabel 'Zeit [t]'
set ylabel 'Spannung [V]'
set xrange [0:1023]
set yrange [0:1023]
set label at 1022,1022 '1' left
set label at 1022,511 '2' left
unset output
set terminal qt
unset output
plot "/tmp/tempfile32" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'Desc P [Unit P] = 1' w l
plot "/tmp/tempfile0" using ($1*1.000000):($2*1.000000) binary format="%int16%int16" endian=big title ' [] = 1' w l,"/tmp/tempfile1" using ($1*1.000000):($2*1.000000) binary format="%int16%int16" endian=big title ' [] = 2' w l

BIN
main

Binary file not shown.

View file

@ -23,16 +23,23 @@ int main()
drv.analogEingabeSequenz(1, &ba[0], 0, 0, &bb[0], 0, 1023, -1, 1023);
PlottyFile pf;
pf.setUnitX("t");
pf.setUnitY("V");
pf.setDescX("Zeit");
pf.setDescY("Spannung");
for(uint16_t i = 0; i < 1023; i++)
{
Dot d(i,i, DotColor::PURPLE);
pf.addDot(d);
pf.addDot(Dot(i,i, 0));
pf.addDot(Dot(i,i/2, 1));
}
pf.writeToFile("test_plot");
system("./plotty --in test_plot");
int code = system("./plotty --in test_plot");
if(code)
{
std::cout << "plotty konnte nicht gestarted werden" << std::endl;
}
std::cout << "Schluss." << std::endl;
}

BIN
main.o

Binary file not shown.

16
nohup.out Normal file
View file

@ -0,0 +1,16 @@
PROGRAMMVERSION: 1.0
Terminal: qt
weiter mit 'e'
PROGRAMMVERSION: 1.0
Terminal: qt
weiter mit 'e'
PROGRAMMVERSION: 1.0
Terminal: qt
weiter mit 'e'
Invalid MIT-MAGIC-COOKIE-1 keyqt.qpa.screen: QXcbConnection: Could not connect to display :0.0
Could not connect to any X display.
PROGRAMMVERSION: 1.0
Terminal: qt
weiter mit 'e'
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-famulus'

4
print Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
# echo $DISPLAY
export DISPLAY=:1
./plotty --in test_plot

BIN
test_plot

Binary file not shown.