Added the possibility to use a hostname instead of an IP-address for the LAN connection.

merge-requests/1/head
Teuniz 2017-09-09 18:40:22 +02:00
rodzic 8603a339e7
commit f2d44e11ce
6 zmienionych plików z 191 dodań i 56 usunięć

Wyświetl plik

@ -35,7 +35,7 @@
#define PROGRAM_NAME "DSRemote"
#define PROGRAM_VERSION "0.35_1707091429"
#define PROGRAM_VERSION "0.35_1709091834"
#define MAX_PATHLEN 4096
@ -124,6 +124,8 @@ struct device_settings
int vertdivisions; // number of vertical divisions, 8 or 10
int use_extra_vertdivisions; // If 1: use 10 vertical divisions instead of 8, DS1000Z only
char hostname[128];
int screentimerival;
int channel_cnt; // Device has 2 or 4 channels

Wyświetl plik

@ -55,9 +55,9 @@ struct tmcdev * lan_connect_thread::get_device(void)
void lan_connect_thread::set_device_address(const char *addr)
{
strncpy(dev_str, addr, 16);
strncpy(dev_str, addr, 63);
dev_str[15] = 0;
dev_str[63] = 0;
}

Wyświetl plik

@ -98,53 +98,62 @@ void UI_Mainwindow::open_connection()
if(devparms.connectiontype == 1) // LAN
{
strcpy(dev_str, settings.value("connection/ip", "192.168.1.100").toString().toLatin1().data());
strcpy(devparms.hostname, settings.value("connection/hostname", "").toString().toLatin1().data());
if(!strcmp(dev_str, ""))
if(strlen(devparms.hostname))
{
sprintf(str, "No IP address set");
goto OC_OUT_ERROR;
strcpy(dev_str, devparms.hostname);
}
len = strlen(dev_str);
if(len < 7)
else
{
sprintf(str, "No IP address set");
goto OC_OUT_ERROR;
}
strcpy(dev_str, settings.value("connection/ip", "192.168.1.100").toString().toLatin1().data());
int cf = 0;
for(i=0; i<len; i++)
{
if(dev_str[i] == '.')
if(!strcmp(dev_str, ""))
{
cf = 0;
sprintf(str, "No IP address or hostname set");
goto OC_OUT_ERROR;
}
if(dev_str[i] == '0')
len = strlen(dev_str);
if(len < 7)
{
if(cf == 0)
sprintf(str, "No IP address set");
goto OC_OUT_ERROR;
}
int cf = 0;
for(i=0; i<len; i++)
{
if(dev_str[i] == '.')
{
if((dev_str[i+1] != 0) && (dev_str[i+1] != '.'))
cf = 0;
}
if(dev_str[i] == '0')
{
if(cf == 0)
{
for(j=i; j<len; j++)
if((dev_str[i+1] != 0) && (dev_str[i+1] != '.'))
{
dev_str[j] = dev_str[j+1];
for(j=i; j<len; j++)
{
dev_str[j] = dev_str[j+1];
}
i--;
len--;
}
i--;
len--;
}
}
}
else
{
if(dev_str[i] != '.')
else
{
cf = 1;
if(dev_str[i] != '.')
{
cf = 1;
}
}
}
}
@ -548,6 +557,8 @@ void UI_Mainwindow::close_connection()
}
statusLabel->setText("Disconnected");
printf("Disconnected from device\n");
}

Wyświetl plik

