Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add log #70

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/master_phpserial.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy PHP app to Azure Web App - phpserial

on:
push:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Check if composer.json exists
id: check_files
uses: andstor/file-existence-action@v1
with:
files: 'composer.json'

- name: Run composer install if composer.json exists
if: steps.check_files.outputs.files_exists == 'true'
run: composer validate --no-check-publish && composer install --prefer-dist --no-progress

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: php-app
path: .

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: php-app

- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: 'phpserial'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_3802BA5F7DB1469F8E6A590AF17D87FA }}
package: .
95 changes: 95 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<button onclick="startSerialCommunication()">Connect</button>
<button onclick="stopSerialCommunication()">Disconnect</button>
<input type="text" id="text"><button onclick="sendData()">Send</button>
<script>
let port, textEncoder, writer, writableStreamClosed = -1;

function sendData(){
let txt = document.getElementById("text").value;

writeSerialData(port, txt)
}

// Richiedi l'accesso alla porta seriale
async function requestSerialPort() {

try {
port = await navigator.serial.requestPort();
await port.open({ baudRate: 9600 }); // Configura la velocità di baud rate appropriata
let settings = {};

if (localStorage.dtrOn == "true") settings.dataTerminalReady = true;
if (localStorage.rtsOn == "true") settings.requestToSend = true;
if (Object.keys(settings).length > 0) await port.setSignals(settings);

textEncoder = new TextEncoderStream();
writableStreamClosed = textEncoder.readable.pipeTo(port.writable);
writer = textEncoder.writable.getWriter();

return port;
} catch (error) {
console.error("Errore durante la richiesta della porta seriale:", error);
}
}

// Leggi dati dalla porta seriale
async function readSerialData(port) {
const reader = port.readable.getReader();

while (true) {
try {
const { value, done } = await reader.read();
console.log("lettura porta:" + done);
if (done) break;
// Elabora i dati letti
console.log("Dati seriali ricevuti:", new TextDecoder().decode(value));
} catch (error) {
console.error("Errore durante la lettura dati seriali:", error);
break;
}
}

reader.releaseLock();
}

// Scrivi dati sulla porta seriale
async function writeSerialData(port, data) {



try {
await writer.write(data + "\n");
console.log("Dati seriali inviati con successo.");
} catch (error) {
console.error("Errore durante l'invio dati seriali:", error);
} finally {
//writer.releaseLock();
}
}

function stopSerialCommunication(){
writer.releaseLock();
}

// Esempio di utilizzo
async function startSerialCommunication() {
port = await requestSerialPort();
if (port) {
await readSerialData(port); // Avvia la lettura dei dati seriali
// Puoi anche scrivere dati sulla porta seriale utilizzando la funzione writeSerialData()
await writeSerialData(port, "Dati da inviare sulla porta seriale");
}
}

// Avvia la comunicazione seriale
</script>


</body>
</html>
155 changes: 154 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,156 @@
<?php
//require_once("jsSerialApi.js");

echo "Hello World!";
function sendData(){

echo "<button id='connectBtn' onclick='startSerialCommunication()'>Connect</button>";
//echo "<button onclick='stopSerialCommunication()'>Disconnect</button>"
echo " <button id='sendBtn' onclick='sendData()' disabled='true'>Send</button>";


$tipoMsg = "113";

$tmp = "$tipoMsg~0008";
/*
echo "<form name id='form1' method='post' action='/opt/web/php/accesso/awp/index.php/sessione/inviorichieste' enctype='application/x-www-form-urlencoded'>\n";
*/
echo "<form name='form1' id='form1' method='post' action='index.php' enctype='application/x-www-form-urlencoded'>\n";
// echo "<input type='hidden' id='com' name='com' value='{$com}'>\n";
// echo "<input type='hidden' id='idEnte' name='idEnte' value='{$_SESSION['AWP']['id_ente_old']}'>\n";
// echo "<input type='hidden' id='idVerifica' name='idVerifica' value='{$_SESSION['AWP']['id_ver']}'>\n";
// echo "<input type='hidden' id='richiesta' name='richiesta' value={$ricCryptToCard}>\n";
// echo "<input type='hidden' id='risposta' name='risposta' value='prova'>\n";
echo "<input type='hidden' id='rispostaCom' name='rispostaCom' value='prova'>\n";
echo "<input type='hidden' id='messaggio' name='messaggio' value='{$tmp}'>\n";
// echo "<input type='hidden' id='codeid' name='codeid' value='{$codeid}'>\n"; ///per passarlo quando ricarica la pag...... bah
// echo "<input type='hidden' id='tipoMsg' name='tipoMsg' value={$tipoMsg}>\n";
//echo "<script type='text/javascript'>\n";
//echo "alert(',,,,,,,,,'+document.getElementById('rispostaCom').value);\n";
//echo "sendData();\n";
//echo "document.getElementById('form1').submit();\n";
//echo "</script>\n";
//echo "<input type='submit' value='submit'>\n";
echo "</form >\n";

echo "<script type='text/javascript'>\n";
require_once("jsSerialApi.js");
echo "</script>\n";

}


