42 _pStatus =
fgGetNode(
"/network/cpdlc/link/status",
true);
43 _pStatus->setIntValue(_status);
44 _pDataAuthority =
fgGetNode(
"/network/cpdlc/link/data-authority",
true);
45 _pDataAuthority->setStringValue(_data_authority);
47 _pMessage =
fgGetNode(
"/network/cpdlc/rx/message",
true);
48 _pMessage->setStringValue(
"");
49 _pNewMessage =
fgGetNode(
"/network/cpdlc/rx/new-message",
true);
50 _pNewMessage->setBoolValue(0);
73 if (_data_authority.empty()) {
74 if (authority.empty()) {
75 SG_LOG(SG_NETWORK, SG_WARN,
"cpdlcConnect not possible: empty argument!");
78 _data_authority = authority;
81 if (!authority.empty() && authority != _data_authority) {
82 SG_LOG(SG_NETWORK, SG_WARN,
"cpdlcConnect: cannot change authority now, use disconnect first!");
87 if (!_irc->isConnected()) {
88 SG_LOG(SG_NETWORK, SG_INFO,
"Connecting to IRC server...");
90 SG_LOG(SG_NETWORK, SG_WARN,
"IRC login failed.");
96 SG_LOG(SG_NETWORK, SG_INFO,
"CPDLC sending 'connect'");
98 _pStatus->setIntValue(_status);
106 if (_irc && _irc->isConnected() && !_data_authority.empty()) {
109 _data_authority =
"";
110 _pDataAuthority->setStringValue(_data_authority);
112 _pStatus->setIntValue(_status);
120 return _irc->sendPrivmsg(_data_authority, textline);
126 if (!_incoming_messages.empty()) {
127 struct IRCMessage entry = _incoming_messages.front();
128 _incoming_messages.pop_front();
130 if (_incoming_messages.empty()) {
131 _pNewMessage->setBoolValue(0);
144 if (_irc->isConnected()) {
146 SG_LOG(SG_NETWORK, SG_INFO,
"CPDLC IRC ready, connecting...");
149 if (_irc->hasMessage()) {
150 processMessage(_irc->getMessage());
156 _pStatus->setIntValue(_status);
162void CPDLCManager::processMessage(
struct IRCMessage message)
166 SG_LOG(SG_NETWORK, SG_INFO,
"CPDLC got connected.");
167 _data_authority = message.
sender;
168 _pDataAuthority->setStringValue(_data_authority);
170 _pStatus->setIntValue(_status);
173 if (message.
sender != _data_authority) {
174 SG_LOG(SG_NETWORK, SG_WARN,
"Received CPDLC message from foreign authority.");
179 if (message.
sender == _data_authority) {
180 SG_LOG(SG_NETWORK, SG_INFO,
"CPDLC got disconnect.");
186 SG_LOG(SG_NETWORK, SG_INFO,
"CPDLC message");
187 _incoming_messages.push_back(message);
188 _pNewMessage->setBoolValue(1);
bool connect(const std::string authority)
bool send(const std::string message)
CPDLCManager(IRCConnection *irc)
const std::string CPDLC_MSGPREFIX_CONNECT
const std::string CPDLC_MSGPREFIX_DISCONNECT
const std::string CPDLC_MSGPREFIX_MSG
const std::string CPDLC_IRC_SERVER
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.