Skip to content

Commit

Permalink
Added DLT injection feature to control relais and power.
Browse files Browse the repository at this point in the history
Fixed relais board 2 DLT output.
  • Loading branch information
alexmucde committed Jul 9, 2021
1 parent 598587b commit 8804c00
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 9 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ The Arduino board sends the status of Relais, when it was triggered with the but

The Arduino board sends every second a watchdog signal "WD\n".

## DLT injection commands

The commands are interpreted independent of the service id.

* <Relais name> on/off/trigger
* <Power name> on/off

## Installation

To build this SW the Qt Toolchain must be used.
Expand Down Expand Up @@ -113,6 +120,10 @@ Github Sponsors:

## Changes

v0.0.6:

* added DLT Injection feature to control Relais and Power

v0.0.5:

* support also voltage in Multimeter
Expand Down
155 changes: 149 additions & 6 deletions dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <QFileDialog>
#include <QFile>
#include <QMessageBox>
#include <QStringList>

#include "dialog.h"
#include "ui_dialog.h"
Expand Down Expand Up @@ -48,6 +49,8 @@ Dialog::Dialog(bool autostart,QString configuration,QWidget *parent)
connect(&dltMultimeter2, SIGNAL(status(QString)), this, SLOT(statusMultimeter2(QString)));
connect(&dltMiniServer, SIGNAL(status(QString)), this, SLOT(statusDlt(QString)));

connect(&dltMiniServer, SIGNAL(injection(QString)), this, SLOT(injection(QString)));

//connect value slots from Multimeter
connect(&dltMultimeter1, SIGNAL(valueMultimeter(QString,QString)), this, SLOT(valueMultimeter1(QString,QString)));
connect(&dltMultimeter2, SIGNAL(valueMultimeter(QString,QString)), this, SLOT(valueMultimeter2(QString,QString)));
Expand Down Expand Up @@ -95,6 +98,8 @@ Dialog::~Dialog()
disconnect(&dltRelais2, SIGNAL(status(QString)), this, SLOT(statusRelais2(QString)));
disconnect(&dltMiniServer, SIGNAL(status(QString)), this, SLOT(statusDlt(QString)));

disconnect(&dltMiniServer, SIGNAL(injection(QString)), this, SLOT(injection(QString)));

disconnect(&dltMultimeter1, SIGNAL(status(QString)), this, SLOT(statusMultimeter1(QString)));
disconnect(&dltMultimeter1, SIGNAL(valueMultimeter(QString,QString)), this, SLOT(valueMultimeter1(QString,QString)));
disconnect(&dltMultimeter2, SIGNAL(status(QString)), this, SLOT(statusMultimeter2(QString)));
Expand Down Expand Up @@ -541,12 +546,12 @@ void Dialog::on_checkBoxRelais4_clicked(bool checked)
if(checked)
{
dltRelais2.on(0);
dltMiniServer.sendValue2(dltRelais2.getRelaisName(0),"On");
dltMiniServer.sendValue2(dltRelais2.getRelaisName(1),"On");
}
else
{
dltRelais2.off(0);
dltMiniServer.sendValue2(dltRelais2.getRelaisName(0),"Off");
dltMiniServer.sendValue2(dltRelais2.getRelaisName(1),"Off");
}
}

Expand All @@ -555,12 +560,12 @@ void Dialog::on_checkBoxRelais5_clicked(bool checked)
if(checked)
{
dltRelais2.on(1);
dltMiniServer.sendValue2(dltRelais2.getRelaisName(1),"On");
dltMiniServer.sendValue2(dltRelais2.getRelaisName(2),"On");
}
else
{
dltRelais2.off(1);
dltMiniServer.sendValue2(dltRelais2.getRelaisName(1),"Off");
dltMiniServer.sendValue2(dltRelais2.getRelaisName(2),"Off");
}
}

Expand All @@ -570,12 +575,12 @@ void Dialog::on_checkBoxRelais6_clicked(bool checked)
if(checked)
{
dltRelais2.on(2);
dltMiniServer.sendValue2(dltRelais2.getRelaisName(2),"On");
dltMiniServer.sendValue2(dltRelais2.getRelaisName(3),"On");
}
else
{
dltRelais2.off(2);
dltMiniServer.sendValue2(dltRelais2.getRelaisName(2),"Off");
dltMiniServer.sendValue2(dltRelais2.getRelaisName(3),"Off");
}
}

