aboutsummaryrefslogtreecommitdiffstats
path: root/ncpd
diff options
context:
space:
mode:
authorFritz Elfert <felfert@to.com>1999-07-01 20:44:20 +0000
committerFritz Elfert <felfert@to.com>1999-07-01 20:44:20 +0000
commit80e566ea830ec9e6534f1a140af0bbc6b1765aa7 (patch)
tree86788a4b96d0b9ba70f787e4cd31777c4eb457bc /ncpd
parent8c29602b21efacced9d7ff4cd1f3c4101dda5f65 (diff)
downloadplptools-80e566ea830ec9e6534f1a140af0bbc6b1765aa7.tar.gz
plptools-80e566ea830ec9e6534f1a140af0bbc6b1765aa7.tar.bz2
plptools-80e566ea830ec9e6534f1a140af0bbc6b1765aa7.zip
modified logging for finer control.
proper reconnect on link failure.
Diffstat (limited to 'ncpd')
-rw-r--r--ncpd/channel.cc62
-rw-r--r--ncpd/channel.h46
-rw-r--r--ncpd/link.cc154
-rw-r--r--ncpd/link.h48
-rw-r--r--ncpd/linkchan.cc14
-rw-r--r--ncpd/linkchan.h15
-rw-r--r--ncpd/main.cc46
-rw-r--r--ncpd/ncp.cc125
-rw-r--r--ncpd/ncp.h11
-rw-r--r--ncpd/packet.cc51
-rw-r--r--ncpd/packet.h7
-rw-r--r--ncpd/socketchan.cc123
12 files changed, 466 insertions, 236 deletions
diff --git a/ncpd/channel.cc b/ncpd/channel.cc
index 6cc3ff3..7374191 100644
--- a/ncpd/channel.cc
+++ b/ncpd/channel.cc
@@ -26,35 +26,63 @@
#include "channel.h"
#include "ncp.h"
-channel::channel(ncp *_ncpController) {
- ncpController = _ncpController;
- _terminate = false;
+channel::channel(ncp * _ncpController)
+{
+ verbose = 0;
+ ncpController = _ncpController;
+ _terminate = false;
}
-void channel::ncpSend(bufferStore &a) {
- ncpController->send(ncpChannel, a);
+void channel::
+ncpSend(bufferStore & a)
+{
+ ncpController->send(ncpChannel, a);
}
-bool channel::terminate() {
- return _terminate;
+bool channel::
+terminate()
+{
+ return _terminate;
}
-void channel::terminateWhenAsked() {
- _terminate = true;
+void channel::
+terminateWhenAsked()
+{
+ _terminate = true;
}
-void channel::ncpConnect() {
- ncpController->connect(this);
+void channel::
+ncpConnect()
+{
+ ncpController->connect(this);
}
-void channel::ncpDisconnect() {
- ncpController->disconnect(ncpChannel);
+void channel::
+ncpDisconnect()
+{
+ ncpController->disconnect(ncpChannel);
}
-void channel::setNcpChannel(int chan) {
- ncpChannel = chan;
+void channel::
+setNcpChannel(int chan)
+{
+ ncpChannel = chan;
}
-void channel::newNcpController(ncp *_ncpController) {
- ncpController = _ncpController;
+void channel::
+newNcpController(ncp * _ncpController)
+{
+ ncpController = _ncpController;
+}
+
+void channel::
+setVerbose(short int _verbose)
+{
+ verbose = _verbose;
+}
+
+short int channel::
+getVerbose()
+{
+ return verbose;
}
diff --git a/ncpd/channel.h b/ncpd/channel.h
index b71e248..4442088 100644
--- a/ncpd/channel.h
+++ b/ncpd/channel.h
@@ -9,26 +9,32 @@ class ncp;
class bufferStore;
class channel {
-public:
- channel(ncp *ncpController);
- void newNcpController(ncp *ncpController);
-
- void setNcpChannel(int chan);
- void ncpSend(bufferStore &a);
- virtual void ncpDataCallback(bufferStore &a) = NULL;
- virtual const char *getNcpConnectName() = NULL;
- void ncpConnect();
- virtual void ncpConnectAck() = NULL;
- virtual void ncpConnectTerminate() = NULL;
- void ncpDisconnect();
-
- // The following two calls are used for destructing an instance
- virtual bool terminate(); // Mainloop will terminate this class if true
- void terminateWhenAsked();
-private:
- ncp *ncpController;
- bool _terminate;
- int ncpChannel;
+ public:
+ channel(ncp *ncpController);
+ void newNcpController(ncp *ncpController);
+
+ void setNcpChannel(int chan);
+ void ncpSend(bufferStore &a);
+ void setVerbose(short int _verbose);
+ short int getVerbose();
+ virtual void ncpDataCallback(bufferStore &a) = NULL;
+ virtual const char *getNcpConnectName() = NULL;
+ void ncpConnect();
+ virtual void ncpConnectAck() = NULL;
+ virtual void ncpConnectTerminate() = NULL;
+ void ncpDisconnect();
+
+ // The following two calls are used for destructing an instance
+ virtual bool terminate(); // Mainloop will terminate this class if true
+ void terminateWhenAsked();
+
+ protected:
+ short int verbose;
+
+ private:
+ ncp *ncpController;
+ bool _terminate;
+ int ncpChannel;
};
#endif
diff --git a/ncpd/link.cc b/ncpd/link.cc
index f3a13df..cc3781d 100644
--- a/ncpd/link.cc
+++ b/ncpd/link.cc
@@ -30,10 +30,9 @@
#include "bufferstore.h"
#include "bufferarray.h"
-link::link(const char *fname, int baud, IOWatch & iow, bool _s5, bool _verbose):
-s5(_s5)
+link::link(const char *fname, int baud, IOWatch & iow, unsigned short _verbose)
{
- p = new packet(fname, baud, iow, PACKET_LAYER_DIAGNOSTICS);
+ p = new packet(fname, baud, iow);
verbose = _verbose;
idSent = 0;
idLastGot = -1;
@@ -49,6 +48,40 @@ link::~link()
}
void link::
+reset() {
+ idSent = 0;
+ idLastGot = -1;
+ newLink = true;
+ somethingToSend = false;
+ timesSent = 0;
+ failed = false;
+}
+
+short int link::
+getVerbose()
+{
+ return verbose;
+}
+
+void link::
+setVerbose(short int _verbose)
+{
+ verbose = _verbose;
+}
+
+short int link::
+getPktVerbose()
+{
+ return p->getVerbose();
+}
+
+void link::
+setPktVerbose(short int _verbose)
+{
+ p->setVerbose(_verbose);
+}
+
+void link::
send(const bufferStore & buff)
{
if (buff.getLen() > 300)
@@ -65,49 +98,65 @@ poll()
unsigned char type;
while (p->get(type, buff)) {
- if ((type & 0xf0) == 0x30) {
- // Data
- int ser = type & 0x0f;
- if (verbose)
- cout << "link: Got data ser " << ser << " : " << buff << endl;
- // Send ack
- if (idLastGot != ser) {
- idLastGot = ser;
- ret.pushBuffer(buff);
- } else {
- if (verbose)
- cout << "link: Duplicated data - not passing back, repeating ack\n";
- }
- if (verbose)
- cout << "link: Send ack ser " << ser << endl;
- bufferStore blank;
- p->send(ser, blank);
- break;
- } else if ((type & 0xf0) == 0x00) {
- // Ack
- int ser = type & 0x0f;
- if (ser == idSent) {
- if (verbose)
- cout << "link: Got ack " << ser << " : " << buff << endl;
+ int seq = type & 0x0f;
+ bufferStore blank;
+ type &= 0xf0;
+ switch (type) {
+ case 0x30:
+ if (verbose & LNK_DEBUG_LOG) {
+ cout << "link: << dat seq=" << seq ;
+ if (verbose & LNK_DEBUG_DUMP)
+ cout << " " << buff << endl;
+ else
+ cout << " len=" << buff.getLen() << endl;
+ }
+ // Send ack
+ if (idLastGot != seq) {
+ idLastGot = seq;
+ ret.pushBuffer(buff);
+ } else {
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: DUP\n";
+ }
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: >> ack seq=" << seq << endl;
+ blank.init();
+ p->send(seq, blank);
+ break;
+ case 0x00:
+ // Ack
+ if (seq == idSent) {
+ if (verbose & LNK_DEBUG_LOG) {
+ cout << "link: << ack seq=" << seq ;
+ if (verbose & LNK_DEBUG_DUMP)
+ cout << " " << buff;
+ cout << endl;
+ }
+ somethingToSend = false;
+ timesSent = 0;
+ }
+ break;
+ case 0x20:
+ // New link
+ if (verbose & LNK_DEBUG_LOG) {
+ cout << "link: << lrq seq=" << seq;
+ if (verbose & LNK_DEBUG_DUMP)
+ cout << " " << buff;
+ cout << endl;
+ }
+ idLastGot = 0;
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: >> lack seq=" << seq << endl;
somethingToSend = false;
- timesSent = 0;
- }
- } else if ((type & 0xf0) == 0x20) {
- // New link
- int ser = type & 0x0f;
- if (verbose)
- cout << "link: got New link request " << ser << " : " << buff << endl;
- idLastGot = 0;
- bufferStore blank;
- if (verbose)
- cout << "link: Sending ack of new link\n";
- somethingToSend = false;
- p->send(idLastGot, blank);
- } else if ((type & 0xf0) == 0x10) {
- // Disconnect
- cerr << "Disconnect?\n";
- failed = true;
- return ret;
+ blank.init();
+ p->send(idLastGot, blank);
+ break;
+ case 0x10:
+ // Disconnect
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: << DISC" << endl;
+ failed = true;
+ return ret;
}
}
@@ -136,19 +185,22 @@ poll()
} else {
if (toSend.empty()) {
// Request for new link
- if (verbose)
- cout << "link: Send req new session ser " << idSent << endl;
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: >> lrq seq=" << idSent << endl;
p->send(0x20 + idSent, toSend);
} else {
- if (verbose)
- cout << "link: Send data packet ser " << idSent << " : " << toSend << endl;
+ if (verbose & LNK_DEBUG_LOG) {
+ cout << "link: >> data seq=" << idSent;
+ if (verbose & LNK_DEBUG_DUMP)
+ cout << " " << toSend;
+ cout << endl;
+ }
p->send(0x30 + idSent, toSend);
}
countToResend = 5;
}
- } else {
+ } else
countToResend--;
- }
}
return ret;
}
diff --git a/ncpd/link.h b/ncpd/link.h
index f166513..596f6f1 100644
--- a/ncpd/link.h
+++ b/ncpd/link.h
@@ -4,31 +4,39 @@
#include "bool.h"
#include "bufferstore.h"
#include "bufferarray.h"
+
+#define LNK_DEBUG_LOG 1
+#define LNK_DEBUG_DUMP 2
+
class packet;
class IOWatch;
class link {
-public:
- link(const char *fname, int baud, IOWatch &iow, bool s5, bool _verbose = false);
- ~link();
- void send(const bufferStore &buff);
- bufferArray poll();
- bool stuffToSend();
- bool hasFailed();
+ public:
+ link(const char *fname, int baud, IOWatch &iow, unsigned short _verbose = 0);
+ ~link();
+ void send(const bufferStore &buff);
+ bufferArray poll();
+ bool stuffToSend();
+ bool hasFailed();
+ void reset();
+ void setVerbose(short int);
+ short int getVerbose();
+ void setPktVerbose(short int);
+ short int getPktVerbose();
-private:
- packet *p;
- int idSent;
- int countToResend;
- int timesSent;
- bufferArray sendQueue;
- bufferStore toSend;
- int idLastGot;
- bool newLink;
- bool verbose;
- bool somethingToSend;
- bool failed;
- bool s5;
+ private:
+ packet *p;
+ int idSent;
+ int countToResend;
+ int timesSent;
+ bufferArray sendQueue;
+ bufferStore toSend;
+ int idLastGot;
+ bool newLink;
+ unsigned short verbose;
+ bool somethingToSend;
+ bool failed;
};
#endif
diff --git a/ncpd/linkchan.cc b/ncpd/linkchan.cc
index e5d7c13..2f9a066 100644
--- a/ncpd/linkchan.cc
+++ b/ncpd/linkchan.cc
@@ -31,7 +31,13 @@ linkChan::linkChan(ncp * _ncpController):channel(_ncpController)
void linkChan::
ncpDataCallback(bufferStore & a)
{
- cout << "linkchan: got message " << a << endl;
+ if (verbose & LINKCHAN_DEBUG_LOG) {
+ cout << "linkchan: << msg ";
+ if (verbose & LINKCHAN_DEBUG_DUMP)
+ cout << a << endl;
+ else
+ cout << a.getLen() << endl;
+ }
}
const char *linkChan::
@@ -43,12 +49,14 @@ getNcpConnectName()
void linkChan::
ncpConnectAck()
{
- cout << "linkchan: got connect ack\n";
+ if (verbose & LINKCHAN_DEBUG_LOG)
+ cout << "linkchan: << cack" << endl;
}
void linkChan::
ncpConnectTerminate()
{
- cout << "linkchan: got connect terminate\n";
+ if (verbose & LINKCHAN_DEBUG_LOG)
+ cout << "linkchan: << ctrm" << endl;
terminateWhenAsked();
}
diff --git a/ncpd/linkchan.h b/ncpd/linkchan.h
index e90dee2..db36f27 100644
--- a/ncpd/linkchan.h
+++ b/ncpd/linkchan.h
@@ -3,14 +3,17 @@
#include "channel.h"
+#define LINKCHAN_DEBUG_LOG 1
+#define LINKCHAN_DEBUG_DUMP 2
+
class linkChan : public channel {
-public:
- linkChan(ncp *ncpController);
+ public:
+ linkChan(ncp *ncpController);
- void ncpDataCallback(bufferStore &a);
- const char *getNcpConnectName();
- void ncpConnectAck();
- void ncpConnectTerminate();
+ void ncpDataCallback(bufferStore &a);
+ const char *getNcpConnectName();
+ void ncpConnectAck();
+ void ncpConnectTerminate();
};
#endif
diff --git a/ncpd/main.cc b/ncpd/main.cc
index dd32729..fca9efc 100644
--- a/ncpd/main.cc
+++ b/ncpd/main.cc
@@ -31,6 +31,8 @@
#include "socketchan.h"
#include "iowatch.h"
#include "linkchan.h"
+#include "link.h"
+#include "packet.h"
void
checkForNewSocketConnection(ppsocket & skt, int &numScp, socketChan ** scp, ncp * a, IOWatch & iow)
@@ -44,6 +46,8 @@ checkForNewSocketConnection(ppsocket & skt, int &numScp, socketChan ** scp, ncp
bufferStore a;
a.addStringT("No psion ncp channel free");
next->sendBufferStore(a);
+ sleep(1);
+ next->closeSocket();
} else
scp[numScp++] = new socketChan(next, a, iow);
}
@@ -90,8 +94,8 @@ resetSocketConnections(int &numScp, socketChan ** scp, ncp * a)
void
usage()
{
- cout << "Version : " << VERSION << endl;
- cout << "Usage : ncp [-s <socket number>] [-d <device>] [-b <baud rate>]\n";
+ cerr << "Usage : ncpd [-s <socket number>] [-d <device>] [-b <baud rate>]\n";
+ exit(1);
}
int
@@ -105,23 +109,40 @@ main(int argc, char **argv)
int sockNum = DPORT;
int baudRate = DSPEED;
const char *serialDevice = DDEV;
+ short int nverbose = 0;
+ short int pverbose = 0;
+ short int lverbose = 0;
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-s") && i + 1 < argc) {
sockNum = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-d") && i + 1 < argc) {
serialDevice = argv[++i];
+ } else if (!strcmp(argv[i], "-v") && i + 1 < argc) {
+ i++;
+ if (!strcmp(argv[i], "nl"))
+ nverbose |= NCP_DEBUG_LOG;
+ if (!strcmp(argv[i], "nd"))
+ nverbose |= NCP_DEBUG_DUMP;
+ if (!strcmp(argv[i], "ll"))
+ lverbose |= LNK_DEBUG_LOG;
+ if (!strcmp(argv[i], "ld"))
+ lverbose |= LNK_DEBUG_DUMP;
+ if (!strcmp(argv[i], "pl"))
+ pverbose |= PKT_DEBUG_LOG;
+ if (!strcmp(argv[i], "pd"))
+ pverbose |= PKT_DEBUG_DUMP;
} else if (!strcmp(argv[i], "-b") && i + 1 < argc) {
baudRate = atoi(argv[++i]);
- } else {
+ } else if (!strcmp(argv[i], "-V")) {
+ cout << "plpnfsd version " << VERSION << endl;
+ exit(0);
+ } else
usage();
- exit(1);
- }
}
if (!skt.listen("127.0.0.1", sockNum)) {
cerr << "Could not initiate listen on socket " << sockNum << endl;
- cerr << "NCP is now started by rfsv - you don't have to do it explicitly yourself" << endl;
} else {
ncp *a = NULL;
int numScp;
@@ -130,12 +151,15 @@ main(int argc, char **argv)
while (true) {
if (a == NULL) {
a = new ncp(serialDevice, baudRate, iow);
+ a->setVerbose(nverbose);
+ a->setLinkVerbose(lverbose);
+ a->setPktVerbose(pverbose);
numScp = 0;
iow.addIO(skt.socket());
}
// sockets
- checkForNewSocketConnection(skt, numScp, scp, a, iow);
pollSocketConnections(numScp, scp);
+ checkForNewSocketConnection(skt, numScp, scp, a, iow);
// psion
a->poll();
@@ -144,11 +168,13 @@ main(int argc, char **argv)
iow.watch(0, 100000);
else
iow.watch(100000, 0);
+
if (a->hasFailed()) {
cout << "ncp: restarting\n";
- resetSocketConnections(numScp, scp, a);
- delete a;
- a = NULL;
+ // resetSocketConnections(numScp, scp, a);
+ // delete a;
+ // a = NULL;
+ a->reset();
}
}
delete a;
diff --git a/ncpd/ncp.cc b/ncpd/ncp.cc
index d859ea9..2391586 100644
--- a/ncpd/ncp.cc
+++ b/ncpd/ncp.cc
@@ -35,9 +35,9 @@
ncp::ncp(const char *fname, int baud, IOWatch & iow)
{
- l = new link(fname, baud, iow, LINK_LAYER_DIAGNOSTICS);
- gotLinkChan = false;
+ l = new link(fname, baud, iow);
failed = false;
+ verbose = 0;
// init channels
for (int i = 0; i < 8; i++)
@@ -50,6 +50,51 @@ ncp::~ncp()
}
void ncp::
+reset() {
+ for (int i = 0; i < 8; i++)
+ channelPtr[i] = NULL;
+ failed = false;
+ gotLinkChan = false;
+ l->reset();
+}
+
+short int ncp::
+getVerbose()
+{
+ return verbose;
+}
+
+void ncp::
+setVerbose(short int _verbose)
+{
+ verbose = _verbose;
+}
+
+short int ncp::
+getLinkVerbose()
+{
+ return l->getVerbose();
+}
+
+void ncp::
+setLinkVerbose(short int _verbose)
+{
+ l->setVerbose(_verbose);
+}
+
+short int ncp::
+getPktVerbose()
+{
+ return l->getPktVerbose();
+}
+
+void ncp::
+setPktVerbose(short int _verbose)
+{
+ l->setPktVerbose(_verbose);
+}
+
+void ncp::
poll()
{
bufferArray res(l->poll());
@@ -66,7 +111,7 @@ poll()
int allData = s.getByte(1);
s.discardFirstBytes(2);
if (channelPtr[channel] == NULL) {
- cerr << "Got message for unknown channel\n";
+ cerr << "ncp: Got message for unknown channel\n";
} else {
messageList[channel].addBuff(s);
if (allData == LAST_MESS) {
@@ -93,7 +138,8 @@ controlChannel(int chan, enum interControllerMessageType t, bufferStore & comman
open.addByte(chan);
open.addByte(t);
open.addBuff(command);
- cout << "put " << ctrlMsgName(t) << endl;
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: >> " << ctrlMsgName(t) << " " << chan << endl;
l->send(open);
}
@@ -103,16 +149,16 @@ decodeControlMessage(bufferStore & buff)
int remoteChan = buff.getByte(0);
interControllerMessageType imt = (interControllerMessageType) buff.getByte(1);
buff.discardFirstBytes(2);
- cout << "got " << ctrlMsgName(imt) << " " << remoteChan << " ";
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: << " << ctrlMsgName(imt) << " " << remoteChan;
switch (imt) {
- case NCON_MSG_DATA_XOFF:
- cout << remoteChan << " " << buff << endl;
- break;
- case NCON_MSG_DATA_XON:
- cout << buff << endl;
- break;
- case NCON_MSG_CONNECT_TO_SERVER:{
- cout << buff << endl;
+ case NCON_MSG_CONNECT_TO_SERVER:
+ {
+ if (verbose & NCP_DEBUG_LOG) {
+ if (verbose & NCP_DEBUG_DUMP)
+ cout << " " << buff;
+ cout << endl;
+ }
int localChan;
bufferStore b;
@@ -125,61 +171,72 @@ decodeControlMessage(bufferStore & buff)
if (!strcmp(buff.getString(0), "LINK.*")) {
if (gotLinkChan)
failed = true;
- cout << "Accepted link channel" << endl;
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: Link UP" << endl;
channelPtr[localChan] = new linkChan(this);
channelPtr[localChan]->setNcpChannel(localChan);
channelPtr[localChan]->ncpConnectAck();
gotLinkChan = true;
} else {
- cout << "Disconnecting channel" << endl;
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: Link DOWN" << endl;
bufferStore b;
b.addByte(remoteChan);
controlChannel(localChan, NCON_MSG_CHANNEL_DISCONNECT, b);
}
}
break;
- case NCON_MSG_CONNECT_RESPONSE:{
+ case NCON_MSG_CONNECT_RESPONSE:
+ {
int forChan = buff.getByte(0);
- cout << "for channel " << forChan << " status ";
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ch=" << forChan << " stat=";
if (buff.getByte(1) == 0) {
- cout << "OK" << endl;
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "OK" << endl;
if (channelPtr[forChan]) {
remoteChanList[forChan] = remoteChan;
channelPtr[forChan]->ncpConnectAck();
} else {
- cerr << "Got message for unknown channel\n";
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: message for unknown channel\n";
}
} else {
- cout << "Unknown status " << (int) buff.getByte(1) << endl;
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "Unknown " << (int) buff.getByte(1) << endl;
channelPtr[forChan]->ncpConnectTerminate();
}
}
break;
- case NCON_MSG_CHANNEL_CLOSED:
- cout << buff << endl;
- break;
case NCON_MSG_NCP_INFO:
if (buff.getByte(0) == 6) {
- cout << buff << endl;
- {
- // Send time info
- bufferStore b;
- b.addByte(6);
- b.addDWord(0);
- controlChannel(0, NCON_MSG_NCP_INFO, b);
+ bufferStore b;
+ if (verbose & NCP_DEBUG_LOG) {
+ if (verbose & NCP_DEBUG_DUMP)
+ cout << " " << buff;
+ cout << endl;
}
+ b.addByte(6);
+ b.addDWord(0);
+ controlChannel(0, NCON_MSG_NCP_INFO, b);
} else
cout << "ALERT!!!! Protocol-Version is NOT 6!! (No Series 5?)!" << endl;
break;
case NCON_MSG_CHANNEL_DISCONNECT:
- cout << "channel " << (int) buff.getByte(0) << endl;
+ if (verbose & NCP_DEBUG_LOG)
+ cout << " ch=" << (int) buff.getByte(0) << endl;
disconnect(buff.getByte(0));
break;
+ case NCON_MSG_DATA_XOFF:
+ case NCON_MSG_DATA_XON:
+ case NCON_MSG_CHANNEL_CLOSED:
case NCON_MSG_NCP_END:
- cout << buff << endl;
- break;
default:
- cout << endl;
+ if (verbose & NCP_DEBUG_LOG) {
+ if (verbose & NCP_DEBUG_DUMP)
+ cout << " " << buff;
+ cout << endl;
+ }
}
}
diff --git a/ncpd/ncp.h b/ncpd/ncp.h
index 9e8444c..0f0525d 100644
--- a/ncpd/ncp.h
+++ b/ncpd/ncp.h
@@ -7,6 +7,9 @@ class link;
class channel;
class IOWatch;
+#define NCP_DEBUG_LOG 1
+#define NCP_DEBUG_DUMP 2
+
class ncp {
public:
ncp(const char *fname, int baud, IOWatch &iow);
@@ -16,9 +19,16 @@ class ncp {
void disconnect(int channel);
void send(int channel, bufferStore &a);
void poll();
+ void reset();
bool stuffToSend();
bool hasFailed();
bool gotLinkChannel();
+ void setVerbose(short int);
+ short int getVerbose();
+ void setLinkVerbose(short int);
+ short int getLinkVerbose();
+ void setPktVerbose(short int);
+ short int getPktVerbose();
private:
enum c { MAX_LEN = 200, LAST_MESS = 1, NOT_LAST_MESS = 2 };
@@ -39,6 +49,7 @@ class ncp {
char * ctrlMsgName(unsigned char);
link *l;
+ unsigned short verbose;
channel *channelPtr[8];
bufferStore messageList[8];
int remoteChanList[8];
diff --git a/ncpd/packet.cc b/ncpd/packet.cc
index 62f6b09..70006bc 100644
--- a/ncpd/packet.cc
+++ b/ncpd/packet.cc
@@ -40,7 +40,7 @@ extern "C" {
#define BUFFERLEN 2000
-packet::packet(const char *fname, int _baud, IOWatch & _iow, bool _verbose):
+packet::packet(const char *fname, int _baud, IOWatch & _iow, short int _verbose = 0):
iow(_iow)
{
verbose = _verbose;
@@ -56,12 +56,23 @@ iow(_iow)
iow.addIO(fd);
}
+short int packet::
+getVerbose()
+{
+ return verbose;
+}
+
+void packet::
+setVerbose(short int _verbose)
+{
+ verbose = _verbose;
+}
+
packet::~packet()
{
iow.remIO(fd);
ser_exit(fd);
usleep(100000);
-
delete[]inBuffer;
delete[]outBuffer;
free(devname);
@@ -70,8 +81,13 @@ packet::~packet()
void packet::
send(unsigned char type, const bufferStore & b)
{
- if (verbose)
- cout << "packet: send ";
+ if (verbose & PKT_DEBUG_LOG) {
+ cout << "packet: >> ";
+ if (verbose & PKT_DEBUG_DUMP)
+ cout << b << endl;
+ else
+ cout << "len=" << b.getLen() << endl;
+ }
opByte(0x16);
opByte(0x10);
opByte(0x02);
@@ -94,8 +110,6 @@ send(unsigned char type, const bufferStore & b)
opByte(crcOut >> 8);
opByte(crcOut & 0xff);
- if (verbose)
- cout << endl;
realWrite();
}
@@ -117,8 +131,6 @@ opByte(unsigned char a)
{
*outPtr++ = a;
outLen++;
- if (verbose)
- cout << hex << setw(2) << setfill('0') << (int) a << " ";
if (outLen >= BUFFERLEN)
realWrite();
}
@@ -129,8 +141,8 @@ realWrite()
outPtr = outBuffer;
while (outLen > 0) {
int r = write(fd, outPtr, outLen);
- if (verbose)
- cout << "realW:" << dec << r << endl;
+ if (verbose & PKT_DEBUG_LOG)
+ cout << "packet: WR=" << dec << r << endl;
if (r > 0) {
outLen -= r;
outPtr += r;
@@ -145,7 +157,7 @@ get(unsigned char &type, bufferStore & ret)
while (!terminated()) {
int res = read(fd, inPtr, BUFFERLEN - inLen);
if (res > 0) {
- if (verbose)
+ if (verbose & PKT_DEBUG_LOG)
cout << "packet: rcv " << dec << res << endl;
inPtr += res;
inLen += res;
@@ -153,16 +165,19 @@ get(unsigned char &type, bufferStore & ret)
if (res < 0)
return false;
if (inLen >= BUFFERLEN) {
- cerr << "input Overflow!!!!" << endl;
+ cerr << "packet: input buffer overflow!!!!" << endl;
inLen = 0;
inPtr = inBuffer;
return false;
}
}
- if (verbose) {
+ if (verbose & PKT_DEBUG_LOG) {
cout << "packet: get ";
- for (int i = 0; i < termLen; i++)
- cout << hex << setw(2) << setfill('0') << (int) inBuffer[i] << " ";
+ if (verbose & PKT_DEBUG_DUMP) {
+ for (int i = 0; i < termLen; i++)
+ cout << hex << setw(2) << setfill('0') << (int) inBuffer[i] << " ";
+ } else
+ cout << "len=" << dec << termLen;
cout << endl;
}
inLen -= termLen;
@@ -176,8 +191,10 @@ get(unsigned char &type, bufferStore & ret)
ret = rcv;
ret.discardFirstBytes(1);
return true;
- } else
- cout << "packet::Warning - bad crc packet " << endl;
+ } else {
+ if (verbose & PKT_DEBUG_LOG)
+ cout << "packet: BAD CRC" << endl;
+ }
return false;
}
diff --git a/ncpd/packet.h b/ncpd/packet.h
index cd02513..85a0a77 100644
--- a/ncpd/packet.h
+++ b/ncpd/packet.h
@@ -8,12 +8,17 @@ class psiEmul;
class bufferStore;
class IOWatch;
+#define PKT_DEBUG_LOG 1
+#define PKT_DEBUG_DUMP 2
+
class packet {
public:
- packet(const char *fname, int baud, IOWatch &iow, bool verbose = false);
+ packet(const char *fname, int baud, IOWatch &iow, short int verbose = 0);
~packet();
void send(unsigned char type, const bufferStore &b);
bool get(unsigned char &type, bufferStore &b);
+ void setVerbose(short int);
+ short int getVerbose();
private:
bool terminated();
diff --git a/ncpd/socketchan.cc b/ncpd/socketchan.cc
index 0afabf2..72ee298 100644
--- a/ncpd/socketchan.cc
+++ b/ncpd/socketchan.cc
@@ -30,76 +30,85 @@
#include "ppsocket.h"
#include "iowatch.h"
-socketChan::socketChan(ppsocket *_skt, ncp *_ncpController, IOWatch &_iow) :
- channel(_ncpController),
- iow(_iow)
+socketChan:: socketChan(ppsocket * _skt, ncp * _ncpController, IOWatch & _iow):
+channel(_ncpController),
+iow(_iow)
{
- skt = _skt;
- connectName = 0;
- iow.addIO(skt->socket());
- connected = false;
+ skt = _skt;
+ connectName = 0;
+ iow.addIO(skt->socket());
+ connected = false;
}
-socketChan::~socketChan() {
- iow.remIO(skt->socket());
- skt->closeSocket();
- delete skt;
- if (connectName) free(connectName);
+socketChan::~socketChan()
+{
+ iow.remIO(skt->socket());
+ skt->closeSocket();
+ delete skt;
+ if (connectName)
+ free(connectName);
}
-void socketChan::ncpDataCallback(bufferStore &a) {
- if (connectName != 0) {
- skt->sendBufferStore(a);
- }
- else {
- cerr << "This should not happen\n";
- }
+void socketChan::
+ncpDataCallback(bufferStore & a)
+{
+ if (connectName != 0) {
+ skt->sendBufferStore(a);
+ } else
+ cerr << "socketchan: Connect without name!!!\n";
}
-const char *socketChan::getNcpConnectName() {
- return connectName;
+const char *socketChan::
+getNcpConnectName()
+{
+ return connectName;
}
-void socketChan::ncpConnectAck() {
- bufferStore a;
- a.addStringT("Ok");
- skt->sendBufferStore(a);
- connected = true;
+void socketChan::
+ncpConnectAck()
+{
+ bufferStore a;
+ a.addStringT("Ok");
+ skt->sendBufferStore(a);
+ connected = true;
}
-void socketChan::ncpConnectTerminate() {
- bufferStore a;
- a.addStringT("Close");
- skt->sendBufferStore(a);
- terminateWhenAsked();
+void socketChan::
+ncpConnectTerminate()
+{
+ bufferStore a;
+ a.addStringT("Close");
+ skt->sendBufferStore(a);
+ terminateWhenAsked();
}
-void socketChan::socketPoll() {
- if (connectName == 0) {
- bufferStore a;
- if (skt->getBufferStore(a, false) == 1) {
- connectName = strdup(a.getString());
- ncpConnect();
- }
- }
- else if (connected) {
- bufferStore a;
- int res = skt->getBufferStore(a, false);
- if ( res == -1 ) {
- ncpDisconnect();
- }
- else if (res == 1) {
- if (a.getLen() > 5 &&
- !strncmp(a.getString(), "Close", 5)) {
- ncpDisconnect();
- }
- else {
- ncpSend(a);
- }
- }
- }
+void socketChan::
+socketPoll()
+{
+ if (connectName == 0) {
+ bufferStore a;
+ if (skt->getBufferStore(a, false) == 1) {
+ connectName = strdup(a.getString());
+ ncpConnect();
+ }
+ } else if (connected) {
+ bufferStore a;
+ int res = skt->getBufferStore(a, false);
+ if (res == -1) {
+ ncpDisconnect();
+ } else if (res == 1) {
+ if (a.getLen() > 5 &&
+ !strncmp(a.getString(), "Close", 5)) {
+ ncpDisconnect();
+ } else {
+ ncpSend(a);
+ }
+ }
+ }
}
-bool socketChan::isConnected() const {
- return connected;
+bool socketChan::
+isConnected()
+const {
+ return connected;
}