function hexToStr($hex){
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2){
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}


if($_POST){


foreach ($_POST as $key => $value){
//echo "$key => $value";

$sel["$key"] = urldecode($value);
}


// $codeid = isset($sel['codeid'])?$sel['codeid']:null;
// $com = isset($sel['com'])?$sel['com']:null;
// $tipoMsg = isset($sel['tipoMsg'])?$sel['tipoMsg']:null;
// $risposta = isset($sel['risposta'])?$sel['risposta']:null;
$rispostaCom = isset($sel['rispostaCom'])?$sel['rispostaCom']:null;
//$richiesta = isset($sel['richiesta'])?$sel['richiesta']:null;
$pattern = '/^[a-fA-F0-9]{16,16}$/';

// $_SESSION['AWP']['id_ente_old']=isset($sel['idEnte'])?$sel['idEnte']:$_SESSION['AWP']['id_ente_old'];
// $_SESSION['AWP']['id_ver']=isset($sel['idVerifica'])?$sel['idVerifica']:$_SESSION['AWP']['id_ver'];

if($rispostaCom){

if($rispostaCom == 'prova' || $rispostaCom == null){

$rc="problemi con activex";
$fase = 4;
//$rc= getValue('help.txt',$fase);
}else{
//exit;
//$tmp1=explode('#',$richiesta);


$rispostaCom=hexToStr($rispostaCom);

$itemRis= explode('~',$rispostaCom);

// $data['CNTTOTIN'] = intval($itemRis[5]);
// $data['CNTTOTOT'] = intval($itemRis[6]);
// $data['CNTCL'] = intval($itemRis[7]);
// $data['CNTOT'] = intval($itemRis[9]);
// $data['CNTNP'] = intval($itemRis[10]);
// $data['CNTIN'] = intval($itemRis[8]);

// $message = 'CNTTOTIN:'. $data['CNTTOTIN'] .'<br>
// CNTTOTOT:'. $data['CNTTOTOT'].'<br>
// CNTCL:'. $data['CNTCL'] .'<br>
// CNTOT:'. $data['CNTOT'] .'<br>
// CNTNP:'. $data['CNTNP'] .'<br>
// CNTIN:'. $data['CNTIN'] .'<br>';

//echo $message;


$response = "########################################<br>
Id_messaggio: " . $itemRis[0] . "<br>
L_messaggio: " . $itemRis[1] . "<br>
DATA_Risposta: " . $itemRis[2] . "<br>
CODEID: " . $itemRis[3] . "<br>
ESITO: " . $itemRis[4] . "<br>
Valore contatore CNTTOTIN: " . $itemRis[5] . "<br>
Valore contatore CNTTOTOT: " . $itemRis[6] . "<br>
Valore contatore CNTCL: " . $itemRis[7] . "<br>
Valore contatore CNTIN: " . $itemRis[8] . "<br>
Valore contatore CNTOT: " . $itemRis[9] . "<br>
Valore contatore CNTNP: " . $itemRis[10] . "<br>
ORA_Risposta: " . $itemRis[11] . "<br>
Codice_autenticazione: " . $itemRis[12] . "<br>
Esito_comunicazione: " . $itemRis[13] . "<br>
########################################<br>";

echo $response;

echo "<script type='text/javascript'>\n";
echo "window.onload = function(){
document.getElementById('connectBtn').style.display = 'none';
document.getElementById('sendBtn').style.display = 'none';
}";
echo "</script>\n";

//echo $rispostaCom;
//die();
}
}
}



?>

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>

</head>
<body>
<!-- <button onclick="startSerialCommunication()">Connect</button>
<button onclick="stopSerialCommunication()">Disconnect</button>
<button onclick="sendData()">Send</button> -->
<?php
sendData();
?>
<!-- <script type="text/javascript" src='jsSerialApi.js'></script> -->
</body>
</html>
Loading