Expand Down Expand Up @@ -757,3 +762,141 @@ void Dialog::on_checkBoxPower2_clicked(bool checked)
dltMiniServer.sendValue2(dltMultimeter2.getPowerName(),"Off");
}
}

void Dialog::injection(QString text)
{
QStringList list = text.split(' ');

qDebug() << "Injection received: " << text;

if(dltRelais1.getRelaisName(1) == list[0])
{
if(list[1]=="on")
{
ui->checkBoxRelais1->setChecked(true);
on_checkBoxRelais1_clicked(true);
}
else if(list[1]=="off")
{
ui->checkBoxRelais1->setChecked(false);
on_checkBoxRelais1_clicked(false);
}
else if(list[1]=="trigger")
{
on_pushButtonRelais1Trigger_clicked();
}
}
else if(dltRelais1.getRelaisName(2) == list[0])
{
if(list[1]=="on")
{
ui->checkBoxRelais2->setChecked(true);
on_checkBoxRelais2_clicked(true);
}
else if(list[1]=="off")
{
ui->checkBoxRelais2->setChecked(false);
on_checkBoxRelais2_clicked(false);
}
else if(list[1]=="trigger")
{
on_pushButtonRelais2Trigger_clicked();
}
}
else if(dltRelais1.getRelaisName(3) == list[0])
{
if(list[1]=="on")
{
ui->checkBoxRelais3->setChecked(true);
on_checkBoxRelais3_clicked(true);
}
else if(list[1]=="off")
{
ui->checkBoxRelais3->setChecked(false);
on_checkBoxRelais3_clicked(false);
}
else if(list[1]=="trigger")
{
on_pushButtonRelais3Trigger_clicked();
}
}
else if(dltRelais2.getRelaisName(1) == list[0])
{
if(list[1]=="on")
{
ui->checkBoxRelais4->setChecked(true);
on_checkBoxRelais4_clicked(true);
}
else if(list[1]=="off")
{
ui->checkBoxRelais4->setChecked(false);
on_checkBoxRelais4_clicked(false);
}
else if(list[1]=="trigger")
{
on_pushButtonRelais4Trigger_clicked();
}
}
else if(dltRelais2.getRelaisName(2) == list[0])
{
if(list[1]=="on")
{
ui->checkBoxRelais5->setChecked(true);
on_checkBoxRelais5_clicked(true);
}
else if(list[1]=="off")
{
ui->checkBoxRelais5->setChecked(false);
on_checkBoxRelais5_clicked(false);
}
else if(list[1]=="trigger")
{
on_pushButtonRelais5Trigger_clicked();
}
}
else if(dltRelais2.getRelaisName(3) == list[0])
{
if(list[1]=="on")
{
ui->checkBoxRelais6->setChecked(true);
on_checkBoxRelais6_clicked(true);
}
else if(list[1]=="off")
{
ui->checkBoxRelais6->setChecked(false);
on_checkBoxRelais6_clicked(false);
}
else if(list[1]=="trigger")
{
on_pushButtonRelais6Trigger_clicked();
}
}

if(dltMultimeter1.getPowerName() == list[0])
{
if(list[1]=="on")
{
ui->checkBoxPower1->setChecked(true);
on_checkBoxPower1_clicked(true);
}
else if(list[1]=="off")
{
ui->checkBoxPower1->setChecked(false);
on_checkBoxPower1_clicked(false);
}
}
else if(dltMultimeter2.getPowerName() == list[0])
{
if(list[1]=="on")
{
ui->checkBoxPower2->setChecked(true);
on_checkBoxPower2_clicked(true);
}
else if(list[1]=="off")
{
ui->checkBoxPower2->setChecked(false);
on_checkBoxPower2_clicked(false);
}
}

}
2 changes: 2 additions & 0 deletions dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ private slots:
void statusMultimeter2(QString text);
void statusDlt(QString text);

void injection(QString text);

