function newRadio($name = "", $description = "", $location = "") { global $db; //First see if there is a radio there using default address $returnArray = array(); exec("nrfcl -t f0f0f0f001 -r f0f0f0f001 gi", $returnArray); if (!isset($returnArray[0]) or strpos($returnArray[0], "ok") === false) { echo "No radio communication"; return false; } $sql = "SELECT max(rxAddress0) from radios"; $result = $db->query($sql); if ($result == false) { $freq = "f0f0f0f002"; } else { $row = $result->fetchArray(SQLITE3_NUM); if ($row[0] == NULL) { $freq = "f0f0f0f002"; } else { $lastFreq = $row[0]; $freqNum = "0x" . substr($lastFreq, 6); $thisFreq = intval($freqNum, 16) + 1; $newFreq = dechex($thisFreq); while (strlen($newFreq) < 4) { $newFreq = "0" . $newFreq; } $freq = substr($lastFreq, 0, 6) . $newFreq; } } // Now actually send the changes to the radio // set the receive frequency to the new frequency $command = "nrfcl -t f0f0f0f001 -r f0f0f0f001 RC:0:0x{$freq}"; $returnArray = 0; exec($command, $returnArray); if (count($returnArray) < 2) { print_r($returnArray); return false; } // set the transmit frequency to the new frequency $command = "nrfcl -t {$freq} -r {$freq} RC:T:0x{$freq}"; $returnArray = 0; exec($command, $returnArray); if (count($returnArray) < 2) { print_r($returnArray); return false; } // do the update return existingNewRadio($name, $description, $location, $freq); }
function processExistingRadio() { $name = $_POST['name']; if (isset($_POST['description'])) { $description = $_POST['description']; } else { $description = ""; } if (isset($_POST['location'])) { $location = $_POST['location']; } else { $location = ""; } $channel = $_POST['channel']; if (preg_match('/^[a-zA-Z0-9:-]+$/', $channel) != 1) { return "Invalid channel."; } include_once 'functions.php'; return existingNewRadio($name, $description, $location, $channel); }