tcp client 1st working
This commit is contained in:
parent
d21e497864
commit
5b843a23be
|
@ -88,7 +88,7 @@ void GwChannel::begin(
|
||||||
this->toN2k=toN2k;
|
this->toN2k=toN2k;
|
||||||
this->readActisense=readActisense;
|
this->readActisense=readActisense;
|
||||||
this->writeActisense=writeActisense;
|
this->writeActisense=writeActisense;
|
||||||
if (readActisense|| writeActisense){
|
if (impl && (readActisense|| writeActisense)){
|
||||||
channelStream=impl->getStream(false);
|
channelStream=impl->getStream(false);
|
||||||
if (! channelStream) {
|
if (! channelStream) {
|
||||||
this->readActisense=false;
|
this->readActisense=false;
|
||||||
|
|
|
@ -56,6 +56,7 @@ void GwChannelList::begin(bool fallbackSerial){
|
||||||
logger->setWriter(new GwSerialLog(usb));
|
logger->setWriter(new GwSerialLog(usb));
|
||||||
logger->prefix="GWSERIAL:";
|
logger->prefix="GWSERIAL:";
|
||||||
channel=new GwChannel(logger,"USB",USB_CHANNEL_ID);
|
channel=new GwChannel(logger,"USB",USB_CHANNEL_ID);
|
||||||
|
channel->setImpl(usb);
|
||||||
channel->begin(true,
|
channel->begin(true,
|
||||||
config->getBool(config->sendUsb),
|
config->getBool(config->sendUsb),
|
||||||
config->getBool(config->receiveUsb),
|
config->getBool(config->receiveUsb),
|
||||||
|
@ -140,9 +141,19 @@ void GwChannelList::begin(bool fallbackSerial){
|
||||||
}
|
}
|
||||||
|
|
||||||
//tcp client
|
//tcp client
|
||||||
|
bool tclEnabled=config->getBool(config->tclEnabled);
|
||||||
channel=new GwChannel(logger,"TCPClient",TCP_CLIENT_CHANNEL_ID);
|
channel=new GwChannel(logger,"TCPClient",TCP_CLIENT_CHANNEL_ID);
|
||||||
|
if (tclEnabled){
|
||||||
|
client=new GwTcpClient(logger);
|
||||||
|
client->begin(TCP_CLIENT_CHANNEL_ID,
|
||||||
|
config->getString(config->remoteAddress),
|
||||||
|
config->getInt(config->remotePort),
|
||||||
|
config->getBool(config->readTCL)
|
||||||
|
);
|
||||||
|
channel->setImpl(client);
|
||||||
|
}
|
||||||
channel->begin(
|
channel->begin(
|
||||||
config->getBool(config->tclEnabled),
|
tclEnabled,
|
||||||
config->getBool(config->sendTCL),
|
config->getBool(config->sendTCL),
|
||||||
config->getBool(config->readTCL),
|
config->getBool(config->readTCL),
|
||||||
config->getString(config->tclReadFilter),
|
config->getString(config->tclReadFilter),
|
||||||
|
@ -152,15 +163,7 @@ void GwChannelList::begin(bool fallbackSerial){
|
||||||
false,
|
false,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
if (channel->isEnabled()){
|
theChannels.push_back(channel);
|
||||||
client=new GwTcpClient(logger);
|
|
||||||
client->begin(TCP_CLIENT_CHANNEL_ID,
|
|
||||||
config->getString(config->remoteAddress),
|
|
||||||
config->getInt(config->remotePort),
|
|
||||||
channel->shouldRead()
|
|
||||||
);
|
|
||||||
channel->setImpl(client);
|
|
||||||
}
|
|
||||||
LOG_DEBUG(GwLog::LOG,"%s",channel->toString().c_str());
|
LOG_DEBUG(GwLog::LOG,"%s",channel->toString().c_str());
|
||||||
logger->flush();
|
logger->flush();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ bool GwTcpClient::isConnected(){
|
||||||
}
|
}
|
||||||
void GwTcpClient::stop()
|
void GwTcpClient::stop()
|
||||||
{
|
{
|
||||||
if (connection->hasClient())
|
if (connection && connection->hasClient())
|
||||||
{
|
{
|
||||||
LOG_DEBUG(GwLog::DEBUG, "stopping tcp client");
|
LOG_DEBUG(GwLog::DEBUG, "stopping tcp client");
|
||||||
connection->stop();
|
connection->stop();
|
||||||
|
@ -17,7 +17,8 @@ void GwTcpClient::stop()
|
||||||
}
|
}
|
||||||
void GwTcpClient::startConnection()
|
void GwTcpClient::startConnection()
|
||||||
{
|
{
|
||||||
//TODO
|
LOG_DEBUG(GwLog::DEBUG,"TcpClient::startConnection to %s:%d",
|
||||||
|
remoteAddress.c_str(),port);
|
||||||
state = C_INITIALIZED;
|
state = C_INITIALIZED;
|
||||||
error="";
|
error="";
|
||||||
connectStart=millis();
|
connectStart=millis();
|
||||||
|
@ -50,15 +51,19 @@ void GwTcpClient::startConnection()
|
||||||
}
|
}
|
||||||
state=C_CONNECTING;
|
state=C_CONNECTING;
|
||||||
connection->setClient(sockfd);
|
connection->setClient(sockfd);
|
||||||
|
LOG_DEBUG(GwLog::DEBUG,"TcpClient connecting...");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
state=C_CONNECTED;
|
state=C_CONNECTED;
|
||||||
connection->setClient(sockfd);
|
connection->setClient(sockfd);
|
||||||
|
LOG_DEBUG(GwLog::DEBUG,"TcpClient connected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void GwTcpClient::checkConnection()
|
void GwTcpClient::checkConnection()
|
||||||
{
|
{
|
||||||
unsigned long now=millis();
|
unsigned long now=millis();
|
||||||
|
LOG_DEBUG(GwLog::DEBUG+3,"TcpClient::checkConnection state=%d, start=%ul, now=%ul",
|
||||||
|
(int)state,connectStart,now);
|
||||||
if (! connection->hasClient()){
|
if (! connection->hasClient()){
|
||||||
state = hasConfig()?C_INITIALIZED:C_DISABLED;
|
state = hasConfig()?C_INITIALIZED:C_DISABLED;
|
||||||
}
|
}
|
||||||
|
@ -118,6 +123,7 @@ void GwTcpClient::checkConnection()
|
||||||
GwTcpClient::GwTcpClient(GwLog *logger)
|
GwTcpClient::GwTcpClient(GwLog *logger)
|
||||||
{
|
{
|
||||||
this->logger = logger;
|
this->logger = logger;
|
||||||
|
this->connection=NULL;
|
||||||
}
|
}
|
||||||
GwTcpClient::~GwTcpClient(){
|
GwTcpClient::~GwTcpClient(){
|
||||||
if (connection)
|
if (connection)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "GwChannelInterface.h"
|
#include "GwChannelInterface.h"
|
||||||
class GwTcpClient : public GwChannelInterface
|
class GwTcpClient : public GwChannelInterface
|
||||||
{
|
{
|
||||||
static const unsigned long CON_TIMEOUT=10;
|
static const unsigned long CON_TIMEOUT=10000;
|
||||||
GwSocketConnection *connection = NULL;
|
GwSocketConnection *connection = NULL;
|
||||||
String remoteAddress;
|
String remoteAddress;
|
||||||
uint16_t port = 0;
|
uint16_t port = 0;
|
||||||
|
|
|
@ -573,9 +573,9 @@ void setup() {
|
||||||
logger.prefix="FALLBACK:";
|
logger.prefix="FALLBACK:";
|
||||||
#endif
|
#endif
|
||||||
userCodeHandler.startInitTasks(MIN_USER_TASK);
|
userCodeHandler.startInitTasks(MIN_USER_TASK);
|
||||||
channels.begin(fallbackSerial);
|
|
||||||
MDNS.begin(config.getConfigItem(config.systemName)->asCString());
|
|
||||||
gwWifi.setup();
|
gwWifi.setup();
|
||||||
|
MDNS.begin(config.getConfigItem(config.systemName)->asCString());
|
||||||
|
channels.begin(fallbackSerial);
|
||||||
logger.flush();
|
logger.flush();
|
||||||
webserver.registerMainHandler("/api/reset", [](AsyncWebServerRequest *request)->GwRequestMessage *{
|
webserver.registerMainHandler("/api/reset", [](AsyncWebServerRequest *request)->GwRequestMessage *{
|
||||||
return new ResetRequest(request->arg("_hash"));
|
return new ResetRequest(request->arg("_hash"));
|
||||||
|
|
Loading…
Reference in New Issue