// value from Multimeter or Power Supply
void valueMultimeter1(QString value,QString unit);
void valueMultimeter2(QString value,QString unit);
Expand Down
4 changes: 2 additions & 2 deletions dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>906</width>
<width>458</width>
<height>719</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down
75 changes: 75 additions & 0 deletions dltminiserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ void DLTMiniServer::stop()
disconnect(&tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection()));
tcpServer.close();

readData.clear();

status("stopped");
qDebug() << "DLTMiniServer: stopped" << port;
}
Expand Down Expand Up @@ -142,16 +144,86 @@ void DLTMiniServer::readSettings(const QString &filename)

void DLTMiniServer::readyRead()
{
while(tcpSocket && tcpSocket->bytesAvailable())
{
readData += tcpSocket->readAll();

// check if complete DLT message is received
if(readData.size()>=4)
{
// calculate size
unsigned short length = (unsigned short)(readData[3]) | ((unsigned short)(readData[2]) << 8);
if(readData.size()>=length)
{
qDebug() << "DLTMiniServer: msg received with length" << length;

unsigned char htyp = (unsigned char)(readData[0]);

unsigned short standardHeaderLength = 4;
if(htyp&0x04) standardHeaderLength+=4; // with ecu id
if(htyp&0x08) standardHeaderLength+=4; // with session id
if(htyp&0x10) standardHeaderLength+=4; // with timestamp

//qDebug() << "DLTMiniServer: header length" << standardHeaderLength;

if(htyp&0x01) // use of extended header
{
unsigned char msin = (unsigned char)(readData[standardHeaderLength]);
unsigned char mstp = (msin >> 1) & 0x07;
unsigned char mtin = (msin >> 4) & 0x0f;

//qDebug() << "DLTMiniServer: mstp" << mstp << "mtin" << mtin;

if(mstp==0x3 && mtin == 0x01 && readData.size()>=standardHeaderLength+10+4) // Control request message
{
unsigned int serviceId = (unsigned int)(readData[standardHeaderLength+10]) |
(unsigned int)(readData[standardHeaderLength+11]) << 8 |
(unsigned int)(readData[standardHeaderLength+12]) << 16 |
(unsigned int)(readData[standardHeaderLength+13]) << 24;

//qDebug() << "DLTMiniServer: serviceId" << serviceId;

if(serviceId==4096 && readData.size()>=standardHeaderLength+10+4+4)
{
unsigned int lengthData = (unsigned int)(readData[standardHeaderLength+14]) |
(unsigned int)(readData[standardHeaderLength+15]) << 8 |
(unsigned int)(readData[standardHeaderLength+15]) << 16 |
(unsigned int)(readData[standardHeaderLength+15]) << 24;

//qDebug() << "DLTMiniServer: lengthData" << lengthData;

if(readData.size()>=standardHeaderLength+18+lengthData)
{
QByteArray injectionData = readData.mid(standardHeaderLength+18,lengthData);
QString injectionStr = QString::fromLatin1(injectionData);

qDebug() << "DLTMiniServer: injection" << injectionStr;

injection(injectionStr);
}
}

}
}


readData.remove(0,length);
}
}

}
}

void DLTMiniServer::newConnection()
{
tcpSocket = tcpServer.nextPendingConnection();
connect(tcpSocket, SIGNAL(connected()), this, SLOT(connected()));
connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readyRead()));
tcpServer.pauseAccepting();

readData.clear();

status("connected");
}

Expand All @@ -165,10 +237,13 @@ void DLTMiniServer::disconnected()
tcpSocket->close();
disconnect(tcpSocket, SIGNAL(connected()), this, SLOT(connected()));
disconnect(tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
disconnect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readyRead()));
//delete tcpSocket;
tcpSocket = 0;
tcpServer.resumeAccepting();

readData.clear();

status("listening");
}

Expand Down
3 changes: 3 additions & 0 deletions dltminiserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DLTMiniServer : public QObject
signals:

void status(QString text);
void injection(QString text);

private slots:

Expand All @@ -68,6 +69,8 @@ private slots:
QString applicationId;
QString contextId;

QByteArray readData;

};

#endif // DLTMINISERVER_H
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
#ifndef VERSION_H
#define VERSION_H

#define DLT_POWER_VERSION "v0.0.5"
#define DLT_POWER_VERSION "v0.0.6"

#endif // VERSION_H

0 comments on commit 8804c00

Please sign in to comment.