boardinfo

This commit is contained in:
Tristan Krause 2019-03-27 15:48:24 +01:00
parent 46809d811b
commit 0f71e121fa
12 changed files with 168 additions and 18 deletions

View file

@ -50,6 +50,10 @@ void B15F::init()
if(tries == 0)
throw DriverException("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
std::cout << "OK" << std::endl;
// Gib board info aus
std::vector<std::string> info = getBoardInfo();
std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl;
}
@ -115,6 +119,38 @@ bool B15F::testIntConv()
}
std::vector<std::string> B15F::getBoardInfo(void)
{
try
{
std::vector<std::string> info;
writeByte(RQ_INFO);
uint8_t n = readByte();
while(n--)
{
uint8_t len = readByte();
std::string str;
while(len--)
str += static_cast<char>(readByte());
info.push_back(str);
}
uint8_t aw = readByte();
if(aw != MSG_OK)
throw DriverException("Board Info fehlerhalft");
return info;
}
catch(DriverException& de)
{
reconnect();
return getBoardInfo();
}
}
bool B15F::digitaleAusgabe0(uint8_t port)
{

View file

@ -8,6 +8,7 @@
#include <cstdlib>
#include <chrono>
#include <cstdint>
#include <vector>
#include <unistd.h>
#include <fcntl.h>
@ -25,6 +26,7 @@ public:
void discard(void);
bool testConnection(void);
bool testIntConv(void);
std::vector<std::string> getBoardInfo(void);
// Board Befehle
bool digitaleAusgabe0(uint8_t);

Binary file not shown.

84
drv/plottyfile.cpp Normal file
View file

@ -0,0 +1,84 @@
#include "plottyfile.h"
void PlottyFile::prepStr(std::string& str, uint8_t len)
{
if(str.length() > len)
throw std::runtime_error("Zu grosser String.");
if(str.length() != len)
str += '\n';
while(str.length() < len)
str += '\0';
}
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);
std::ofstream file(filename);
file.write(reinterpret_cast<char*>(&command), 1);
file.write(title.c_str(), title.length());
file.write(filetype.c_str(), 2);
file.write(reinterpret_cast<char*>(&version), 2);
file.write(reinterpret_cast<char*>(&subversion), 2);
file.write(reinterpret_cast<char*>(&function_type), 1);
file.write(reinterpret_cast<char*>(&quadrant), 1);
file.write(reinterpret_cast<char*>(&ref_x), 2);
file.write(reinterpret_cast<char*>(&ref_y), 2);
file.write(reinterpret_cast<char*>(&para_first), 2);
file.write(reinterpret_cast<char*>(&para_stepwidth), 2);
file.write(unit_x.c_str(), unit_x.length());
file.write(desc_x.c_str(), desc_x.length());
file.write(unit_y.c_str(), unit_y.length());
file.write(desc_y.c_str(), desc_y.length());
file.write(unit_para.c_str(), unit_para.length());
file.write(desc_para.c_str(), desc_para.length());
file.write(reinterpret_cast<const char*>(&eof), 1);
while(file.tellp() < 256)
file.put(0);
for(uint16_t i = 0; i < 1023; i++)
{
file.put(i >> 8);
file.put(i & 0xFF);
file.put(1);
file.put(0);
}
for(uint16_t i = 0; i < 1023; i++)
{
file.put((i >> 8) | 128);
file.put(i & 0xFF);
file.put(2);
file.put(0);
}
file.close();
}

35
drv/plottyfile.h Normal file
View file

@ -0,0 +1,35 @@
#ifndef PLOTTYFILE_H
#define PLOTTYFILE_H
#include <iostream>
#include <fstream>
#include <exception>
class PlottyFile
{
public:
void writeToFile(std::string filename);
private:
void prepStr(std::string& str, uint8_t len);
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;
std::string unit_x;
std::string desc_x;
std::string unit_y;
std::string desc_y;
std::string unit_para;
std::string desc_para;
const uint8_t eof = 0xD;
};
#endif // PLOTTYFILE_H

BIN
drv/plottyfile.o Normal file

Binary file not shown.