require "utils/utils.php"; if (file_exists("local.aprsbot.cfg.php")) { require "local.aprsbot.cfg.php"; } else { require "aprsbot.cfg.php"; } $aprs = new phpaprs\APRS(); $aprs->_debug = $debug; $beacon = new packets\APRS_Item(BEACON_LATITUDE, BEACON_LONGITUDE, MYCALL, BEACON_SYMBOL, BEACON_STATUS); $beacon->setCallsign(MYCALL); $filter = FILTER; if ($aprs->connect(HOST, PORT, MYCALL, PASSCODE, $filter) == FALSE) { die("Connect failed\n"); } $lastbeacon = 1; // Setup our callbacks to process incoming stuff $aprs->addCallback(APRSCODE_MESSAGE, "*", "handlemessage"); $aprs->addCallback(APRSCODE_STATUS, "*", "handlestatus"); $aprs->addCallback(APRSCODE_POSITION, "*", "handleposition"); while (1) { // Beacon every BEACON_INTERVAL seconds if (time() - $lastbeacon > BEACON_INTERVAL) { echo "Send beacon\n"; $aprs->sendPacket($beacon); $lastbeacon = time(); } $aprs->ioloop(5); // handle I/O events sleep(1); // sleep for a second to prevent cpu spinning }
$beacon = new packets\APRS_Item(BEACON_LATITUDE, BEACON_LONGITUDE, MYCALL, BEACON_SYMBOL, BEACON_STATUS); $beacon->setCallsign(MYCALL); //update the airplane table with most recent DDB data $ogn->updateAirplaneTable(); //optionally provide an array of aircraft registrations you want to add to the airplane table // set the APRS filter (to specify what messages we want to receive) $filter = FILTER; if (empty($filter)) { $filter = $ogn->getFilter(); } // connect to OGN's APRS Server if ($aprs->connect(HOST, PORT, MYCALL, PASSCODE, $filter) == FALSE) { die("Connect failed\n"); } $lastbeacon = 1; // Setup our callbacks to process incoming stuff $aprs->addCallback(APRSCODE_POSITION_TS, "APRS", array($ogn, "handlePosition")); while (1) { // send our own beacon every N seconds to keep connection alive if (time() - $lastbeacon > BEACON_INTERVAL) { echo "Send beacon\n"; $aprs->sendPacket($beacon); $lastbeacon = time(); } // handle any received APRS messages $aprs->ioloop(5); // Save buffered messages to database $ogn->savePositions(); sleep(1); // sleep for a second to prevent cpu spinning }