function existingNewRadio($name = "", $description = "", $location = "", $freq) { global $db; //First see if there is a radio there using default address $returnArray = array(); exec("nrfcl -t {$freq} -r {$freq} gi", $returnArray); if (!isset($returnArray[0]) or strpos($returnArray[0], "ok") === false) { echo "No radio communication!<br/>"; print_r($returnArray); return false; } $returnString = ""; foreach ($returnArray as $line) { if (strpos($line, "Transmitting") === false) { $returnString .= $line; } } //Make sure we got the whole message if (strpos($returnString, "Pr") === false or strpos($returnString, "Sw") === false or strpos($returnString, "In") === false or strpos($returnString, "Li") === false or strpos($returnString, "CC") === false) { echo "Didn't receive summary."; return false; } // k cool. We have all the info $radioParams = explode(",", $returnString); for ($x = 0; $x < count($radioParams); $x += 2) { $number = explode("/", $radioParams[$x + 1]); $programmed = $number[0]; $total = $number[1]; switch ($radioParams[$x]) { case "Pr": $programs = $total; break; case "Sw": $switches = $total; break; case "In": $inputs = $total; break; case "Li": $limits = $total; break; case "CC": $colorChanges = $total; break; } } $sql = "INSERT INTO radios (name, description, location, switchCount, \n programCount, inputCount, timeLimitCount, colorChangeCount, txAddress, \n rxAddress0) values (:name, :description, :location, {$switches}, \n {$programs}, {$inputs}, {$limits}, {$colorChanges}, '{$freq}', '{$freq}')"; $statement = $db->prepare($sql); if (!$statement->bindValue(":name", $name, SQLITE3_TEXT)) { echo $db->lastErrorMsg(); } $statement->bindValue(":description", $description, SQLITE3_TEXT); $statement->bindValue(":location", $location, SQLITE3_TEXT); $result = $statement->execute(); if (!$result) { echo $db->lastErrorMsg(); } $radioID = $db->lastInsertRowID(); // save setup $command = "nrfcl -t {$freq} -r {$freq} SA"; exec($command, $returnArray); // set clock $command = "nrfcl -t {$freq} -r {$freq}"; exec($command, $returnArray); // get info from the radio processRadio($radioID); return "ok"; }
function updateRadio() { include_once 'functions.php'; return processRadio($_POST['radioID']); }