some comments

This commit is contained in:
Tristan Krause 2019-06-04 09:43:10 +02:00
parent 0ec3988c58
commit b4ac345875
3 changed files with 90 additions and 94 deletions

View file

@ -12,7 +12,7 @@
</component>
<component name="ChangeListManager">
<list default="true" id="d13a1bae-0fd7-48fc-b53c-d6dd1aaf95b9" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/drv/b15f.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/drv/b15f.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/drv/usart.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/drv/usart.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/drv/usart.h" beforeDir="false" afterPath="$PROJECT_DIR$/drv/usart.h" afterDir="false" />
</list>
@ -28,7 +28,7 @@
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" />
<component name="FileEditorManager">
<leaf>
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
@ -38,20 +38,20 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/drv/usart.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="506">
<caret line="106" column="35" selection-start-line="106" selection-start-column="35" selection-end-line="106" selection-end-column="35" />
<state relative-caret-position="405">
<caret line="154" column="8" lean-forward="true" selection-start-line="154" selection-start-column="8" selection-end-line="154" selection-end-column="17" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/drv/usart.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="554">
<caret line="102" column="11" selection-start-line="102" selection-start-column="11" selection-end-line="102" selection-end-column="11" />
<state relative-caret-position="105">
<caret line="7" column="34" selection-start-line="7" selection-start-column="34" selection-end-line="7" selection-end-column="34" />
</state>
</provider>
</entry>
@ -68,7 +68,7 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/drv/b15f.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="192">
<state relative-caret-position="3315">
<caret line="221" column="29" selection-start-line="221" selection-start-column="29" selection-end-line="221" selection-end-column="29" />
</state>
</provider>
@ -96,8 +96,8 @@
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/drv/b15f.cpp" />
<option value="$PROJECT_DIR$/drv/usart.cpp" />
<option value="$PROJECT_DIR$/drv/usart.h" />
<option value="$PROJECT_DIR$/drv/usart.cpp" />
</list>
</option>
</component>
@ -137,7 +137,7 @@
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
<property name="settings.editor.selected.configurable" value="preferences.keymap" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
@ -168,26 +168,21 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1559118962147</updated>
<workItem from="1559118964304" duration="1887000" />
<workItem from="1559118964304" duration="1913000" />
<workItem from="1559633658436" duration="466000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="1887000" />
<option name="totallyTimeSpent" value="2379000" />
</component>
<component name="ToolWindowManager">
<frame x="67" y="25" width="1853" height="1055" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24958494" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25235197" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Database Changes" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Messages" weight="0.32937366" />
<window_info active="true" anchor="bottom" id="Terminal" visible="true" weight="0.23434125" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="CMake" weight="0.33045357" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32937366" />
<window_info anchor="bottom" id="Run" order="2" />
@ -195,17 +190,26 @@
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Database" />
<window_info anchor="right" id="make" />
<window_info anchor="bottom" id="Database Changes" order="7" />
<window_info anchor="bottom" id="Messages" order="8" weight="0.32937366" />
<window_info active="true" anchor="bottom" id="Terminal" order="9" visible="true" weight="0.23434125" />
<window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
<window_info anchor="bottom" id="Version Control" order="11" />
<window_info anchor="bottom" id="CMake" order="12" weight="0.33045357" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="make" order="3" />
<window_info anchor="right" id="Database" order="4" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/drv/b15f.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90">
@ -213,8 +217,12 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/drv/b15f.h">
<provider selected="true" editor-type-id="text-editor" />
<entry file="file://$PROJECT_DIR$/drv/b15f.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="3315">
<caret line="221" column="29" selection-start-line="221" selection-start-column="29" selection-end-line="221" selection-end-column="29" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/drv/usartexception.h">
<provider selected="true" editor-type-id="text-editor">
@ -223,24 +231,17 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/drv/b15f.cpp">
<entry file="file://$PROJECT_DIR$/drv/usart.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="192">
<caret line="221" column="29" selection-start-line="221" selection-start-column="29" selection-end-line="221" selection-end-column="29" />
<state relative-caret-position="405">
<caret line="154" column="8" lean-forward="true" selection-start-line="154" selection-start-column="8" selection-end-line="154" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/drv/usart.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="554">
<caret line="102" column="11" selection-start-line="102" selection-start-column="11" selection-end-line="102" selection-end-column="11" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/drv/usart.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="506">
<caret line="106" column="35" selection-start-line="106" selection-start-column="35" selection-end-line="106" selection-end-column="35" />
<state relative-caret-position="105">
<caret line="7" column="34" selection-start-line="7" selection-start-column="34" selection-end-line="7" selection-end-column="34" />
</state>
</provider>
</entry>

View file

@ -1,111 +1,109 @@
#include "usart.h"
void USART::openDevice(std::string device)
{
file_desc = open(device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY /* | O_NONBLOCK*/);
if(file_desc <= 0)
USART::~USART() {
closeDevice();
}
void USART::openDevice(std::string device) {
// Benutze blockierenden Modus
file_desc = open(device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
if (file_desc <= 0)
throw USARTException("Fehler beim Öffnen des Gerätes");
struct termios options;
int code = tcgetattr(file_desc, &options);
if(code)
if (code)
throw USARTException("Fehler beim Lesen der Geräteparameter");
options.c_cflag = CS8 | CLOCAL | CREAD;
options.c_iflag = IGNPAR;
options.c_oflag = 0;
options.c_lflag = 0;
options.c_cc[VMIN] = 0; // #bytes read returns at least
options.c_cc[VMIN] = 0; // #bytes read returns at least
options.c_cc[VTIME] = timeout;
code = cfsetspeed(&options, baudrate);
if(code)
if (code)
throw USARTException("Fehler beim Setzen der Baudrate");
code = tcsetattr(file_desc, TCSANOW, &options);
if(code)
if (code)
throw USARTException("Fehler beim Setzen der Geräteparameter");
clearOutputBuffer();
clearInputBuffer();
}
void USART::closeDevice()
{
int code = close(file_desc);
if(code)
throw USARTException("Fehler beim Schließen des Gerätes");
void USART::closeDevice() {
if (file_desc > 0) {
int code = close(file_desc);
if (code)
throw USARTException("Fehler beim Schließen des Gerätes");
file_desc = -1;
}
}
void USART::clearInputBuffer()
{
void USART::clearInputBuffer() {
int code = tcflush(file_desc, TCIFLUSH);
if(code)
if (code)
throw USARTException("Fehler beim Leeren des Eingangspuffers");
}
void USART::clearOutputBuffer()
{
void USART::clearOutputBuffer() {
int code = tcflush(file_desc, TCOFLUSH);
if(code)
if (code)
throw USARTException("Fehler beim Leeren des Ausgangspuffers");
}
void USART::flushOutputBuffer()
{
void USART::flushOutputBuffer() {
int code = tcdrain(file_desc);
if(code)
if (code)
throw USARTException("Fehler beim Versenden des Ausgangspuffers");
}
void USART::writeByte(uint8_t b)
{
void USART::writeByte(uint8_t b) {
int sent = write(file_desc, &b, 1);
if(sent != 1)
{
if (sent != 1) {
std::cout << "WARNUNG: Fehler beim Senden (" << sent << "): writeByte(), wiederhole..." << std::endl;
usleep(100000);
sent = write(file_desc, &b, 1);
if(sent != 1)
if (sent != 1)
throw USARTException("Fehler beim Senden: writeByte()");
}
}
void USART::writeInt(uint16_t d)
{
int sent = write(file_desc, reinterpret_cast<char*>(&d), 2);
if(sent != 2)
void USART::writeInt(uint16_t d) {
int sent = write(file_desc, reinterpret_cast<char *>(&d), 2);
if (sent != 2)
throw USARTException("Fehler beim Senden: writeInt()");
}
void USART::writeU32(uint32_t w)
{
int sent = write(file_desc, reinterpret_cast<char*>(&w), 4);
if(sent != 4)
void USART::writeU32(uint32_t w) {
int sent = write(file_desc, reinterpret_cast<char *>(&w), 4);
if (sent != 4)
throw USARTException("Fehler beim Senden: writeU32()");
}
void USART::receive(uint8_t *buffer, uint16_t offset, uint8_t len)
{
void USART::receive(uint8_t *buffer, uint16_t offset, uint8_t len) {
int n = read(file_desc, buffer + offset, len);
if(n != len)
throw USARTException(std::string(__FUNCTION__) + " failed: " + std::string(__FILE__) + "#" + std::to_string(__LINE__));
if (n != len)
throw USARTException(
std::string(__FUNCTION__) + " failed: " + std::string(__FILE__) + "#" + std::to_string(__LINE__));
}
void USART::transmit(uint8_t *buffer, uint16_t offset, uint8_t len)
{
void USART::transmit(uint8_t *buffer, uint16_t offset, uint8_t len) {
int n = write(file_desc, buffer + offset, len);
if(n != len)
throw USARTException(std::string(__FUNCTION__) + " failed: " + std::string(__FILE__) + "#" + std::to_string(__LINE__));
if (n != len)
throw USARTException(
std::string(__FUNCTION__) + " failed: " + std::string(__FILE__) + "#" + std::to_string(__LINE__));
}
uint8_t USART::readByte(void)
{
uint8_t USART::readByte(void) {
char b;
auto start = std::chrono::steady_clock::now();
auto end = start;
uint16_t elapsed = 0;
while(elapsed < timeout * 100)
{
while (elapsed < timeout * 100) {
int code = read(file_desc, &b, 1);
if (code > 0)
return static_cast<uint8_t>(b);
@ -117,27 +115,22 @@ uint8_t USART::readByte(void)
throw TimeoutException("Verbindung unterbrochen.", timeout);
}
uint16_t USART::readInt(void)
{
uint16_t USART::readInt(void) {
return readByte() | readByte() << 8;
}
uint32_t USART::getBaudrate()
{
uint32_t USART::getBaudrate() {
return baudrate;
}
uint8_t USART::getTimeout()
{
uint8_t USART::getTimeout() {
return timeout;
}
void USART::setBaudrate(uint32_t baudrate)
{
void USART::setBaudrate(uint32_t baudrate) {
this->baudrate = baudrate;
}
void USART::setTimeout(uint8_t timeout)
{
void USART::setTimeout(uint8_t timeout) {
this->timeout = timeout;
}

View file

@ -23,6 +23,8 @@ public:
* Methoden für die Verwaltung der Schnittstelle *
*************************************************/
~USART(void);
/**
* Öffnet die USART Schnittstelle
* \param device Linux-Gerätepfad