plptools
Loading...
Searching...
No Matches
linkchan.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 "linkchan.h"
31#include "ncp_log.h"
32#include "ncp.h"
33
34using namespace std;
35
36linkChan::linkChan(NCP* _ncpController, int _ncpChannel):channel(_ncpController)
37{
38 registerSer = 0x1234;
39 if (_ncpChannel != -1)
40 setNcpChannel(_ncpChannel);
41 ncpConnect();
42}
43
46{
47 int len = a.getLen();
49 lout << "linkchan: << msg ";
51 lout << a << endl;
52 else
53 lout << len << endl;
54 }
55
56 if ((len >= 5) && (a.getByte(0) == 1)) {
57 char srvName[20];
58 unsigned int ser = a.getWord(1);
59 int res = a.getWord(3);
60 // int dontknow = a.getWord(5);
61 bufferArray newStack;
62 bufferStore se;
63
64
65 strncpy(srvName, a.getString(7), 17);
67 lout << "linkchan: received registerAck: ser=0x" << hex << setw(4)
68 << setfill('0') << ser << " res=" << res << " srvName=\""
69 << srvName << "\"" << endl;
70
71 while (!registerStack.empty()) {
72 se = registerStack.pop();
73 if (se.getWord(0) == ser) {
75 lout << "linkchan: found ser=0x" << hex << setw(4) <<
76 setfill('0') << se.getWord(0) <<
77 " on stack -> callBack to waiting chan" << endl;
78 if (strlen(srvName) < 4)
79 strcat(srvName, ".*");
80 ncpDoRegisterAck((int)se.getWord(2), srvName);
81 } else
82 newStack += se;
83 }
84 registerStack = newStack;
85 return;
86 }
87 lerr << "linkchan: unknown message " << a.getByte(0) << endl;
88}
89
90const char *linkChan::
92{
93 return "LINK";
94}
95
98{
100 lout << "linkchan: << cack" << endl;
101}
102
105{
107 lout << "linkchan: << ctrm" << endl;
109}
110
113{
115}
116
118Register(channel *ch)
119{
121 bufferStore stack;
122
123 stack.addWord(registerSer);
124 stack.addWord(ch->getNcpChannel());
125 registerStack += stack;
126 a.addByte(0);
127 a.addWord(registerSer++);
128 a.addString(ch->getNcpRegisterName());
129 a.addByte(0);
130 ncpSend(a);
131}
Definition: ncp.h:54
An array of bufferStores.
Definition: bufferarray.h:31
bufferStore pop(void)
Removes the first bufferStore.
Definition: bufferarray.cc:48
bool empty() const
Checks if this bufferArray is empty.
Definition: bufferarray.h:165
A generic container for an array of bytes.
Definition: bufferstore.h:37
uint16_t getWord(long pos=0) const
Retrieves the word at index pos.
Definition: bufferstore.cc:102
void addWord(int w)
Appends a word to the content of this instance.
Definition: bufferstore.cc:193
void ncpSend(bufferStore &a)
Definition: channel.cc:46
virtual const char * getNcpRegisterName()=0
void ncpDoRegisterAck(int ch, const char *name)
Definition: channel.cc:76
void setNcpChannel(int chan)
Definition: channel.cc:118
void ncpConnect()
Definition: channel.cc:64
void terminateWhenAsked()
Definition: channel.cc:58
int getNcpChannel(void)
Definition: channel.cc:124
short int verbose
Definition: channel.h:71
linkChan(NCP *ncpController, int ncpChannel=-1)
Definition: linkchan.cc:36
void ncpConnectAck()
Definition: linkchan.cc:97
void Register(channel *)
Definition: linkchan.cc:118
void ncpConnectTerminate()
Definition: linkchan.cc:104
const char * getNcpRegisterName()
Definition: linkchan.cc:91
void ncpConnectNak()
Definition: linkchan.cc:112
bufferArray registerStack
Definition: linkchan.h:43
int registerSer
Definition: linkchan.h:42
void ncpDataCallback(bufferStore &a)
Definition: linkchan.cc:45
#define LINKCHAN_DEBUG_DUMP
Definition: linkchan.h:28
#define LINKCHAN_DEBUG_LOG
Definition: linkchan.h:27
Definition: doctest.h:522
std::ostream lerr
std::ostream lout
static rfsv * a
Definition: main.cc:53