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