@ -57,14 +57,19 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
usbRadioButton->setChecked(true);
}
lanRadioButton = new QRadioButton("LAN", this);
lanRadioButton->setAutoExclusive(true);
lanRadioButton->setGeometry(40, 70, 110, 25);
lanIPRadioButton = new QRadioButton("LAN", this);
lanIPRadioButton->setAutoExclusive(true);
lanIPRadioButton->setGeometry(40, 70, 110, 25);
if(mainwindow->devparms.connectiontype == 1)
{
lanRadioButton->setChecked(true);
lanIPRadioButton->setChecked(true);
}
hostnameLabel = new QLabel(this);
hostnameLabel->setGeometry(40, 120, 120, 35);
hostnameLabel->setText("Hostname\n(overides IP-address)");
hostnameLabel->setToolTip("Leave empty if you want to use the above IP-address");
comboBox1 = new QComboBox(this);
comboBox1->setGeometry(180, 20, 110, 25);
comboBox1->addItem("/dev/usbtmc0");
@ -129,23 +134,34 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
ipSpinbox4->setValue(100);
}
if(settings.contains("connection/hostname"))
{
strncpy(mainwindow->devparms.hostname, settings.value("connection/hostname").toString().toLatin1().data(), 63);
}
HostLineEdit = new QLineEdit(this);
HostLineEdit->setGeometry(180, 120, 240, 25);
HostLineEdit->setMaxLength(63);
HostLineEdit->setText(mainwindow->devparms.hostname);
HostLineEdit->setToolTip("Leave empty if you want to use the above IP-address");
refreshLabel = new QLabel(this);
refreshLabel->setGeometry(40, 120, 120, 35);
refreshLabel->setText("Screen update\n interval");
refreshLabel->setGeometry(40, 170, 120, 35);
refreshLabel->setText("Screen update\ninterval");
refreshSpinbox = new QSpinBox(this);
refreshSpinbox->setGeometry(180, 120, 100, 25);
refreshSpinbox->setGeometry(180, 170, 100, 25);
refreshSpinbox->setSuffix(" mS");
refreshSpinbox->setRange(50, 2000);
refreshSpinbox->setSingleStep(10);
refreshSpinbox->setValue(mainwindow->devparms.screentimerival);
invScrShtLabel = new QLabel(this);
invScrShtLabel->setGeometry(40, 170, 120, 35);
invScrShtLabel->setGeometry(40, 220, 120, 35);
invScrShtLabel->setText("Screenshot invert\n colors");
invScrShtCheckbox = new QCheckBox(this);
invScrShtCheckbox->setGeometry(180, 170, 120, 35);
invScrShtCheckbox->setGeometry(180, 220, 120, 35);
invScrShtCheckbox->setTristate(false);
if(mainwindow->devparms.screenshot_inv)
{
@ -157,11 +173,11 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
}
showfpsLabel = new QLabel(this);
showfpsLabel->setGeometry(40, 220, 120, 35);
showfpsLabel->setGeometry(40, 270, 120, 35);
showfpsLabel->setText("Show frames\n per second");
showfpsCheckbox = new QCheckBox(this);
showfpsCheckbox->setGeometry(180, 220, 120, 35);
showfpsCheckbox->setGeometry(180, 270, 120, 35);
showfpsCheckbox->setTristate(false);
if(mainwindow->devparms.show_fps)
{
@ -173,11 +189,11 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
}
extendvertdivLabel = new QLabel(this);
extendvertdivLabel->setGeometry(40, 270, 120, 35);
extendvertdivLabel->setGeometry(40, 320, 120, 35);
extendvertdivLabel->setText("Use extended\n vertical range");
extendvertdivCheckbox = new QCheckBox(this);
extendvertdivCheckbox->setGeometry(180, 270, 120, 35);
extendvertdivCheckbox->setGeometry(180, 320, 120, 35);
extendvertdivCheckbox->setTristate(false);
if(mainwindow->devparms.use_extra_vertdivisions)
{
@ -210,7 +226,7 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
if(mainwindow->devparms.connected)
{
usbRadioButton->setEnabled(false);
lanRadioButton->setEnabled(false);
lanIPRadioButton->setEnabled(false);
ipSpinbox1->setEnabled(false);
ipSpinbox2->setEnabled(false);
ipSpinbox3->setEnabled(false);
@ -223,11 +239,12 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
QObject::connect(applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked()));
}
QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
QObject::connect(refreshSpinbox, SIGNAL(valueChanged(int)), this, SLOT(refreshSpinboxChanged(int)));
QObject::connect(invScrShtCheckbox, SIGNAL(stateChanged(int)), this, SLOT(invScrShtCheckboxChanged(int)));
QObject::connect(showfpsCheckbox, SIGNAL(stateChanged(int)), this, SLOT(showfpsCheckboxChanged(int)));
QObject::connect(extendvertdivCheckbox, SIGNAL(stateChanged(int)), this, SLOT(extendvertdivCheckboxChanged(int)));
QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
QObject::connect(refreshSpinbox, SIGNAL(valueChanged(int)), this, SLOT(refreshSpinboxChanged(int)));
QObject::connect(invScrShtCheckbox, SIGNAL(stateChanged(int)), this, SLOT(invScrShtCheckboxChanged(int)));
QObject::connect(showfpsCheckbox, SIGNAL(stateChanged(int)), this, SLOT(showfpsCheckboxChanged(int)));
QObject::connect(extendvertdivCheckbox, SIGNAL(stateChanged(int)), this, SLOT(extendvertdivCheckboxChanged(int)));
QObject::connect(HostLineEdit, SIGNAL(textEdited(QString)), this, SLOT(hostnamechanged(QString)));
exec();
}
@ -268,6 +285,10 @@ void UI_settings_window::applyButtonClicked()
settings.setValue("connection/ip", dev_str);
strncpy(mainwindow->devparms.hostname, HostLineEdit->text().toLatin1().data(), 64);
settings.setValue("connection/hostname", mainwindow->devparms.hostname);
if(invScrShtCheckbox->checkState() == Qt::Checked)
{
mainwindow->devparms.screenshot_inv = 1;
@ -388,6 +409,55 @@ void UI_settings_window::extendvertdivCheckboxChanged(int state)
}
void UI_settings_window::hostnamechanged(QString qstr)
{
int i, j, len, trunc=0;
char str[128];
strncpy(str, qstr.toLatin1().data(), 63);
str[63] = 0;
len = strlen(str);
for(i=0; i<len; i++)
{
if(((str[i] < '0') && (str[i] != '-') && (str[i] != '.')) ||
((str[i] > '9') && (str[i] < 'A')) ||
((str[i] > 'Z') && (str[i] < 'a')) ||
(str[i] > 'z'))
{
for(j=i; j<len; j++)
{
str[j] = str[j+1];
}
len--;
i--;
trunc = 1;
}
}
for(i=0; i<len; i++)
{
if((str[i] >= 'A') && (str[i] <= 'Z'))
{
str[i] += 32;
trunc = 1;
}
}
if(trunc)
{
HostLineEdit->setText(str);
}
}

