84 lines
3.5 KiB
Plaintext
84 lines
3.5 KiB
Plaintext
package org.ka2ddo.yaac.core.queries;
|
|
/*
|
|
* Copyright (C) 2011-2021 Andrew Pavlin, KA2DDO
|
|
* This file is part of YAAC (Yet Another APRS Client).
|
|
*
|
|
* YAAC is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* YAAC is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* and GNU Lesser General Public License along with YAAC. If not,
|
|
* see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import org.ka2ddo.aprs.Message;
|
|
import org.ka2ddo.ax25.Connector;
|
|
import org.ka2ddo.yaac.ax25.StationTracker;
|
|
import org.ka2ddo.yaac.io.PortManager;
|
|
import org.ka2ddo.yaac.pluginapi.AbstractQueryHandler;
|
|
|
|
import java.util.Arrays;
|
|
|
|
/**
|
|
* This class handles queries for the list of stations directly reachable by this station over RF.
|
|
* @author Andrew Pavlin, KA2DDO
|
|
*/
|
|
public class DirectQueryHandler extends AbstractQueryHandler {
|
|
/**
|
|
* Handle the passed in message and generate whatever appropriate response should be made.
|
|
*
|
|
* @param mm MessageMessage addressed explicitly to local station whose content begins with
|
|
* one of the prefixes specified by the subclass.
|
|
*/
|
|
public void handleQuery(Message mm) {
|
|
long now = System.currentTimeMillis();
|
|
String[] directStations = StationTracker.getInstance().getDirectStationList(now);
|
|
if (directStations != null && directStations.length > 0) {
|
|
Arrays.sort(directStations);
|
|
int totalCharLen = 0;
|
|
for (String direct : directStations) {
|
|
totalCharLen += 1 + direct.length();
|
|
}
|
|
if (totalCharLen < 59) {
|
|
// can send answer in one piece without exceeding maximum message length
|
|
StringBuilder b = new StringBuilder(totalCharLen+8).append("Directs=");
|
|
for (String s : directStations) {
|
|
b.append(' ').append(s);
|
|
}
|
|
transmitReply(mm, b.toString());
|
|
} else {
|
|
int numDirectResponses = 0;
|
|
int index = 0;
|
|
StringBuilder b = new StringBuilder("Directs(");
|
|
while (index < directStations.length) {
|
|
b.append(++numDirectResponses).append(")=");
|
|
while (index < directStations.length && b.length() < 66) {
|
|
String station = directStations[index];
|
|
if (b.length() + station.length() + 1 < 67) {
|
|
b.append(' ').append(station);
|
|
index++;
|
|
} else {
|
|
break; // can't fit any more in this line
|
|
}
|
|
}
|
|
transmitReply(mm, b.toString());
|
|
b.setLength(8); // reset to use the prefix again
|
|
}
|
|
}
|
|
} else if (PortManager.getPreferredConnector(Connector.CAP_RF) == null) {
|
|
// must be only an I-Gate connection with no "locals" because no RF
|
|
transmitReply(mm, "Directs=none (APRS-IS only)");
|
|
} else {
|
|
// we have RF with no "locals"
|
|
transmitReply(mm, "Directs=none (with RF)");
|
|
}
|
|
}
|
|
}
|