plptools
Loading...
Searching...
No Matches
linkchannel.cc
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5 * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * along with this program; if not, see <https://www.gnu.org/licenses/>.
19 *
20 */
21#include "config.h"
22
23#include <iomanip>
24#include <string>
25#include <cstring>
26
27#include "bufferstore.h"
28#include "bufferarray.h"
29
30#include "linkchannel.h"
31#include "ncp_log.h"
32#include "ncp.h"
33
34using namespace std;
35
36LinkChannel::LinkChannel(NCP* _ncpController, int _ncpChannel)
37: Channel(_ncpController) {
38 registerSer = 0x1234;
39 if (_ncpChannel != -1) {
40 setNcpChannel(_ncpChannel);
41 }
42 ncpConnect();
43}
44
46 int len = a.getLen();
48 lout << "linkchan: << msg ";
50 lout << a << endl;
51 else
52 lout << len << endl;
53 }
54
55 if ((len >= 5) && (a.getByte(0) == 1)) {
56 char srvName[20];
57 unsigned int ser = a.getWord(1);
58 int res = a.getWord(3);
59 // int dontknow = a.getWord(5);
60 BufferArray newStack;
61 BufferStore se;
62
63
64 strncpy(srvName, a.getString(7), 17);
66 lout << "linkchan: received registerAck: ser=0x" << hex << setw(4)
67 << setfill('0') << ser << " res=" << res << " srvName=\""
68 << srvName << "\"" << endl;
69
70 while (!registerStack.empty()) {
71 se = registerStack.pop();
72 if (se.getWord(0) == ser) {
74 lout << "linkchan: found ser=0x" << hex << setw(4) <<
75 setfill('0') << se.getWord(0) <<
76 " on stack -> callBack to waiting chan" << endl;
77 if (strlen(srvName) < 4)
78 strcat(srvName, ".*");
79 ncpDoRegisterAck((int)se.getWord(2), srvName);
80 } else
81 newStack += se;
82 }
83 registerStack = newStack;
84 return;
85 }
86 lerr << "linkchan: unknown message " << a.getByte(0) << endl;
87}
88
90 return "LINK";
91}
92
95 lout << "linkchan: << cack" << endl;
96}
97
100 lout << "linkchan: << ctrm" << endl;
102}
103
106}
107
110 BufferStore stack;
111
112 stack.addWord(registerSer);
113 stack.addWord(ch->getNcpChannel());
114 registerStack += stack;
115 a.addByte(0);
116 a.addWord(registerSer++);
117 a.addString(ch->getNcpRegisterName());
118 a.addByte(0);
119 ncpSend(a);
120}
An array of BufferStores.
Definition: bufferarray.h:30
bool empty() const
Checks if this BufferArray is empty.
Definition: bufferarray.h:164
BufferStore pop(void)
Removes the first BufferStore.
Definition: bufferarray.cc:48
A generic container for an array of bytes.
Definition: bufferstore.h:36
uint16_t getWord(long pos=0) const
Retrieves the word at index pos.
Definition: bufferstore.cc:100
void addWord(int w)
Appends a word to the content of this instance.
Definition: bufferstore.cc:191
void ncpDoRegisterAck(int ch, const char *name)
Definition: channel.cc:68
virtual const char * getNcpRegisterName()=0
void setNcpChannel(int chan)
Definition: channel.cc:96
short int verbose
Definition: channel.h:70
void ncpConnect()
Definition: channel.cc:60
void terminateWhenAsked()
Definition: channel.cc:55
int getNcpChannel(void)
Definition: channel.cc:100
void ncpSend(BufferStore &a)
Definition: channel.cc:44
int registerSer
Definition: linkchannel.h:41
BufferArray registerStack
Definition: linkchannel.h:42
const char * getNcpRegisterName()
Definition: linkchannel.cc:89
void Register(Channel *)
Definition: linkchannel.cc:108
LinkChannel(NCP *ncpController, int ncpChannel=-1)
Definition: linkchannel.cc:36
void ncpConnectAck()
Definition: linkchannel.cc:93
void ncpConnectNak()
Definition: linkchannel.cc:104
void ncpConnectTerminate()
Definition: linkchannel.cc:98
void ncpDataCallback(BufferStore &a)
Definition: linkchannel.cc:45
Definition: ncp.h:55
#define LINKCHAN_DEBUG_DUMP
Definition: linkchannel.h:27
#define LINKCHAN_DEBUG_LOG
Definition: linkchannel.h:26
Definition: doctest.h:522
std::ostream lerr
std::ostream lout
static RFSV * a
Definition: main.cc:55