IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Communiquer avec un GPS


Sujet :

Langage PHP

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2011
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2011
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Communiquer avec un GPS
    Bonjour,
    j'ai développé une application de suivi (php) mais je suis bloqués à l'étape de communication avec le tracker GPS ..
    j'ai essayé ce code pour récupérer les informations envoyer par le trackeur GPS

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    <?php
     
    $ip = '127.0.0.1';
    $port = 1108 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;
     
    $__server_listening = true;
     
    error_reporting(E_ALL);
    set_time_limit(0);
    ob_implicit_flush();
    declare(ticks = 1);
     
    become_daemon();
     
    /* nobody/nogroup, change to your host's uid/gid of the non-priv user */
    change_identity(65534, 65534);
     
    /* handle signals */
    pcntl_signal(SIGTERM, 'sig_handler');
    pcntl_signal(SIGINT, 'sig_handler');
    pcntl_signal(SIGCHLD, 'sig_handler');
     
    /* change this to your own host / port */
    server_loop($ip, $port);
     
    /**
    * Change the identity to a non-priv user
    */
    function change_identity( $uid, $gid )
    { 
    if( !posix_setgid( $gid ) )
    {
     
    print "Unable to setgid to " . $gid . "!\n";
    exit;
    }
     
    if( !posix_setuid( $uid ) )
    {
    print "Unable to setuid to " . $uid . "!\n";
    exit;
    }
    }
     
    /**
    * Creates a server socket and listens for incoming client connections
    * @param string $address The address to listen on
    * @param int $port The port to listen on
    */
    function server_loop($address, $port)
    {
    GLOBAL $__server_listening;
    if(($sock = socket_create(AF_INET, SOCK_STREAM, 0)) < 0)
    {
    echo "failed to create socket: ".socket_strerror($sock)."\n";
    exit();
     
    }
     
    if(($ret = socket_bind($sock, $address, $port)) < 0)
    {
    echo "failed to bind socket: ".socket_strerror($ret)."\n";
    exit();
     
    }
     
    if( ( $ret = socket_listen( $sock, 0 ) ) < 0 )
    {
    echo "failed to listen to socket: ".socket_strerror($ret)."\n";
    exit();
    }
     
    socket_set_nonblock($sock);
     
    echo "waiting for clients to connect\n";
     
    while ($__server_listening)
    {
    $connection = @socket_accept($sock);
    if ($connection === false)
    {
    usleep(100);
    }elseif ($connection > 0)
    {
    handle_client($sock, $connection);
    }else
    {
    echo "error: ".socket_strerror($connection);
    die;
    }
    }
    }
     
    /**
    * Signal handler
    */
    function sig_handler($sig)
    {
    switch($sig)
    {
    case SIGTERM:
    case SIGINT:
    //exit();
    break;
     
    case SIGCHLD:
    pcntl_waitpid(-1, $status);
    break;
    }
    }
     
    /**
    * Handle a new client connection
    */
    function handle_client($ssock, $csock)
    {
    GLOBAL $__server_listening;
     
    $pid = pcntl_fork();
     
    if ($pid == -1)
    {
    /* fork failed */
    echo "fork failure!\n";
    die;
    }elseif ($pid == 0)
    {
    /* child process */
    $__server_listening = false;
    socket_close($ssock);
    interact($csock);
    socket_close($csock);
    }else
    {
    socket_close($csock);
    }
    }
     
    function interact($socket)
    {
    /* TALK TO YOUR CLIENT */
    $rec = "";
    socket_recv($socket, $rec, 20480, 0);
    $parts = preg_split(',',$rec);
    $cnx = mysql_connect('localhost', 'user', 'password');
    /*
    Array
    (
    [0] => 0908242216
    [1] => 0033663282263
    [2] => GPRMC
    [3] => 212442.000
    [4] => A
    [5] => 4849.0475
    [6] => N
    [7] => 00219.4763
     => E
    [9] => 2.29
    [10] =>
    [11] => 220809
    [12] =>
    [13] =>
    [14] => A*70
    [15] => L
    [16] => imei:359587017313647
    [17] => 101Q
    [18] =>
    
    )
    */
     
     
    $trackerdate = mysql_real_escape_string($parts[0]);
    $phone = mysql_real_escape_string($parts[1]);
    $gprmc = mysql_real_escape_string($parts[2]);
    $satelliteDerivedTime = mysql_real_escape_string($parts[3]);
    $satelliteFixStatus = mysql_real_escape_string($parts[4]);
    $latitudeDecimalDegrees = mysql_real_escape_string($parts[5]);
    $latitudeHemisphere = mysql_real_escape_string($parts[6]);
    $longitudeDecimalDegrees = mysql_real_escape_string($parts[7]);
    $longitudeHemisphere = mysql_real_escape_string($parts);
    $speed = mysql_real_escape_string($parts[9]);
    $bearing = mysql_real_escape_string($parts[10]);
    $utcDate = mysql_real_escape_string($parts[11]);
    // = $parts[12];
    // = $parts[13];
    $checksum = mysql_real_escape_string($parts[14]);
    $gpsSignalIndicator = mysql_real_escape_string($parts[15]);
    if(ereg("imei",$parts[16]))
    {
    $imei = mysql_real_escape_string($parts[16]);
    $other = mysql_real_escape_string($parts[17].' '.$parts[18]);
    }
    else
    {
    $imei = mysql_real_escape_string($parts[17]);
    $other = mysql_real_escape_string($parts[18].' '.$parts[19]);
    }
     
    $imei = substr($imei,5);
    $other=$rec;
    mysql_select_db('tracker', $cnx);
    if($gpsSignalIndicator != 'L')
    mysql_query("INSERT INTO gprmc (date, imei, phone, trackerdate, satelliteDerivedTime, satelliteFixStatus, latitudeDecimalDegrees, latitudeHemisphere, longitudeDecimalDegrees, longitudeHemisphere, speed, Bearing, utcDate, Checksum, gpsSignalIndicator, other) VALUES (now(), '$imei', '$phone', '$trackerdate', '$satelliteDerivedTime', '$satelliteFixStatus', '$latitudeDecimalDegrees', '$latitudeHemisphere', '$longitudeDecimalDegrees', '$longitudeHemisphere', '$speed', '$bearing', '$utcDate', '$checksum', '$gpsSignalIndicator', '$other')", $cnx);
    mysql_close($cnx);
    }
     
    /**
    * Become a daemon by forking and closing the parent
    */
    function become_daemon()
    {
    $pid = pcntl_fork();
     
    if ($pid == -1)
    {
    /* fork failed */
    echo "fork failure!\n";
    exit();
    }elseif ($pid)
    {
    /* close the parent */
    exit();
    }else
    {
    /* child becomes our daemon */
    posix_setsid();
    chdir('/');
    umask(0);
    return posix_getpid();
     
    }
    } 
     
    ?>
    mais j'ai reçu un message d'erreur :
    Fatal error: Call to undefined function pcntl_fork() in C:\xampp\htdocs\communication\nh.php on line 214


    je vous merci d'avance

  2. #2
    Membre éclairé
    Avatar de keaton7
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    743
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 743
    Points : 689
    Points
    689
    Par défaut
    Bonjour,
    CF la doc
    Le support du contrôle des processus n'est pas activé par défaut en PHP. Vous devez compiler la version CLI ou CGI de PHP avec l'option de configuration --enable-pcntl pour activer le support de cette extension.
    Il semble que l'extension ne soit pas activée dans ton cas.

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Janvier 2012
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Janvier 2012
    Messages : 1
    Points : 1
    Points
    1
    Par défaut
    bonjour hiba, enfin je travail sur le même fichier , et après quelque recherches ,j'ai finis par trouver que la fonction "pcntl_fork()" ne marche pas avec le php sous le WIN32 ,et fonctionne correctement sous Linux . b.courage.

Discussions similaires

  1. [PHP 5.2] Communiquer avec un trackeur GPS
    Par g_escande81 dans le forum Langage
    Réponses: 3
    Dernier message: 28/05/2013, 10h17
  2. [MFC] [POCKETPC] S'interfacer avec un GPS
    Par Yellowmat dans le forum MFC
    Réponses: 2
    Dernier message: 06/10/2005, 14h15
  3. Réponses: 7
    Dernier message: 27/09/2005, 10h38
  4. [Lisp] Communiquer avec une fonction en c++
    Par Nadine dans le forum Lisp
    Réponses: 5
    Dernier message: 10/01/2005, 20h15
  5. [TComport] communiquer avec un PIC
    Par tracks dans le forum C++Builder
    Réponses: 5
    Dernier message: 09/06/2004, 13h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo