BIG deep clean
This commit is contained in:
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
CAN
|
||||
Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "pican.h"
|
||||
#include "pipropertystorage.h"
|
||||
#include "piincludes_p.h"
|
||||
@@ -18,14 +36,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
//PRIVATE_DEFINITION_START(PICAN)
|
||||
//#ifdef PIP_CAN
|
||||
//int fd;
|
||||
//spi_ioc_transfer spi_ioc_tr;
|
||||
//#endif
|
||||
//PRIVATE_DEFINITION_END(PICAN)
|
||||
|
||||
|
||||
REGISTER_DEVICE(PICAN)
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*! \file pican.h
|
||||
* \brief CAN device
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
CAN
|
||||
Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PICAN_H
|
||||
#define PICAN_H
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Config parser
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -17,12 +17,14 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "piconfig.h"
|
||||
#include "pifile.h"
|
||||
#include "piiostring.h"
|
||||
#include "pistring_std.h"
|
||||
|
||||
#ifdef PIP_STD_IOSTREAM
|
||||
# include "pistring_std.h"
|
||||
# include <iostream>
|
||||
#endif
|
||||
/*! \class PIConfig
|
||||
* \brief Configuration file
|
||||
* \details This class provide handle access to configuration file.
|
||||
@@ -258,7 +260,7 @@ void PIConfig::Entry::coutt(std::ostream & s, const PIString & p) const {
|
||||
void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const {
|
||||
PIString nl = p + " ";
|
||||
if (!_value.isEmpty()) s << p << _name << " = " << _value << " (" << _type << " " << _comment << ")" << PICoutManipulators::NewLine;
|
||||
else std::cout << p << _name << std::endl;
|
||||
else s << p << _name << PICoutManipulators::NewLine;
|
||||
piForeachC (Entry * i, _children) i->piCoutt(s, nl);
|
||||
}
|
||||
|
||||
@@ -620,8 +622,6 @@ PIString PIConfig::getPrefixFromLine(PIString line, bool * exists) {
|
||||
void PIConfig::writeAll() {
|
||||
//cout << this << " write < " << size() << endl;
|
||||
_clearDev();
|
||||
//*this << "1234567894132456798\n"; return;
|
||||
//writeEntry(&root);
|
||||
buildFullNames(&root);
|
||||
Branch b = allLeaves();
|
||||
PIString prefix, tprefix;
|
||||
@@ -635,7 +635,7 @@ void PIConfig::writeAll() {
|
||||
if (b[j]->_line == i) {
|
||||
b[j]->buildLine();
|
||||
_writeDev((b[j]->_all).cutLeft(prefix.size()) + "\n");
|
||||
//cout << this << " " << b[j]->_all << endl;
|
||||
//cout << this << " " << b[j]->_all << endl;
|
||||
++j;
|
||||
} else {
|
||||
_writeDev(other[i]);
|
||||
@@ -647,7 +647,7 @@ void PIConfig::writeAll() {
|
||||
}
|
||||
if (i < other.size_s() - 1)
|
||||
_writeDev('\n');
|
||||
//cout << this << " " << other[i] << endl;
|
||||
//cout << this << " " << other[i] << endl;
|
||||
}
|
||||
} else {
|
||||
_writeDev(other[i]);
|
||||
@@ -659,7 +659,7 @@ void PIConfig::writeAll() {
|
||||
}
|
||||
if (i < other.size_s() - 1)
|
||||
_writeDev('\n');
|
||||
//cout << this << " " << other[i] << endl;
|
||||
//cout << this << " " << other[i] << endl;
|
||||
}
|
||||
}
|
||||
_flushDev();
|
||||
@@ -787,7 +787,6 @@ void PIConfig::parse() {
|
||||
//piCout << "[PIConfig] str" << str.size() << str << str.toUTF8();
|
||||
ind = str.find('=');
|
||||
if ((ind > 0) && (str[0] != '#')) {
|
||||
//name = str.left(ind).trimmed();
|
||||
tree = (prefix + str.left(ind).trimmed()).split(delim);
|
||||
if (tree.front() == "include") {
|
||||
name = str.mid(ind + 1).trimmed();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Configuration parser and writer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -94,8 +94,6 @@ public:
|
||||
bool isEntryExists(const PIString & name) const {piForeachC (Entry * i, *this) if (entryExists(i, name)) return true; return false;}
|
||||
int indexOf(const Entry * e) {for (int i = 0; i < size_s(); ++i) if (at(i) == e) return i; return -1;}
|
||||
|
||||
//void clear() {piForeach (Entry * i, *this) delete i; PIVector<Entry * >::clear();}
|
||||
|
||||
private:
|
||||
bool entryExists(const Entry * e, const PIString & name) const;
|
||||
void allLeaves(Branch & b, Entry * e) {piForeach (Entry * i, e->_children) {if (i->isLeaf()) b << i; else allLeaves(b, i);}}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Directory
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Directory
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "piincludes_p.h"
|
||||
#include "pidir.h"
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief Local directory
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Directory
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Directory
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIDIR_H
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Ethernet, UDP/TCP Broadcast/Multicast
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Ethernet, UDP/TCP Broadcast/Multicast
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "piincludes_p.h"
|
||||
#include "piethernet.h"
|
||||
@@ -216,7 +216,6 @@ PIEthernet::PIEthernet(): PIIODevice("", ReadWrite) {
|
||||
construct();
|
||||
setType(UDP);
|
||||
setParameters(PIEthernet::ReuseAddress | PIEthernet::MulticastLoop | PIEthernet::KeepConnection);
|
||||
//if (type_ != UDP) init();
|
||||
}
|
||||
|
||||
|
||||
@@ -297,13 +296,9 @@ bool PIEthernet::init() {
|
||||
}
|
||||
if (params[PIEthernet::ReuseAddress]) ethSetsockoptBool(sock, SOL_SOCKET, SO_REUSEADDR);
|
||||
if (params[PIEthernet::Broadcast]) ethSetsockoptBool(sock, SOL_SOCKET, SO_BROADCAST);
|
||||
//if (type() == PIEthernet::TCP_Client) ethSetsockoptBool(sock, SOL_SOCKET, SO_KEEPALIVE);
|
||||
applyTimeouts();
|
||||
applyOptInt(IPPROTO_IP, IP_TTL, TTL());
|
||||
// piCoutObj << "inited" << path();
|
||||
//cout << "inited " << sock << ": bc = " << params << endl;
|
||||
//fcntl(sock, F_SETFL, 0/*O_NONBLOCK*/);
|
||||
//piCoutObj << "init" << sock;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -360,7 +355,6 @@ bool PIEthernet::openDevice() {
|
||||
init();
|
||||
if (sock == -1 || path().isEmpty()) return false;
|
||||
addr_r.set(path());
|
||||
//Address::splitIPPort(path(), &ip_, &port_);
|
||||
if (type() == TCP_Client)
|
||||
connecting_ = true;
|
||||
if (type() != UDP || mode() == PIIODevice::WriteOnly)
|
||||
@@ -387,7 +381,6 @@ bool PIEthernet::openDevice() {
|
||||
opened_ = true;
|
||||
while (!mcast_queue.isEmpty())
|
||||
joinMulticastGroup(mcast_queue.dequeue());
|
||||
//cout << "!" << endl;
|
||||
applyTimeouts();
|
||||
applyOptInt(IPPROTO_IP, IP_TTL, TTL());
|
||||
addr_lr.clear();
|
||||
@@ -479,9 +472,6 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) {
|
||||
return true;
|
||||
}
|
||||
PIFlags<Parameters> params = parameters();
|
||||
//#ifndef QNX
|
||||
//if (!params[Broadcast])
|
||||
//;piCoutObj << "Warning: \"Broadcast\" parameter not set, \"joinMulticastGroup(\"" << group << "\")\" may be useless!";
|
||||
addr_r.set(path());
|
||||
#ifndef FREERTOS
|
||||
struct ip_mreqn mreq;
|
||||
@@ -508,11 +498,6 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) {
|
||||
mreq.imr_interface.s_addr = addr_r.ip();
|
||||
#endif
|
||||
|
||||
/*#ifndef WINDOWS
|
||||
PIEthernet::InterfaceList il = interfaces();
|
||||
const PIEthernet::Interface * ci = il.getByAddress(ip_);
|
||||
if (ci != 0) mreq.imr_ifindex = ci->index;
|
||||
#endif*/
|
||||
//piCout << "join group" << group << "ip" << ip_ << "with index" << mreq.imr_ifindex << "socket" << sock;
|
||||
mreq.imr_multiaddr.s_addr = inet_addr(group.dataAscii());
|
||||
if (ethSetsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) != 0) {
|
||||
@@ -522,20 +507,6 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) {
|
||||
if (params[PIEthernet::MulticastLoop]) ethSetsockoptInt(sock, IPPROTO_IP, IP_MULTICAST_LOOP);
|
||||
applyOptInt(IPPROTO_IP, IP_MULTICAST_TTL, multicastTTL());
|
||||
if (!mcast_groups.contains(group)) mcast_groups << group;
|
||||
//#else
|
||||
// parseAddress(path(), &ip_, &port_);
|
||||
// struct ip_mreq mreq;
|
||||
// memset(&mreq, 0, sizeof(mreq));
|
||||
// mreq.imr_interface.s_addr = inet_addr(ip_.dataAscii());
|
||||
// mreq.imr_multiaddr.s_addr = inet_addr(group.dataAscii());
|
||||
// if (ethSetsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) != 0) {
|
||||
// piCoutObj << "Can`t join multicast group " << group << ", " << ethErrorString();
|
||||
// return false;
|
||||
// }
|
||||
// if (params[PIEthernet::MulticastLoop]) ethSetsockoptInt(sock, IPPROTO_IP, IP_MULTICAST_LOOP);
|
||||
// applyOptInt(IPPROTO_IP, IP_MULTICAST_TTL, multicastTTL());
|
||||
// if (!mcast_groups.contains(group)) mcast_groups << group;
|
||||
//#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -601,22 +572,6 @@ bool PIEthernet::connect(bool threaded) {
|
||||
connected();
|
||||
}
|
||||
return connected_;
|
||||
/*if (sock == -1) return false;
|
||||
memset(addr_, 0, sizeof(*addr_));
|
||||
parseAddress(path_, &ip_, &port_);
|
||||
PRIVATE->addr_.sin_port = htons(port_);
|
||||
PRIVATE->addr_.sin_addr.s_addr = inet_addr(ip_.data());
|
||||
PRIVATE->addr_.sin_family = AF_INET;
|
||||
#ifdef QNX
|
||||
PRIVATE->addr_.sin_len = sizeof(*addr_);
|
||||
#endif
|
||||
//piCoutObj << "connect to " << ip << ":" << port_;
|
||||
connected_ = (::connect(sock, (sockaddr * )addr_, sizeof(*addr_)) == 0);
|
||||
if (!connected_)
|
||||
piCoutObj << "Can`t connect to " << ip_ << ":" << port_ << ", " << ethErrorString();
|
||||
opened_ = connected_;
|
||||
if (connected_) connected();
|
||||
return connected_;*/
|
||||
}
|
||||
|
||||
|
||||
@@ -664,7 +619,7 @@ bool PIEthernet::listen(bool threaded) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//#include <QDebug>
|
||||
|
||||
int PIEthernet::readDevice(void * read_to, int max_size) {
|
||||
//piCout << "read" << sock;
|
||||
if (sock == -1) init();
|
||||
@@ -704,10 +659,8 @@ int PIEthernet::readDevice(void * read_to, int max_size) {
|
||||
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
|
||||
#endif
|
||||
//piCoutObj << "connect to " << ip_ << ":" << port_ << "...";
|
||||
//qDebug() << "connect to " << ip_.data() << ":" << port_ << sock << PRIVATE->addr_.sin_addr.s_addr << "...";
|
||||
connected_ = (::connect(sock, (sockaddr * )&(PRIVATE->addr_), sizeof(PRIVATE->addr_)) == 0);
|
||||
//piCoutObj << "connect to " << ip_ << ":" << port_ << connected_;
|
||||
//qDebug() << "connect to " << ip_.data() << ":" << port_ << connected_;
|
||||
if (!connected_)
|
||||
piCoutObj << "Can`t connect to" << addr_r << "," << ethErrorString();
|
||||
opened_ = connected_;
|
||||
@@ -717,13 +670,11 @@ int PIEthernet::readDevice(void * read_to, int max_size) {
|
||||
} else
|
||||
piMSleep(10);
|
||||
//piCout << "connected to" << path();
|
||||
//qDebug() << "connected to" << path().data();
|
||||
}
|
||||
if (!connected_) return -1;
|
||||
errorClear();
|
||||
rs = ethRecv(sock, read_to, max_size);
|
||||
//piCoutObj << "readed" << rs;
|
||||
//qDebug() << "readed" << rs;
|
||||
if (rs <= 0) {
|
||||
lerr = ethErrorCore();
|
||||
//piCoutObj << "readed error" << lerr << errorString().data() << parameters()[DisonnectOnTimeout];
|
||||
@@ -735,7 +686,6 @@ int PIEthernet::readDevice(void * read_to, int max_size) {
|
||||
if ((lerr == EWOULDBLOCK || lerr == EAGAIN) && !parameters()[DisonnectOnTimeout]) {
|
||||
#endif
|
||||
//piCoutObj << errorString();
|
||||
//piMSleep(10);
|
||||
return -1;
|
||||
}
|
||||
if (connected_) {
|
||||
@@ -749,7 +699,6 @@ int PIEthernet::readDevice(void * read_to, int max_size) {
|
||||
//piCoutObj << "eth" << ip_ << "disconnected";
|
||||
}
|
||||
if (rs > 0) received(read_to, rs);
|
||||
//qDebug() << "return from read" << rs;
|
||||
return rs;
|
||||
case UDP:
|
||||
memset(&PRIVATE->raddr_, 0, sizeof(PRIVATE->raddr_));
|
||||
@@ -757,14 +706,11 @@ int PIEthernet::readDevice(void * read_to, int max_size) {
|
||||
if (rs > 0) {
|
||||
addr_lr.set(uint(PRIVATE->raddr_.sin_addr.s_addr), ntohs(PRIVATE->raddr_.sin_port));
|
||||
//piCoutObj << "read from" << ip_r << ":" << port_r << rs << "bytes";
|
||||
//piCout << "received from" << lastReadAddress();
|
||||
received(read_to, rs);
|
||||
}
|
||||
//else piCoutObj << "read returt" << rs << ", error" << ethErrorString();
|
||||
return rs;
|
||||
//return ::read(sock, read_to, max_size);
|
||||
default: break;
|
||||
//return ::read(sock, (char * )read_to, max_size);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -801,8 +747,7 @@ int PIEthernet::writeDevice(const void * data, int max_size) {
|
||||
return ret;
|
||||
case UDP:
|
||||
PRIVATE->saddr_.sin_port = htons(addr_s.port());
|
||||
/*if (params[PIEthernet::Broadcast]) PRIVATE->saddr_.sin_addr.s_addr = INADDR_BROADCAST;
|
||||
else*/ PRIVATE->saddr_.sin_addr.s_addr = addr_s.ip();
|
||||
PRIVATE->saddr_.sin_addr.s_addr = addr_s.ip();
|
||||
PRIVATE->saddr_.sin_family = AF_INET;
|
||||
//piCoutObj << "write to" << ip_s << ":" << port_s << "socket" << sock_s << max_size << "bytes ...";
|
||||
return ethSendto(sock_s, data, max_size,
|
||||
@@ -843,7 +788,6 @@ int PIEthernet::writeDevice(const void * data, int max_size) {
|
||||
}
|
||||
return ret;
|
||||
default: break;
|
||||
//return ::read(sock, read_to, max_size);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -907,10 +851,6 @@ void PIEthernet::server_func(void * eth) {
|
||||
ce->clients_mutex.unlock();
|
||||
ce->newConnection(e);
|
||||
//cout << "connected " << ip << endl;
|
||||
//char d[256];
|
||||
//cout << " recv " << recv(s, d, 256, 0) << endl;
|
||||
//cout << recv(ce->clients_.back()->sock, d, 256, 0) << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1029,8 +969,6 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
|
||||
ci.index = pAdapter->Index;
|
||||
ci.mac = macFromBytes(PIByteArray(pAdapter->Address, pAdapter->AddressLength));
|
||||
ci.flags = PIEthernet::ifActive | PIEthernet::ifRunning;
|
||||
//if (ret->ifa_flags & IFF_BROADCAST) ci.flags |= PIEthernet::ifBroadcast;
|
||||
//if (ret->ifa_flags & IFF_MULTICAST) ci.flags |= PIEthernet::ifMulticast;
|
||||
if (pAdapter->Type == MIB_IF_TYPE_PPP) ci.flags |= PIEthernet::ifPTP;
|
||||
if (pAdapter->Type == MIB_IF_TYPE_LOOPBACK) ci.flags |= PIEthernet::ifLoopback;
|
||||
ci.broadcast.clear();
|
||||
@@ -1047,10 +985,6 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
|
||||
il << ci;
|
||||
as = as->Next;
|
||||
}
|
||||
/*if (ci.flags[PIEthernet::ifBroadcast])
|
||||
ci.broadcast = getSockAddr(ret->ifa_broadaddr);
|
||||
if (ci.flags[PIEthernet::ifPTP])
|
||||
ci.ptp = getSockAddr(ret->ifa_dstaddr);*/
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
} else
|
||||
@@ -1060,40 +994,6 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
|
||||
#else
|
||||
#ifdef FREERTOS
|
||||
#else
|
||||
/*# ifdef QNX
|
||||
PIStringList il, sl;
|
||||
PIProcess proc;
|
||||
proc.setGrabOutput(true);
|
||||
proc.exec(ifconfigPath.c_str(), "-l");
|
||||
if (!proc.waitForFinish(1000)) return sl;
|
||||
PIString out(proc.readOutput());
|
||||
il = out.split(" ");
|
||||
il.removeAll("");
|
||||
piForeachC (PIString & i, il) {
|
||||
proc.exec(ifconfigPath.c_str(), i);
|
||||
if (!proc.waitForFinish(1000)) return il;
|
||||
sl << i.trimmed();
|
||||
out = proc.readOutput();
|
||||
int al = out.length();
|
||||
al = (al - out.replaceAll("alias", "").length()) / 5;
|
||||
for (int j = 0; j < al; ++j)
|
||||
sl << i.trimmed() + ":" + PIString::fromNumber(j);
|
||||
}
|
||||
return sl;
|
||||
# else
|
||||
PIStringList sl;
|
||||
PIProcess proc;
|
||||
proc.setGrabOutput(true);
|
||||
proc.exec(ifconfigPath.c_str(), "-s");
|
||||
if (!proc.waitForFinish(1000)) return sl;
|
||||
PIString out(proc.readOutput());
|
||||
out.cutLeft(out.find('\n') + 1);
|
||||
while (!out.isEmpty()) {
|
||||
sl << out.left(out.find(' '));
|
||||
out.cutLeft(out.find('\n') + 1);
|
||||
}
|
||||
return sl;
|
||||
# endif*/
|
||||
# ifdef ANDROID
|
||||
struct ifconf ifc;
|
||||
int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||
@@ -1222,38 +1122,6 @@ PIEthernet::Address PIEthernet::interfaceAddress(const PIString & interface_) {
|
||||
|
||||
|
||||
PIVector<PIEthernet::Address> PIEthernet::allAddresses() {
|
||||
/*#ifdef WINDOWS
|
||||
PIStringList al;
|
||||
PIString ca;
|
||||
PIP_ADAPTER_INFO pAdapterInfo, pAdapter = 0;
|
||||
int ret = 0;
|
||||
ulong ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
||||
pAdapterInfo = (IP_ADAPTER_INFO * ) HeapAlloc(GetProcessHeap(), 0, (sizeof (IP_ADAPTER_INFO)));
|
||||
if (pAdapterInfo == 0) {
|
||||
piCout << "[PIEthernet] Error allocating memory needed to call GetAdaptersinfo";
|
||||
return PIStringList();
|
||||
}
|
||||
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
|
||||
HeapFree(GetProcessHeap(), 0, (pAdapterInfo));
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *) HeapAlloc(GetProcessHeap(), 0, (ulOutBufLen));
|
||||
if (pAdapterInfo == 0) {
|
||||
piCout << "[PIEthernet] Error allocating memory needed to call GetAdaptersinfo";
|
||||
return PIStringList();
|
||||
}
|
||||
}
|
||||
if ((ret = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
|
||||
pAdapter = pAdapterInfo;
|
||||
while (pAdapter) {
|
||||
ca = PIString(pAdapter->IpAddressList.IpAddress.String);
|
||||
if (ca != "0.0.0.0") al << ca;
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
} else
|
||||
piCout << "[PIEthernet] GetAdaptersInfo failed with error: " << ret;
|
||||
if (pAdapterInfo)
|
||||
HeapFree(GetProcessHeap(), 0, (pAdapterInfo));
|
||||
return al;
|
||||
#else*/
|
||||
PIEthernet::InterfaceList il = interfaces();
|
||||
PIVector<Address> ret;
|
||||
bool has_127 = false;
|
||||
@@ -1266,13 +1134,11 @@ PIVector<PIEthernet::Address> PIEthernet::allAddresses() {
|
||||
// piCout << "[PIEthernet::allAddresses]" << al;
|
||||
if (!has_127) ret << Address("127.0.0.1");
|
||||
return ret;
|
||||
//#endif
|
||||
}
|
||||
|
||||
|
||||
// System wrap
|
||||
|
||||
|
||||
int PIEthernet::ethErrorCore() {
|
||||
#ifdef WINDOWS
|
||||
return WSAGetLastError();
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief Ethernet device
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Ethernet, UDP/TCP Broadcast/Multicast
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Ethernet, UDP/TCP Broadcast/Multicast
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIETHERNET_H
|
||||
@@ -211,8 +211,6 @@ public:
|
||||
//! Returns parameters
|
||||
PIFlags<PIEthernet::Parameters> parameters() const {return (PIFlags<PIEthernet::Parameters>)(property(PIStringAscii("parameters")).toInt());}
|
||||
|
||||
//PIByteArray macAddress() {if (!init_) init(); struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); memcpy(ifr.ifr_name, "eth0", 5); ioctl(sock, SIOCSIFHWADDR, &ifr); return PIByteArray(&ifr.ifr_hwaddr.sa_data, 6);}
|
||||
|
||||
//! Returns %PIEthernet type
|
||||
Type type() const {return (Type)(property(PIStringAscii("type")).toInt());}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piincludes_p.h"
|
||||
#include "pifile.h"
|
||||
#include "pidir.h"
|
||||
@@ -153,15 +154,6 @@ bool PIFile::openTemporary(PIIODevice::DeviceMode mode) {
|
||||
}
|
||||
|
||||
|
||||
//PIFile::PIFile(const PIFile & other) {
|
||||
// PRIVATE->fd = 0;
|
||||
// fdi = -1;
|
||||
// setPrecision(other.prec_);
|
||||
// setPath(other.path());
|
||||
// mode_ = other.mode_;
|
||||
//}
|
||||
|
||||
|
||||
bool PIFile::openDevice() {
|
||||
close();
|
||||
PIString p = path();
|
||||
@@ -632,20 +624,6 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
||||
ret.size = filesize.QuadPart;
|
||||
ret.time_access = FILETIME2PIDateTime(fi.ftLastAccessTime);
|
||||
ret.time_modification = FILETIME2PIDateTime(fi.ftLastWriteTime);
|
||||
/*PIByteArray sec;
|
||||
DWORD sec_n(0);
|
||||
//SECURITY_DESCRIPTOR sec;
|
||||
GetFileSecurity(path.data(), DACL_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION, (SECURITY_DESCRIPTOR*)sec.data(), 0, &sec_n);
|
||||
sec.resize(sec_n);
|
||||
GetFileSecurity(path.data(), DACL_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION, (SECURITY_DESCRIPTOR*)sec.data(), sec.size(), &sec_n);
|
||||
errorClear();
|
||||
SID sid; BOOL def;
|
||||
GetSecurityDescriptorGroup((PSECURITY_DESCRIPTOR)sec.data(), &sid, &def);
|
||||
char * s(0);
|
||||
ConvertSidToStringSid((PSID)&sid, s);
|
||||
piCout << s;
|
||||
LocalFree(s);
|
||||
//ret.id_user = ;*/
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
#else
|
||||
@@ -708,7 +686,6 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
|
||||
if (!info.perm_user.write) attr |= FILE_ATTRIBUTE_READONLY;
|
||||
if (SetFileAttributes((LPCTSTR)(fp.data()), attr) == 0) {
|
||||
piCout << "[PIFile] applyFileInfo: \"SetFileAttributes\" error:" << errorString();
|
||||
//return false;
|
||||
}
|
||||
HANDLE hFile = 0;
|
||||
if ((attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
|
||||
@@ -724,7 +701,6 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
#else
|
||||
//#ifndef ESP_PLATFORM
|
||||
int mode(0);
|
||||
if (info.perm_user.read) mode |= S_IRUSR;
|
||||
if (info.perm_user.write) mode |= S_IWUSR;
|
||||
@@ -737,11 +713,9 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
|
||||
if (info.perm_other.exec) mode |= S_IXOTH;
|
||||
if (chmod(fp.data(), mode) != 0) {
|
||||
piCout << "[PIFile] applyFileInfo: \"chmod\" error:" << errorString();
|
||||
//return false;
|
||||
}
|
||||
if (chown(fp.data(), info.id_user, info.id_group) != 0) {
|
||||
piCout << "[PIFile] applyFileInfo: \"chown\" error:" << errorString();
|
||||
//return false;
|
||||
}
|
||||
struct timeval tm[2];
|
||||
PISystemTime st = info.time_access.toSystemTime();
|
||||
@@ -752,9 +726,7 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
|
||||
tm[1].tv_usec = st.nanoseconds / 1000;
|
||||
if (utimes(fp.data(), tm) != 0) {
|
||||
piCout << "[PIFile] applyFileInfo: \"utimes\" error:" << errorString();
|
||||
//return false;
|
||||
}
|
||||
//#endif
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief Local file
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
File
|
||||
PIP - Platform Independent Primitives
|
||||
File
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIFILE_H
|
||||
@@ -91,13 +91,8 @@ public:
|
||||
//! Open temporary file with open mode "mode"
|
||||
bool openTemporary(PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||
|
||||
// PIFile(const PIFile & other);
|
||||
|
||||
~PIFile() {closeDevice();}
|
||||
|
||||
//PIFile & operator =(const PIFile & f) {path_ = f.path_; type_ = f.type_; return *this;}
|
||||
|
||||
|
||||
//! Immediate write all buffered data to disk
|
||||
void flush();
|
||||
|
||||
@@ -112,7 +107,6 @@ public:
|
||||
|
||||
//! Move read/write position to text line number "line"
|
||||
void seekToLine(llong line);
|
||||
//void fill(char c) {stream.fill(c);}
|
||||
|
||||
//! Read one char and return it
|
||||
char readChar();
|
||||
@@ -178,8 +172,6 @@ public:
|
||||
//! Write to file binary content of "v"
|
||||
PIFile & writeBinary(const double v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//PIFile & operator =(const PIFile & f) {PIIODevice::setPath(f.path()); mode_ = f.mode_; return *this;}
|
||||
|
||||
//! Write to file text representation of "v"
|
||||
PIFile & operator <<(const char v);
|
||||
//! Write to file string "v"
|
||||
@@ -209,7 +201,6 @@ public:
|
||||
//! Write to file text representation of "v" with precision \a precision()
|
||||
PIFile & operator <<(double v);
|
||||
|
||||
|
||||
//! Read from file text representation of "v"
|
||||
PIFile & operator >>(char & v);
|
||||
//! Read from file text representation of "v"
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIP - Platform Independent Primitives
|
||||
GPIO
|
||||
Andrey Bychkov work.a.b@yandex.ru, Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pigpio.h"
|
||||
@@ -139,7 +139,6 @@ bool PIGPIO::getPinState(int gpio_num) {
|
||||
}
|
||||
}
|
||||
//piCoutObj << "pinState" << gpio_num << ":" << ret << (int)r << errorString();
|
||||
//initGPIO(gpio_num, PIGPIO::In); TODO: discuss - why?
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@@ -193,7 +192,7 @@ void PIGPIO::end() {
|
||||
}
|
||||
|
||||
|
||||
void PIGPIO::initPin(int gpio_num, Direction dir) { //, PullUpDownControl pull) {
|
||||
void PIGPIO::initPin(int gpio_num, Direction dir) {
|
||||
#ifdef GPIO_SYS_CLASS
|
||||
PIMutexLocker ml(mutex);
|
||||
GPIOData & g(gpio_[gpio_num]);
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief GPIO
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIP - Platform Independent Primitives
|
||||
GPIO
|
||||
Andrey Bychkov work.a.b@yandex.ru, Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIGPIO_H
|
||||
@@ -38,16 +38,12 @@ public:
|
||||
In /** Input direction (read) */,
|
||||
Out /** Output direction (write) */
|
||||
};
|
||||
//enum PullUpDownControl {NoPull, PullUp, PullDown};
|
||||
|
||||
|
||||
//! \brief Returns singleton object of %PIGPIO
|
||||
static PIGPIO * instance();
|
||||
|
||||
|
||||
//! \brief Initialize pin \"gpio_num\" for \"dir\" mode
|
||||
void initPin(int gpio_num, Direction dir = PIGPIO::In);//, PullUpDownControl pull);
|
||||
|
||||
void initPin(int gpio_num, Direction dir = PIGPIO::In);
|
||||
|
||||
//! \brief Set pin \"gpio_num\" value to \"value\"
|
||||
void pinSet (int gpio_num, bool value);
|
||||
@@ -61,7 +57,6 @@ public:
|
||||
//! \brief Returns pin \"gpio_num\" state
|
||||
bool pinState(int gpio_num);
|
||||
|
||||
|
||||
//! \brief Starts watch for pin \"gpio_num\".
|
||||
//! \details Pins watching starts only with \a PIThread::start() function!
|
||||
//! This function doesn`t affect thread state
|
||||
@@ -77,7 +72,6 @@ public:
|
||||
//! This function doesn`t affect thread state
|
||||
void clearWatch();
|
||||
|
||||
|
||||
EVENT2(pinChanged, int, gpio_num, bool, new_value)
|
||||
|
||||
//! \events
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIIODevice wrapper around PIByteArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
PIIODevice wrapper around PIByteArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piiobytearray.h"
|
||||
@@ -27,8 +27,6 @@
|
||||
* This class sllow you to use PIByteArray as PIIODevice and pass it to, e.g. PIConfig
|
||||
*/
|
||||
|
||||
//REGISTER_DEVICE(PIIOByteArray);
|
||||
|
||||
|
||||
PIIOByteArray::PIIOByteArray(PIByteArray *buffer, PIIODevice::DeviceMode mode) {
|
||||
open(buffer, mode);
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief PIIODevice wrapper around PIByteArray
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIP - Platform Independent Primitives
|
||||
PIIODevice wrapper around PIByteArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIIOBYTEARRAY_H
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Abstract input/output device
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Abstract input/output device
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piiodevice.h"
|
||||
@@ -191,7 +191,6 @@ void PIIODevice::_init() {
|
||||
// setThreadedReadBufferSize(512);
|
||||
#else
|
||||
threaded_read_buffer_size = 4096;
|
||||
// setThreadedReadBufferSize(4096);
|
||||
#endif
|
||||
timer.setName("__S__.PIIODevice.reopen_timer");
|
||||
write_thread.setName("__S__.PIIODevice.write_thread");
|
||||
@@ -268,7 +267,6 @@ void PIIODevice::begin() {
|
||||
//cout << " ok\n";
|
||||
return;
|
||||
}
|
||||
//init();
|
||||
if (!timer.isRunning() && isReopenEnabled()) timer.start(reopenTimeout());
|
||||
}
|
||||
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief Abstract input/output device
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Abstract input/output device
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Abstract input/output device
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIIODEVICE_H
|
||||
@@ -209,9 +209,6 @@ public:
|
||||
//! Write maximum "max_size" bytes of "data" to device
|
||||
int write(const void * data, int max_size) {return writeDevice(data, max_size);}
|
||||
|
||||
//int write(const PIByteArray & data) {return writeDevice(data.data(), data.size_s());}
|
||||
|
||||
|
||||
//! Read from device for "timeout_ms" milliseconds and return readed data as PIByteArray. Timeout should to be greater than 0
|
||||
PIByteArray readForTime(double timeout_ms);
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Module includes
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Module includes
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIIODEVICESMODULE_H
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIIODevice wrapper around PIString
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
PIIODevice wrapper around PIString
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piiostring.h"
|
||||
@@ -27,8 +27,6 @@
|
||||
* This class allow you to use PIString as PIIODevice and pass it to, e.g. PIConfig
|
||||
*/
|
||||
|
||||
//REGISTER_DEVICE(PIIOString);
|
||||
|
||||
|
||||
PIIOString::PIIOString(PIString * string, PIIODevice::DeviceMode mode) {
|
||||
open(string, mode);
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief PIIODevice wrapper around PIString
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIIODevice wrapper around PIString
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
PIIODevice wrapper around PIString
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIIOSTRING_H
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Peer - named I/O ethernet node
|
||||
PIP - Platform Independent Primitives
|
||||
Peer - named I/O ethernet node
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pipeer.h"
|
||||
@@ -79,7 +79,6 @@ PIPeer::PeerData::~PeerData() {
|
||||
|
||||
|
||||
void PIPeer::PeerData::dtThread() {
|
||||
// << "send DT ...";
|
||||
dt_out.send(data);
|
||||
//piCoutObj << "send DT done";
|
||||
}
|
||||
@@ -172,13 +171,10 @@ PIPeer::PIPeer(const PIString & n): PIIODevice(), inited__(false), eth_tcp_srv(P
|
||||
read_buffer_size = 128;
|
||||
self_info.dist = 0;
|
||||
self_info.time = PISystemTime::current();
|
||||
//joinMulticastGroup("239.240.241.242");
|
||||
randomize();
|
||||
//id_ = self_info.name + "_" + PIString::fromNumber(randomi());
|
||||
CONNECTU(&sync_timer, tickEvent, this, timerEvent);
|
||||
prev_ifaces = PIEthernet::interfaces();
|
||||
no_timer = false;
|
||||
// initNetwork();
|
||||
sync_timer.addDelimiter(5);
|
||||
}
|
||||
|
||||
@@ -231,7 +227,6 @@ void PIPeer::timerEvent(void * data, int delim) {
|
||||
checkNetwork();
|
||||
break;
|
||||
}
|
||||
//send("broadcast", 9);
|
||||
}
|
||||
|
||||
|
||||
@@ -269,7 +264,6 @@ void PIPeer::initEths(PIStringList al) {
|
||||
|
||||
|
||||
void PIPeer::initMBcasts(PIStringList al) {
|
||||
// destroyMBcasts();
|
||||
PIEthernet * ce;
|
||||
const PIEthernet::Interface * cint;
|
||||
PIString nm;
|
||||
@@ -316,7 +310,6 @@ void PIPeer::initMBcasts(PIStringList al) {
|
||||
//piCoutObj << "invalid address for bcast" << a;
|
||||
}
|
||||
}
|
||||
// eth_lo.setDebug(false);
|
||||
eth_lo.setName("__S__PIPeer_eth_loopback");
|
||||
eth_lo.setParameters(PIEthernet::SeparateSockets);
|
||||
eth_lo.init();
|
||||
@@ -398,17 +391,6 @@ PIPeer::PeerInfo * PIPeer::quickestPeer(const PIString & to) {
|
||||
if (!peers_map.contains(to)) return 0;
|
||||
//piCout << "*** search quickest peer" << to;
|
||||
PIVector<PeerInfo * > tp = addresses_map.value(to);
|
||||
/*PeerInfo * dp = 0;
|
||||
int mping = 0x7FFFFFFF;
|
||||
for (int i = 0; i < tp.size_s(); ++i) {
|
||||
int p = tp[i]->ping();
|
||||
if (mping > p && p > 0) {
|
||||
mping = p;
|
||||
dp = tp[i];
|
||||
}
|
||||
}
|
||||
//piCout << "*** search quickest peer: found" << (dp ? dp->name : "0");
|
||||
return dp;*/
|
||||
if (tp.isEmpty()) return 0;
|
||||
return tp.back();
|
||||
}
|
||||
@@ -471,7 +453,6 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
||||
int type, cnt;
|
||||
PIString from, to;
|
||||
ba >> type;
|
||||
// PIMutexLocker locker(eth_mutex);
|
||||
eth_mutex.lock();
|
||||
// piCout << "dataRead lock";
|
||||
if (type == 5) { // ping request
|
||||
@@ -728,10 +709,8 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
||||
|
||||
|
||||
bool PIPeer::sendToNeighbour(PIPeer::PeerInfo * peer, const PIByteArray & ba) {
|
||||
//if (peer->_neth == 0) return false;
|
||||
PIEthernet::Address addr = peer->fastestAddress();
|
||||
//piCout << "[PIPeer] sendToNeighbour" << peer->name << addr << ba.size_s() << "bytes ...";
|
||||
//bool ok = peer->_neth->send(peer->_naddress, ba.data(), ba.size_s());
|
||||
send_mutex.lock();
|
||||
bool ok = eth_send.send(addr, ba);
|
||||
//piCout << "[PIPeer] sendToNeighbour" << (ok ? "ok" : "fail");
|
||||
@@ -745,17 +724,11 @@ void PIPeer::sendMBcast(const PIByteArray & ba) {
|
||||
send_mc_mutex.lock();
|
||||
// piCout << "sendMBcast" << ba.size() << "bytes ...";
|
||||
piForeach (PIEthernet * e, eths_mcast) {
|
||||
//errorClear();
|
||||
//piCout << "send to" << e->path() << e->sendAddress();// << e->send(ba);
|
||||
//piCout << PIEthernet::ethErrorString();
|
||||
if (e->isOpened())
|
||||
if (e->send(ba))
|
||||
diag_s.sended(ba.size_s());
|
||||
}
|
||||
piForeach (PIEthernet * e, eths_bcast) {
|
||||
//errorClear();
|
||||
//piCout << "send to" << e->path() << e->sendAddress();// << e->send(ba);
|
||||
//piCout << PIEthernet::ethErrorString();
|
||||
if (e->isOpened())
|
||||
if (e->send(ba))
|
||||
diag_s.sended(ba.size_s());
|
||||
@@ -864,10 +837,6 @@ bool PIPeer::openDevice() {
|
||||
diag_s.reset();
|
||||
//piCoutObj << "open...";
|
||||
return true;
|
||||
// PIMutexLocker ml(peers_mutex);
|
||||
// if (trust_peer.isEmpty())
|
||||
// return !peers.isEmpty();
|
||||
// return hasPeer(trust_peer);
|
||||
}
|
||||
|
||||
|
||||
@@ -931,8 +900,6 @@ void PIPeer::checkNetwork() {
|
||||
|
||||
void PIPeer::reinit() {
|
||||
no_timer = true;
|
||||
// timer.stop();
|
||||
// timer.clearDelimiters();
|
||||
PIMutexLocker mbl(mc_mutex);
|
||||
PIMutexLocker ethl(eth_mutex);
|
||||
// piCout << "reinit lock";
|
||||
@@ -940,14 +907,6 @@ void PIPeer::reinit() {
|
||||
PIMutexLocker sl(send_mutex);
|
||||
initNetwork();
|
||||
sendSelfInfo();
|
||||
// eth_send.close();
|
||||
// eth_lo.stopThreadedRead();
|
||||
// eth_lo.close();
|
||||
// eth_send.init();
|
||||
// eth_send.open();
|
||||
// eth_lo.startThreadedRead();
|
||||
// timer.addDelimiter(5);
|
||||
// timer.start(1000);
|
||||
no_timer = false;
|
||||
if (!sync_timer.isRunning()) sync_timer.start(1000);
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief Peering net node
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Peer - named I/O ethernet node, forming self-organized peering network
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Peer - named I/O ethernet node, forming self-organized peering network
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIPEER_H
|
||||
@@ -47,7 +47,6 @@ public:
|
||||
struct PeerAddress {
|
||||
PeerAddress(const PIEthernet::Address & a = PIEthernet::Address(), const PIEthernet::Address & m = PIEthernet::Address("255.255.255.0"));
|
||||
bool isAvailable() const {return ping > 0;}
|
||||
//inline const Address & operator =(const Address & v) {address = v.address; netmask = v.netmask; piCout << "!!!!!!!!!" << last_ping; return *this;}
|
||||
PIEthernet::Address address;
|
||||
PIEthernet::Address netmask;
|
||||
double ping; // ms
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
COM
|
||||
PIP - Platform Independent Primitives
|
||||
COM
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piincludes_p.h"
|
||||
#include "piserial.h"
|
||||
#include "piconfig.h"
|
||||
@@ -627,16 +628,6 @@ void PISerial::applySettings() {
|
||||
PRIVATE->desc.Parity = params[PISerial::ParityOdd] ? 1 : 2;
|
||||
}
|
||||
PRIVATE->desc.StopBits = params[PISerial::TwoStopBits] ? TWOSTOPBITS : ONESTOPBIT;
|
||||
|
||||
/*PRIVATE->desc.fOutxCtsFlow = 0;
|
||||
PRIVATE->desc.fOutxDsrFlow = 0;
|
||||
PRIVATE->desc.fDtrControl = 0;
|
||||
PRIVATE->desc.fRtsControl = 0;
|
||||
PRIVATE->desc.fInX = 0;
|
||||
PRIVATE->desc.fOutX = 0;
|
||||
PRIVATE->desc.fBinary = 1;
|
||||
PRIVATE->desc.fAbortOnError = 0;
|
||||
PRIVATE->desc.fNull = 0;*/
|
||||
if (SetCommState(PRIVATE->hCom, &PRIVATE->desc) == -1) {
|
||||
piCoutObj << "Unable to set comm state for \"" << path() << "\"";
|
||||
return;
|
||||
@@ -704,7 +695,6 @@ int PISerial::readDevice(void * read_to, int max_size) {
|
||||
if (!canRead()) return -1;
|
||||
if (sending) return -1;
|
||||
// piCoutObj << "com event ...";
|
||||
//WaitCommEvent(PRIVATE->hCom, 0, 0);
|
||||
//piCoutObj << "read ..." << PRIVATE->hCom;
|
||||
ReadFile(PRIVATE->hCom, read_to, max_size, &PRIVATE->readed, 0);
|
||||
DWORD err = GetLastError();
|
||||
@@ -729,12 +719,6 @@ int PISerial::writeDevice(const void * data, int max_size) {
|
||||
return -1;
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
// if (block_write != wait) {
|
||||
// block_write = wait;
|
||||
// piCoutObj << "set timeout ...";
|
||||
// setReadIsBlocking(block_read);
|
||||
// piCoutObj << "set timeout ok";
|
||||
// }
|
||||
DWORD wrote;
|
||||
// piCoutObj << "send ...";// << max_size;// << ": " << PIString((char*)data, max_size);
|
||||
sending = true;
|
||||
@@ -943,24 +927,6 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
|
||||
PIVector<DeviceInfo> ret;
|
||||
DeviceInfo di;
|
||||
#ifdef WINDOWS
|
||||
/*HKEY key = 0;
|
||||
RegOpenKey(HKEY_LOCAL_MACHINE, (LPCTSTR)"HARDWARE\\DEVICEMAP\\SERIALCOMM", &key);
|
||||
if (key != 0) {
|
||||
char name[1024], data[1024];
|
||||
DWORD index = 0;
|
||||
LONG res = ERROR_SUCCESS;
|
||||
while (res != ERROR_NO_MORE_ITEMS) {
|
||||
memset(name, 0, 1024);
|
||||
memset(data, 0, 1024);
|
||||
DWORD name_len = 1024, data_len = 1024, type = 0;
|
||||
res = RegEnumValue(key, index, (LPTSTR)name, &name_len, NULL, &type, (uchar * )data, &data_len);
|
||||
if (res == ERROR_NO_MORE_ITEMS) break;
|
||||
di.path = PIString(data, data_len).trim();
|
||||
ret << di;
|
||||
index++;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
}*/
|
||||
static const GUID guids[] = {GUID_DEVINTERFACE_MODEM, GUID_DEVINTERFACE_COMPORT};
|
||||
static const int guids_cnt = sizeof(guids) / sizeof(GUID);
|
||||
for (int i = 0; i < guids_cnt; ++i) {
|
||||
@@ -1076,17 +1042,7 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
|
||||
continue;
|
||||
}
|
||||
bool rok = true;
|
||||
#ifdef WINDOWS
|
||||
/*COMMTIMEOUTS times;
|
||||
times.ReadIntervalTimeout = MAXDWORD;
|
||||
times.ReadTotalTimeoutConstant = 0;
|
||||
times.ReadTotalTimeoutMultiplier = 0;
|
||||
times.WriteTotalTimeoutConstant = 1;
|
||||
times.WriteTotalTimeoutMultiplier = 0;
|
||||
SetCommTimeouts(hComm, ×);
|
||||
if (ReadFile(hComm, &void_, 1, &readed_, 0) == 0)
|
||||
rok = GetLastError() == ;*/
|
||||
#else
|
||||
#ifndef WINDOWS
|
||||
int void_ = 0;
|
||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||
if (::read(fd, &void_, 1) == -1)
|
||||
@@ -1122,7 +1078,6 @@ void PISerial::threadedReadBufferSizeChanged() {
|
||||
//piCoutObj << "b" << ss.xmit_fifo_size;
|
||||
ss.xmit_fifo_size = piMaxi(threadedReadBufferSize(), 4096);
|
||||
ioctl(fd, TIOCSSERIAL, &ss);
|
||||
//ioctl(fd, TIOCGSERIAL, &ss);
|
||||
//piCoutObj << "a" << ss.xmit_fifo_size;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief Serial device
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
COM
|
||||
PIP - Platform Independent Primitives
|
||||
COM
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PISERIAL_H
|
||||
@@ -161,8 +161,6 @@ public:
|
||||
|
||||
void setVTime(int t) {vtime = t; applySettings();}
|
||||
|
||||
|
||||
|
||||
//! Returns device name
|
||||
PIString device() const {return path();}
|
||||
|
||||
@@ -174,17 +172,14 @@ public:
|
||||
|
||||
int VTime() const {return vtime;}
|
||||
|
||||
|
||||
//! Discard all buffered input and output data
|
||||
void flush();
|
||||
|
||||
|
||||
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
|
||||
bool read(void * read_to, int max_size, double timeout_ms);
|
||||
PIString read(int size = -1, double timeout_ms = 1000.);
|
||||
PIByteArray readData(int size = -1, double timeout_ms = 1000.);
|
||||
|
||||
|
||||
//! \brief Write to device data "data" with maximum size "size" and wait for data written if "wait" is \b true.
|
||||
//! \returns \b true if sended bytes count = "size"
|
||||
bool send(const void * data, int size);
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
File
|
||||
PIP - Platform Independent Primitives
|
||||
File
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piincludes_p.h"
|
||||
#include "pisharedmemory.h"
|
||||
#include "pipropertystorage.h"
|
||||
@@ -152,7 +153,6 @@ bool PISharedMemory::closeDevice() {
|
||||
//piCoutObj << "close" << PIString(PRIVATE->name) << PRIVATE->data;
|
||||
if (PRIVATE->data) munmap(PRIVATE->data, dsize);
|
||||
if (PRIVATE->owner) {
|
||||
//if (!PRIVATE->name.isEmpty()) {
|
||||
//piCout << "unlink" << PIString(PRIVATE->name);
|
||||
shm_unlink((const char *)PRIVATE->name.data());
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief Shared memory
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIP - Platform Independent Primitives
|
||||
Shared Memory
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PISHAREDMEMORY_H
|
||||
@@ -88,7 +88,6 @@ private:
|
||||
int dsize;
|
||||
PRIVATE_DECLARATION
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
SPI
|
||||
Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pispi.h"
|
||||
#include "pipropertystorage.h"
|
||||
#include "piincludes_p.h"
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*! \file pispi.h
|
||||
* \brief SPI device
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
SPI
|
||||
Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PISPI_H
|
||||
#define PISPI_H
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIP - Platform Independent Primitives
|
||||
PIIODevice that pass write to read
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pitransparentdevice.h"
|
||||
@@ -61,9 +61,6 @@ int PITransparentDevice::writeDevice(const void * data, int max_size) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool PITransparentDevice::openDevice() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* \brief PIIODevice that pass write to read
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIP - Platform Independent Primitives
|
||||
PIIODevice that pass write to read
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PITRANSPARENTDEVICE_H
|
||||
|
||||
@@ -132,7 +132,6 @@ protected:
|
||||
void configureFromFullPathDevice(const PIString & full_path);
|
||||
int readDevice(void * read_to, int max_size);
|
||||
int writeDevice(const void * data, int max_size);
|
||||
//bool init();
|
||||
bool openDevice();
|
||||
bool closeDevice();
|
||||
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
|
||||
|
||||
Reference in New Issue
Block a user