Wyświetl plik

@ -43,6 +43,11 @@
#include <QSettings>
#include <QRadioButton>
#include <QSpinBox>
#include <QLineEdit>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mainwindow.h"
#include "global.h"
@ -65,7 +70,7 @@ QPushButton *cancelButton,
*applyButton;
QRadioButton *usbRadioButton,
*lanRadioButton;
*lanIPRadioButton;
QComboBox *comboBox1;
@ -78,12 +83,15 @@ QSpinBox *refreshSpinbox,
QLabel *refreshLabel,
*invScrShtLabel,
*showfpsLabel,
*extendvertdivLabel;
*extendvertdivLabel,
*hostnameLabel;
QCheckBox *invScrShtCheckbox,
*showfpsCheckbox,
*extendvertdivCheckbox;
QLineEdit *HostLineEdit;
UI_Mainwindow *mainwindow;
private slots:
@ -93,6 +101,7 @@ void refreshSpinboxChanged(int);
void invScrShtCheckboxChanged(int);
void showfpsCheckboxChanged(int);
void extendvertdivCheckboxChanged(int);
void hostnamechanged(QString);
};

Wyświetl plik

@ -41,6 +41,7 @@
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include "tmc_dev.h"
#include "utils.h"
@ -103,10 +104,52 @@ static int tmclan_recv(char *buf, int sz)
}
struct tmcdev * tmclan_open(const char *ip_address)
struct tmcdev * tmclan_open(const char *host_or_ip)
{
char ip_address[256]={""};
struct tmcdev *tmc_device;
struct addrinfo *addr_result, *res;
struct sockaddr_in *ipv4_addr;
if((host_or_ip[0] >= 'a') && (host_or_ip[0] <= 'z'))
{
printf("Resolving hostname: %s...\n", host_or_ip);
if(getaddrinfo(host_or_ip, NULL, NULL, &addr_result))
{
printf("Error: getaddrinfo() file: %s line: %i", __FILE__, __LINE__);
return NULL;
}
for(res=addr_result; res!=NULL; res=res->ai_next)
{
if(res->ai_family == AF_INET)
{
if(res->ai_socktype == SOCK_STREAM)
{
break;
}
}
}
if(res == NULL)
{
printf("Error: getaddrinfo() file: %s line: %i", __FILE__, __LINE__);
return NULL;
}
ipv4_addr = (struct sockaddr_in *)res->ai_addr;
inet_ntop(AF_INET, &(ipv4_addr->sin_addr), ip_address, INET_ADDRSTRLEN);
freeaddrinfo(addr_result);
printf("Resolved hostname %s into address: %s\n", host_or_ip, ip_address);
}
else
{
strcpy(ip_address, host_or_ip);
}
sockfd = socket(PF_INET, SOCK_STREAM, 0);
if(sockfd == -1)
{