2

GPS デバイスを構成し、C# でリスナー アプリケーションを作成しました。デバイスから IMEI 番号のみを受信し、GPS NMEA データは受信しません。しかし、GPS Gate Serverで同じことを確認すると、地図に動きが表示されます。助言がありますか!!!

以下は、データの処理方法です。

TcpClient client = (TcpClient)tcpClient;
Byte[] bytes = new Byte[10000];
String data = null;
int i;

NetworkStream stream = client.GetStream();

while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
}

Console.WriteLine(data);

whileループに入ると、待機してスリープします:(

4

5 に答える 5

1
  1. 最初にモジュールがサーバーに接続すると、モジュールはその IMEI を送信します。IMEI は、バーコードのエンコードと同じ方法で送信されます。
  2. 最初に、書き込まれたバイト数を識別する不足があり、次にテキスト (バイト) として IMEI が続きます。たとえば、IMEI 123456789012345 は 000F313233343536373839303132333435 として送信されます IMEI を受信した後、
  3. サーバーは、このモジュールからのデータを受け入れるかどうかを決定する必要があります。はいの場合、サーバーはモジュール 01 に応答します (00 でない場合)。確認はバイナリ パケットとして送信する必要があることに注意してください。
  4. その後、モジュールは firstAVL データ パケットの送信を開始します。
  5. サーバーがパケットを受信して​​解析した後、サーバーは受信したデータのモジュール番号を整数 (4 バイト) として報告する必要があります。送信データ数とサーバーからの報告が一致しない場合、モジュールは送信データを再送信します。

参考文献 FMXXXX プロトコル V2.7

于 2014-02-13T11:02:55.430 に答える
1

私はそのデバイスが次のようなパターンを持っていると思います

Step1:IMEI番号取得後

Step2:「01」ステータスを同じ新規ワークにリプレイ

コード:

TcpClient newClient = (TcpClient)client;

NetworkStream ns = newClient.GetStream()

byte[] bytes = new byte[1024];

bytes = Encoding.ASCII.GetBytes("X");

Console.WriteLine("X");

ns.Write(bytes, 0, bytes.Length);
于 2013-07-16T04:39:25.887 に答える
0

このようなことをする必要があると思います(簡単な解決策)。動作させることができる場合は、いくつかの非同期ソケット/TCP 接続を確認する必要があるかもしれません

TcpClient client = (TcpClient)tcpClient;
Byte[] bytes = new Byte[10000];
String data = null;
int i;

NetworkStream stream = client.GetStream();

// Will get data as long as data is available after 1st read
do
{
    i = stream.Read(bytes, 0, bytes.Length)
    data = String.Concat(data, System.Text.Encoding.ASCII.GetString(bytes, 0, i));
}
while(stream.DataAvailable); 

// Write the data to console (first time it should be IMEI
Console.WriteLine(data);     

// Write 1 to the stream, note it must probably be byte value 1 -> 0x01
// Flush output stream after writing to prevent buffering

data = "";

// Now try if more data comes in after IMEI and 0x01 reply
do
{
    i = stream.Read(bytes, 0, bytes.Length)
    data = String.Concat(data, System.Text.Encoding.ASCII.GetString(bytes, 0, i));
}
while(stream.DataAvailable);

// Write date to console - move inside the while loop if data keeps coming in
Console.WriteLine(data);     
于 2012-11-23T08:58:33.793 に答える
0

図のように、以下の手順を使用して最初にトラッカーを構成する必要があります。

構成プロセスを開始するために、構成サーバーは、サーバー ホスト (IP アドレス) を含むバイナリ開始 SMS (「プッシュ」SMS) を送信し、デバイスが接続する必要がある tcp ポートは、TCP 接続を待ちます。

「プッシュ」SMS を受信すると、デバイスは GPRS を使用して構成サーバーへの TCP 接続を確立しようとします。TCP 接続の試行が成功すると、サーバーは確立された接続を介してデバイスに構成データを送信し、デバイスは構成の受信を確認して自身を構成します。

デバイスが TcpWaitTimeout 時間内にサーバーに接続しない場合、サーバーは TCP 接続の待機を停止し、バイナリ SMS を使用して構成データを送信し、デバイスからの確認 SMS を待ちます。指定した時間内に確認 SMS が届かない場合、サーバーは設定プロセスが失敗したと見なします。 ここに画像の説明を入力

参考ファイル:
https ://sourceforge.net/p/opengts/discussion/579834/thread/6fd0ffe8/6213/attachment/FMXXXX%20Protocols%20v2.10.pdf

于 2016-09-16T09:35:48.487 に答える
-1

これは FM1100 のパーサーです。これは FM4200 モデルのコードを書くのに役立つかもしれません https://github.com/temala/Teltonika-FM1100

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Data;
using System.Net.Sockets;
using System.Linq;
using System.IO;

namespace TeltonikaParser
{
public class Protocol_TeltonikaFMXXXX
{
    private const int CODEC_FMXXX = 0x08;
    private const int ACC = 1;
    private const int DOOR = 2;
    private const int Analog = 4;
    private const int GSM = 5;
    private const int SPEED = 6;
    private const int VOLTAGE = 7;
    private const int GPSPOWER = 8;
    private const int TEMPERATURE = 9;
    private const int ODOMETER = 16;
    private const int STOP = 20;
    private const int TRIP = 28;
    private const int IMMOBILIZER = 29;
    private const int AUTHORIZED = 30;
    private const int GREEDRIVING = 31;
    private const int OVERSPEED = 33;



    private static string Parsebytes(Byte[] byteBuffer, int index, int Size)
    {
        return BitConverter.ToString(byteBuffer, index, Size).Replace("-", string.Empty);
    }

    private static string parseIMEI(Byte[] byteBuffer, int size)
    {
        int index = 0;
        var result = Parsebytes(byteBuffer, index, 2);
        return result;
    }

    private static bool checkIMEI(string data)
    {
        Console.WriteLine(data.Length);
        if (data.Length == 15)
            return true;

        return false;
    }

    private static List<Position> ParsePositions(Byte[] byteBuffer, int linesNB)
    {
        int index = 0;
        index += 7;
        uint dataSize = byteBuffer[index];

        index++;
        uint codecID = byteBuffer[index];

        if (codecID == CODEC_FMXXX)
        {
            index++;
            uint NumberOfData = byteBuffer[index];

            Console.WriteLine("{0} {1} {2} ", codecID, NumberOfData, dataSize);

            List<Position> result = new List<Position>();

            index++;
            for (int i = 0; i < NumberOfData; i++)
            {
                Position position = new Position();

                var timestamp = Int64.Parse(Parsebytes(byteBuffer, index, 8), System.Globalization.NumberStyles.HexNumber);
                index += 8;

                position.Time = DateTime.Now;

                var Preority = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                index++;

                position.Lo = Int32.Parse(Parsebytes(byteBuffer, index, 4), System.Globalization.NumberStyles.HexNumber) / 10000000.0;
                index += 4;

                position.La = Int32.Parse(Parsebytes(byteBuffer, index, 4), System.Globalization.NumberStyles.HexNumber) / 10000000.0;
                index += 4;

                var Altitude = Int16.Parse(Parsebytes(byteBuffer, index, 2), System.Globalization.NumberStyles.HexNumber);
                index += 2;

                var dir = Int16.Parse(Parsebytes(byteBuffer, index, 2), System.Globalization.NumberStyles.HexNumber);

                if (dir < 90) position.Direction = 1;
                else if (dir == 90) position.Direction = 2;
                else if (dir < 180) position.Direction = 3;
                else if (dir == 180) position.Direction = 4;
                else if (dir < 270) position.Direction = 5;
                else if (dir == 270) position.Direction = 6;
                else if (dir > 270) position.Direction = 7;
                index += 2;

                var Satellite = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                index++;

                if (Satellite >= 3)
                    position.Status = "A";
                else
                    position.Status = "L";

                position.Speed = Int16.Parse(Parsebytes(byteBuffer, index, 2), System.Globalization.NumberStyles.HexNumber);
                index += 2;

                int ioEvent = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                index++;
                int ioCount = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                index++;
                //read 1 byte
                {
                    int cnt = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                    index++;
                    for (int j = 0; j < cnt; j++)
                    {
                        int id = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                        index++;
                        //Add output status
                        switch (id)
                        {
                            case ACC:
                                {
                                    var value = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                                    position.Status += value == 1 ? ",ACC off" : ",ACC on";
                                    index++;
                                    break;
                                }
                            case DOOR:
                                {
                                    var value = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                                    position.Status += value == 1 ? ",door close" : ",door open";
                                    index++;
                                    break;
                                }
                            case GSM:
                                {
                                    var value = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                                    position.Status += string.Format(",GSM {0}", value);
                                    index++;
                                    break;
                                }
                            case STOP:
                                {
                                    var value = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                                    position.StopFlag = value == 1;
                                    position.IsStop = value == 1;

                                    index++;
                                    break;
                                }
                            case IMMOBILIZER:
                                {
                                    var value = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                                    position.Alarm = value == 0 ? "Activate Anti-carjacking success" : "Emergency release success";
                                    index++;
                                    break;
                                }
                            case GREEDRIVING:
                                {
                                    var value = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                                    switch (value)
                                    {
                                        case 1:
                                            {
                                                position.Alarm = "Acceleration intense !!";
                                                break;
                                            }
                                        case 2:
                                            {
                                                position.Alarm = "Freinage brusque !!";
                                                break;
                                            }
                                        case 3:
                                            {
                                                position.Alarm = "Virage serré !!";
                                                break;
                                            }
                                        default:
                                            break;
                                    }
                                    index++;
                                    break;
                                }
                            default:
                                {
                                    index++;
                                    break;
                                }
                        }

                    }
                }

                //read 2 byte
                {
                    int cnt = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                    index++;
                    for (int j = 0; j < cnt; j++)
                    {
                        int id = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                        index++;



                        switch (id)
                        {
                            case Analog:
                                {
                                    var value = Int16.Parse(Parsebytes(byteBuffer, index, 2), System.Globalization.NumberStyles.HexNumber);
                                    if (value < 12)
                                        position.Alarm += string.Format("Low voltage", value);
                                    index += 2;
                                    break;
                                }
                            case SPEED:
                                {
                                    var value = Int16.Parse(Parsebytes(byteBuffer, index, 2), System.Globalization.NumberStyles.HexNumber);
                                    position.Alarm += string.Format("Speed", value);
                                    index += 2;
                                    break;
                                }
                            default:
                                {
                                    index += 2;
                                    break;
                                }

                        }
                    }
                }

                //read 4 byte
                {
                    int cnt = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                    index++;
                    for (int j = 0; j < cnt; j++)
                    {
                        int id = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                        index++;

                        switch (id)
                        {
                            case TEMPERATURE:
                                {
                                    var value = Int32.Parse(Parsebytes(byteBuffer, index, 4), System.Globalization.NumberStyles.HexNumber);
                                    position.Alarm += string.Format("Temperature {0}", value);
                                    index += 4;
                                    break;
                                }
                            case ODOMETER:
                                {
                                    var value = Int32.Parse(Parsebytes(byteBuffer, index, 4), System.Globalization.NumberStyles.HexNumber);
                                    position.Mileage = value;
                                    index += 4;
                                    break;
                                }
                            default:
                                {
                                    index += 4;
                                    break;
                                }

                        }


                    }
                }

                //read 8 byte
                {
                    int cnt = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                    index++;
                    for (int j = 0; j < cnt; j++)
                    {
                        int id = byte.Parse(Parsebytes(byteBuffer, index, 1), System.Globalization.NumberStyles.HexNumber);
                        index++;

                        var io = Int64.Parse(Parsebytes(byteBuffer, index, 8), System.Globalization.NumberStyles.HexNumber);
                        position.Status += string.Format(",{0} {1}", id, io);
                        index += 8;
                    }
                }

                result.Add(position);
                Console.WriteLine(position.ToString());
            }

            return result;
        }
        return null;
    }

    public static Byte[] DealingWithHeartBeat(string data)
    {

        Byte[] result = { 1 };
        if (checkIMEI(data))
        {
            return result;
        }
        return null;
    }

    public static string ParseHeartBeatData(Byte[] byteBuffer, int size)
    {
        var IMEI = parseIMEI(byteBuffer, size);
        if (checkIMEI(IMEI))
        {
            return IMEI;
        }
        else
        {
            int index = 0;
            index += 7;
            uint dataSize = byteBuffer[index];

            index++;
            uint codecID = byteBuffer[index];

            if (codecID == CODEC_FMXXX)
            {
                index++;
                uint NumberOfData = byteBuffer[index];

                return NumberOfData.ToString();
            }
        }
        return string.Empty;
    }
    public static List<Position> ParseData(Byte[] byteBuffer, int size)
    {

        List<Position> result = new List<Position>();
        result = ParsePositions(byteBuffer, size);
        return result;
    }

    public static Position GetGPRSPos(string oneLine)
    {
        return null;
    }
}
}
于 2015-04-29T13:51:05.870 に答える