kopia lustrzana https://gitlab.com/Teuniz/DSRemote
Added the possibility to use a hostname instead of an IP-address for the LAN connection.
rodzic
8603a339e7
commit
f2d44e11ce
4
global.h
4
global.h
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
#define PROGRAM_NAME "DSRemote"
|
#define PROGRAM_NAME "DSRemote"
|
||||||
#define PROGRAM_VERSION "0.35_1707091429"
|
#define PROGRAM_VERSION "0.35_1709091834"
|
||||||
|
|
||||||
#define MAX_PATHLEN 4096
|
#define MAX_PATHLEN 4096
|
||||||
|
|
||||||
|
@ -124,6 +124,8 @@ struct device_settings
|
||||||
int vertdivisions; // number of vertical divisions, 8 or 10
|
int vertdivisions; // number of vertical divisions, 8 or 10
|
||||||
int use_extra_vertdivisions; // If 1: use 10 vertical divisions instead of 8, DS1000Z only
|
int use_extra_vertdivisions; // If 1: use 10 vertical divisions instead of 8, DS1000Z only
|
||||||
|
|
||||||
|
char hostname[128];
|
||||||
|
|
||||||
int screentimerival;
|
int screentimerival;
|
||||||
|
|
||||||
int channel_cnt; // Device has 2 or 4 channels
|
int channel_cnt; // Device has 2 or 4 channels
|
||||||
|
|
|
@ -55,9 +55,9 @@ struct tmcdev * lan_connect_thread::get_device(void)
|
||||||
|
|
||||||
void lan_connect_thread::set_device_address(const char *addr)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,53 +98,62 @@ void UI_Mainwindow::open_connection()
|
||||||
|
|
||||||
if(devparms.connectiontype == 1) // LAN
|
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");
|
strcpy(dev_str, devparms.hostname);
|
||||||
goto OC_OUT_ERROR;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
len = strlen(dev_str);
|
|
||||||
|
|
||||||
if(len < 7)
|
|
||||||
{
|
{
|
||||||
sprintf(str, "No IP address set");
|
strcpy(dev_str, settings.value("connection/ip", "192.168.1.100").toString().toLatin1().data());
|
||||||
goto OC_OUT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cf = 0;
|
if(!strcmp(dev_str, ""))
|
||||||
|
|
||||||
for(i=0; i<len; i++)
|
|
||||||
{
|
|
||||||
if(dev_str[i] == '.')
|
|
||||||
{
|
{
|
||||||
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
|
||||||
else
|
|
||||||
{
|
|
||||||
if(dev_str[i] != '.')
|
|
||||||
{
|
{
|
||||||
cf = 1;
|
if(dev_str[i] != '.')
|
||||||
|
{
|
||||||
|
cf = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,6 +557,8 @@ void UI_Mainwindow::close_connection()
|
||||||
}
|
}
|
||||||
|
|
||||||
statusLabel->setText("Disconnected");
|
statusLabel->setText("Disconnected");
|
||||||
|
|
||||||
|
printf("Disconnected from device\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -57,14 +57,19 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
|
||||||
usbRadioButton->setChecked(true);
|
usbRadioButton->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
lanRadioButton = new QRadioButton("LAN", this);
|
lanIPRadioButton = new QRadioButton("LAN", this);
|
||||||
lanRadioButton->setAutoExclusive(true);
|
lanIPRadioButton->setAutoExclusive(true);
|
||||||
lanRadioButton->setGeometry(40, 70, 110, 25);
|
lanIPRadioButton->setGeometry(40, 70, 110, 25);
|
||||||
if(mainwindow->devparms.connectiontype == 1)
|
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 = new QComboBox(this);
|
||||||
comboBox1->setGeometry(180, 20, 110, 25);
|
comboBox1->setGeometry(180, 20, 110, 25);
|
||||||
comboBox1->addItem("/dev/usbtmc0");
|
comboBox1->addItem("/dev/usbtmc0");
|
||||||
|
@ -129,23 +134,34 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
|
||||||
ipSpinbox4->setValue(100);
|
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 = new QLabel(this);
|
||||||
refreshLabel->setGeometry(40, 120, 120, 35);
|
refreshLabel->setGeometry(40, 170, 120, 35);
|
||||||
refreshLabel->setText("Screen update\n interval");
|
refreshLabel->setText("Screen update\ninterval");
|
||||||
|
|
||||||
refreshSpinbox = new QSpinBox(this);
|
refreshSpinbox = new QSpinBox(this);
|
||||||
refreshSpinbox->setGeometry(180, 120, 100, 25);
|
refreshSpinbox->setGeometry(180, 170, 100, 25);
|
||||||
refreshSpinbox->setSuffix(" mS");
|
refreshSpinbox->setSuffix(" mS");
|
||||||
refreshSpinbox->setRange(50, 2000);
|
refreshSpinbox->setRange(50, 2000);
|
||||||
refreshSpinbox->setSingleStep(10);
|
refreshSpinbox->setSingleStep(10);
|
||||||
refreshSpinbox->setValue(mainwindow->devparms.screentimerival);
|
refreshSpinbox->setValue(mainwindow->devparms.screentimerival);
|
||||||
|
|
||||||
invScrShtLabel = new QLabel(this);
|
invScrShtLabel = new QLabel(this);
|
||||||
invScrShtLabel->setGeometry(40, 170, 120, 35);
|
invScrShtLabel->setGeometry(40, 220, 120, 35);
|
||||||
invScrShtLabel->setText("Screenshot invert\n colors");
|
invScrShtLabel->setText("Screenshot invert\n colors");
|
||||||
|
|
||||||
invScrShtCheckbox = new QCheckBox(this);
|
invScrShtCheckbox = new QCheckBox(this);
|
||||||
invScrShtCheckbox->setGeometry(180, 170, 120, 35);
|
invScrShtCheckbox->setGeometry(180, 220, 120, 35);
|
||||||
invScrShtCheckbox->setTristate(false);
|
invScrShtCheckbox->setTristate(false);
|
||||||
if(mainwindow->devparms.screenshot_inv)
|
if(mainwindow->devparms.screenshot_inv)
|
||||||
{
|
{
|
||||||
|
@ -157,11 +173,11 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
showfpsLabel = new QLabel(this);
|
showfpsLabel = new QLabel(this);
|
||||||
showfpsLabel->setGeometry(40, 220, 120, 35);
|
showfpsLabel->setGeometry(40, 270, 120, 35);
|
||||||
showfpsLabel->setText("Show frames\n per second");
|
showfpsLabel->setText("Show frames\n per second");
|
||||||
|
|
||||||
showfpsCheckbox = new QCheckBox(this);
|
showfpsCheckbox = new QCheckBox(this);
|
||||||
showfpsCheckbox->setGeometry(180, 220, 120, 35);
|
showfpsCheckbox->setGeometry(180, 270, 120, 35);
|
||||||
showfpsCheckbox->setTristate(false);
|
showfpsCheckbox->setTristate(false);
|
||||||
if(mainwindow->devparms.show_fps)
|
if(mainwindow->devparms.show_fps)
|
||||||
{
|
{
|
||||||
|
@ -173,11 +189,11 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
extendvertdivLabel = new QLabel(this);
|
extendvertdivLabel = new QLabel(this);
|
||||||
extendvertdivLabel->setGeometry(40, 270, 120, 35);
|
extendvertdivLabel->setGeometry(40, 320, 120, 35);
|
||||||
extendvertdivLabel->setText("Use extended\n vertical range");
|
extendvertdivLabel->setText("Use extended\n vertical range");
|
||||||
|
|
||||||
extendvertdivCheckbox = new QCheckBox(this);
|
extendvertdivCheckbox = new QCheckBox(this);
|
||||||
extendvertdivCheckbox->setGeometry(180, 270, 120, 35);
|
extendvertdivCheckbox->setGeometry(180, 320, 120, 35);
|
||||||
extendvertdivCheckbox->setTristate(false);
|
extendvertdivCheckbox->setTristate(false);
|
||||||
if(mainwindow->devparms.use_extra_vertdivisions)
|
if(mainwindow->devparms.use_extra_vertdivisions)
|
||||||
{
|
{
|
||||||
|
@ -210,7 +226,7 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
|
||||||
if(mainwindow->devparms.connected)
|
if(mainwindow->devparms.connected)
|
||||||
{
|
{
|
||||||
usbRadioButton->setEnabled(false);
|
usbRadioButton->setEnabled(false);
|
||||||
lanRadioButton->setEnabled(false);
|
lanIPRadioButton->setEnabled(false);
|
||||||
ipSpinbox1->setEnabled(false);
|
ipSpinbox1->setEnabled(false);
|
||||||
ipSpinbox2->setEnabled(false);
|
ipSpinbox2->setEnabled(false);
|
||||||
ipSpinbox3->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(applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
|
QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||||
QObject::connect(refreshSpinbox, SIGNAL(valueChanged(int)), this, SLOT(refreshSpinboxChanged(int)));
|
QObject::connect(refreshSpinbox, SIGNAL(valueChanged(int)), this, SLOT(refreshSpinboxChanged(int)));
|
||||||
QObject::connect(invScrShtCheckbox, SIGNAL(stateChanged(int)), this, SLOT(invScrShtCheckboxChanged(int)));
|
QObject::connect(invScrShtCheckbox, SIGNAL(stateChanged(int)), this, SLOT(invScrShtCheckboxChanged(int)));
|
||||||
QObject::connect(showfpsCheckbox, SIGNAL(stateChanged(int)), this, SLOT(showfpsCheckboxChanged(int)));
|
QObject::connect(showfpsCheckbox, SIGNAL(stateChanged(int)), this, SLOT(showfpsCheckboxChanged(int)));
|
||||||
QObject::connect(extendvertdivCheckbox, SIGNAL(stateChanged(int)), this, SLOT(extendvertdivCheckboxChanged(int)));
|
QObject::connect(extendvertdivCheckbox, SIGNAL(stateChanged(int)), this, SLOT(extendvertdivCheckboxChanged(int)));
|
||||||
|
QObject::connect(HostLineEdit, SIGNAL(textEdited(QString)), this, SLOT(hostnamechanged(QString)));
|
||||||
|
|
||||||
exec();
|
exec();
|
||||||
}
|
}
|
||||||
|
@ -268,6 +285,10 @@ void UI_settings_window::applyButtonClicked()
|
||||||
|
|
||||||
settings.setValue("connection/ip", dev_str);
|
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)
|
if(invScrShtCheckbox->checkState() == Qt::Checked)
|
||||||
{
|
{
|
||||||
mainwindow->devparms.screenshot_inv = 1;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,11 @@
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QRadioButton>
|
#include <QRadioButton>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
@ -65,7 +70,7 @@ QPushButton *cancelButton,
|
||||||
*applyButton;
|
*applyButton;
|
||||||
|
|
||||||
QRadioButton *usbRadioButton,
|
QRadioButton *usbRadioButton,
|
||||||
*lanRadioButton;
|
*lanIPRadioButton;
|
||||||
|
|
||||||
QComboBox *comboBox1;
|
QComboBox *comboBox1;
|
||||||
|
|
||||||
|
@ -78,12 +83,15 @@ QSpinBox *refreshSpinbox,
|
||||||
QLabel *refreshLabel,
|
QLabel *refreshLabel,
|
||||||
*invScrShtLabel,
|
*invScrShtLabel,
|
||||||
*showfpsLabel,
|
*showfpsLabel,
|
||||||
*extendvertdivLabel;
|
*extendvertdivLabel,
|
||||||
|
*hostnameLabel;
|
||||||
|
|
||||||
QCheckBox *invScrShtCheckbox,
|
QCheckBox *invScrShtCheckbox,
|
||||||
*showfpsCheckbox,
|
*showfpsCheckbox,
|
||||||
*extendvertdivCheckbox;
|
*extendvertdivCheckbox;
|
||||||
|
|
||||||
|
QLineEdit *HostLineEdit;
|
||||||
|
|
||||||
UI_Mainwindow *mainwindow;
|
UI_Mainwindow *mainwindow;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -93,6 +101,7 @@ void refreshSpinboxChanged(int);
|
||||||
void invScrShtCheckboxChanged(int);
|
void invScrShtCheckboxChanged(int);
|
||||||
void showfpsCheckboxChanged(int);
|
void showfpsCheckboxChanged(int);
|
||||||
void extendvertdivCheckboxChanged(int);
|
void extendvertdivCheckboxChanged(int);
|
||||||
|
void hostnamechanged(QString);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
45
tmc_lan.c
45
tmc_lan.c
|
@ -41,6 +41,7 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
#include "tmc_dev.h"
|
#include "tmc_dev.h"
|
||||||
#include "utils.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 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);
|
sockfd = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
if(sockfd == -1)
|
if(sockfd == -1)
|
||||||
{
|
{
|
||||||
|
|
Ładowanie…
Reference in New Issue