dongxie3701 2009-09-19 23:09
浏览 73
已采纳

TCP服务器(php)

I have a gps simulator, which sends continuous location data (nmea strings) through tcpip to 192.168.0.178:2323. How do I get that data using tcp socket and write to DB (php & mysql)?

Thanks!

  • 写回答

2条回答 默认 最新

  • down2323 2009-09-19 23:24
    关注

    This is a loaded question. First you need to read the data. Then you have to put some structure to the data for it to be usable. It doesn't do you much good to just dump lat-lon to a database. You probably want to save it as a waypoint or part of a track etc.

    So I have no answer to the DB question. Here is part of the PHP program I use to read GPS data off my phone connected to a CradlePoint router. It's modified from GoogleNav code.

    function read_gps() {
            set_time_limit(5);
            $fp = fsockopen ("192.168.0.1", 8080, $errno, $errstr, 30);
            if (!$fp) {
               die ("$errstr ($errno)");
            }
            $point=false;
            $status="";
            $fix=0;
            while (!$point) {
                    $string=@fgets($fp, 4096);
                    switch (substr($string,0,6)) {
                            case "\$GPRMC" :
                                    list($sentence, $time, $status, $latitude, $NS, $longitude, $EW, $speed, $course, $date, $magvar, $magvarEW)= explode(",", trim($string));
                                    $latd=convdec($latitude, $NS);
                                    $lond=convdec($longitude, $EW);
                                    break;
                            case "\$GPGGA" :
                                    list($sentence, $time, $latitude, $NS, $longitude, $EW, $fix, $nbsat, $HDOP, $altitude,,,,,)= explode(",", trim($string));
                                    $latd=convdec($latitude, $NS);
                                    $lond=convdec($longitude, $EW);
                                    break;
                            default :
                            break;
                    }
    
                    if ($status=="A" and $fix == 1){
                            $point=true;
                    }
            }
            ...
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度