fix for back-to-back issue
This commit is contained in:
+14
-1
@@ -282,11 +282,24 @@ class Meshcore {
|
||||
*/
|
||||
public function sendBinaryRequest(string $request): mixed {
|
||||
CoreProtocol::writeFrame($this->serial, chr(CoreProtocol::CMD_SEND_BINARY_REQ) . $request);
|
||||
|
||||
do {
|
||||
$response = CoreProtocol::readFrame($this->serial);
|
||||
|
||||
}
|
||||
while(
|
||||
ord($response) != CoreProtocol::RESP_CODE_SENT &&
|
||||
ord($response) != CoreProtocol::ERR_CODE_NOT_FOUND &&
|
||||
ord($response) != CoreProtocol::ERR_CODE_NOT_FOUND
|
||||
);
|
||||
|
||||
return CoreParser::parseResponse($response);
|
||||
}
|
||||
|
||||
public function readFrame(): mixed {
|
||||
return CoreProtocol::readFrame($this->serial);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $tag
|
||||
@@ -305,7 +318,7 @@ class Meshcore {
|
||||
|
||||
usleep(500000);
|
||||
}
|
||||
while( (time() - $mark) < $timeout_ms );
|
||||
while( ((time() - $mark) * 1000) < $timeout_ms );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
+19
-9
@@ -14,7 +14,12 @@ $mc = Meshcore::getInstance();
|
||||
|
||||
$x = $mc->appStart("get remote tele");
|
||||
|
||||
$repeaters = ['Simpsonville 3810gvr1', 'Simpsonville im37r1'];
|
||||
|
||||
$contacts = $mc->getContacts();
|
||||
|
||||
echo "Found " . count($contacts) . " contacts\n";
|
||||
/*
|
||||
$idx = 1;
|
||||
foreach($contacts as $contact) {
|
||||
echo "(" . $idx++ . ") {$contact['contact_name']} [" . substr($contact['pub_key'], 0, 6) . "]\n";
|
||||
@@ -22,25 +27,30 @@ foreach($contacts as $contact) {
|
||||
|
||||
$choice = readline("\nPlease select contact to attempt remote login: ");
|
||||
$contact = $contacts[$choice - 1];
|
||||
*/
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
if( !in_array($contact['contact_name'], $repeaters) ) continue;
|
||||
|
||||
echo "Using {$contact['contact_name']}\n";
|
||||
|
||||
/*
|
||||
if( !$mc->connected($contact['pub_key']) ) {
|
||||
$password = readline("Password: ");
|
||||
|
||||
$mc->login($contact['pub_key'], $password);
|
||||
}
|
||||
*/
|
||||
|
||||
$req = base64_decode($contact['pub_key']) . chr(CoreProtocol::BINREQ_TELEMETRY);
|
||||
|
||||
$result = $mc->sendBinaryRequest($req);
|
||||
|
||||
if( !isset($result->tag) ) {
|
||||
var_dump($result);
|
||||
echo "sendBinaryRequest sent nothing??\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
echo "Tag: {$result->tag}\n";
|
||||
|
||||
$msg = $mc->pollForMessage($result->tag);
|
||||
|
||||
print_r($msg);
|
||||
echo json_encode($msg->lpp) . "\n";
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
echo "Complete\n";
|
||||
|
||||
Reference in New Issue
Block a user