-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsip2.php
98 lines (93 loc) · 3.12 KB
/
sip2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
// +-------------------------------------------------+
// © 2002-2004 PMB Services / www.sigb.net [email protected] et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: sip2.php,v 1.7 2017-02-16 09:23:09 mbertin Exp $
$time_log_start=microtime(true);
// définition du minimum nécéssaire
$base_path=".";
$base_auth = "CIRCULATION_AUTH";
$base_noheader=1;
require_once("$base_path/includes/init.inc.php");
require_once("$class_path/sip2_protocol.class.php");
require_once("$class_path/sip2_trame.class.php");
require_once("$include_path/sip2/sip2_functions.inc.php");
$message=stripslashes($message);
$protocol=new sip2_protocol("$include_path/sip2/protocol.xml",$charset);
if($debug) $fp_debug_rfid=fopen("temp/messages.log","a+");
$info_debug_rfid="Date (".$automate."): ".date("Y-m-d H:i:s")."\n";
$info_debug_rfid.="Trame recue: ".$message."\n";
//Analyse de la trame
$trame=new sip2_trame($message,$protocol);
$last_trame="";
$message_pair="";
//Si il y a une erreur ?
if ($trame->error) {
$info_debug_rfid.="Erreur trame reçue: ".$tramer->error_message."\n";
print $trame->error_message;
//Si c'est une erreur on redemande le message
$message_pair=96;
$values=array();
} else {
//Sinon tout va bien
$message_pair=$trame->message_pair;
$values=$trame->message_values;
if ($trame->message_id==97) {
//Demande du dernier message
if ($_SESSION[$id]["ltrame"]) {
//Si dernier message pas vide
$last_trame=$_SESSION[$id]["ltrame"];
$info_debug_rfid.="Trame reponse session: ".$_SESSION[$id]["ltrame"]."\n";
print $_SESSION[$id]["ltrame"];
$message_pair="";
} else {
//Si dernier message vide, on envoie une redemande
$message_pair=96;
$values=array();
}
}
}
if ($message_pair) {
$tramer=new sip2_trame("",$protocol);
$tramer->set_message_id($message_pair);
$tramer->set_checksum(true);
$tramer->set_sequence_number($trame->sequence_number*1);
//Appel de la fonction
$func_response="_".strtolower($protocol->messages[$message_pair]["NAME"])."_";
$values=$func_response($values);
$tramer->set_message_values($values);
//Si il y a une erreur, erreur définitive !
if ($tramer->error) {
$info_debug_rfid.="Function: ".$func_response."\n";
$info_debug_rfid.="Erreur trame n1: ".$tramer->error_message."\n";
print $tramer->error_message;
print "exit";
} else {
//On construit la trame
$tramer->make_trame();
//Si il y a une erreur
if ($tramer->error) {
$info_debug_rfid.="Erreur trame n2: ".$tramer->error_message."\n";
print $tramer->error_message;
print "exit";
} else {
if($rtim){
$tramer->trame=rtrim($tramer->trame);
}
$info_debug_rfid.="Trame reponse: ".$tramer->trame."\n";
print $tramer->trame;
$last_trame=$tramer->trame;
}
}
}
if($fp_debug_rfid){
$time_log_end=microtime(true);
$duree=number_format(($time_log_end-$time_log_start), 3);
if($duree > 15){
$info_debug_rfid.="Lenteur traitement\n";
}
$info_debug_rfid.="Script execute en: ".$duree." sec\n\n";
fwrite($fp_debug_rfid,$info_debug_rfid);
fclose($fp_debug_rfid);
}
$_SESSION[$id]["ltrame"]=$last_trame;