Ejemplo n.º 1
0
        public GPS_RESPONSE SendColdStart(int retry, int timeout)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[15];
            cmdData[0] = 0x01;
            cmdData[1] = 0x03;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            for (int i = 0; i < retry; ++i)
            {
                retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), timeout);
                if (retval == GPS_RESPONSE.ACK)
                {
                    break;
                }
            }
            return retval;
        }
Ejemplo n.º 2
0
        public GPS_RESPONSE SetGpsEphemeris(string ephFile)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[87];
            byte[] ephData = new byte[86];
            cmdData[0] = 0x41;
            int ephStart = 0;
            FileStream fileStream = new FileStream(ephFile, FileMode.Open, FileAccess.Read);
            for (int i = 0; i < 32; ++i)
            {
                fileStream.Read(ephData, 0, 86);
                ephStart += 86;

                int zeroCount = 0;
                foreach(byte b in ephData)
                {
                    if(b == 0)
                        zeroCount++;
                }
                if (zeroCount > 60)
                    continue;

                System.Array.Copy(ephData, 0, cmdData, 1, 86);
                BinaryCommand cmd = new BinaryCommand(cmdData);

                retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 4000);
                if (retval != GPS_RESPONSE.ACK)
                {
                    break;
                }
            }
            fileStream.Close();
            return retval;
        }
Ejemplo n.º 3
0
        public GPS_RESPONSE QueryRtc(ref UInt32 rtc)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;

            byte[] cmdData = new byte[5];
            byte[] recv_buff = new byte[128];

            cmdData[0] = 0x71;
            cmdData[1] = 0x20;
            cmdData[2] = 0x01;
            cmdData[3] = 0x4C;
            cmdData[4] = 0x34;

            BinaryCommand cmd = new BinaryCommand(cmdData);

            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 1000);
            if (retval == GPS_RESPONSE.ACK)
            {
                byte[] retCmd = new byte[128];
                retval = WaitReturnCommand(0xc0, retCmd, 1000);
                rtc = (UInt32)retCmd[5] << 24 | (UInt32)retCmd[6] << 16 |
                    (UInt32)retCmd[7] << 8 | (UInt32)retCmd[8];
            }
            return retval;
        }
Ejemplo n.º 4
0
        public GPS_RESPONSE QueryVersion(int timeout, ref String kVer, ref String sVer, ref String rev)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[2];
            cmdData[0] = 0x02;
            cmdData[1] = 0x01;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), timeout);
            if (retval == GPS_RESPONSE.ACK)
            {
                byte[] retCmd = new byte[128];
                retval = WaitReturnCommand(0x80, retCmd, 1000);

                kVer = retCmd[7].ToString("00") + "." + retCmd[8].ToString("00") + "." + retCmd[9].ToString("00");
                sVer = retCmd[11].ToString("00") + "." + retCmd[12].ToString("00") + "." + retCmd[13].ToString("00");
                rev = (retCmd[15] + 2000).ToString("0000") + retCmd[16].ToString("00") + retCmd[17].ToString("00");
            }

            return retval;
        }
Ejemplo n.º 5
0
        public GPS_RESPONSE QueryChannelDoppler(byte channel, ref UInt32 prn, ref UInt32 freq)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[2];
            cmdData[0] = 0x7B;
            cmdData[1] = channel;

            BinaryCommand cmd = new BinaryCommand(cmdData);

            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 2000);
            if (retval == GPS_RESPONSE.ACK)
            {
                byte[] retCmd = new byte[128];
                retval = WaitReturnCommand(0xFE, retCmd, 2000);
                if (retval != GPS_RESPONSE.ACK)
                {
                   // int a = 0;
                }
                prn = (UInt32)retCmd[5] << 8 | (UInt32)retCmd[6];
                freq = (UInt32)retCmd[7] << 8 | (UInt32)retCmd[8];
            }
            else
            {
                //int a = 0;
            }

            return retval;
        }
Ejemplo n.º 6
0
        public GPS_RESPONSE QueryCrc(int timeout, ref uint crc)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[2];
            cmdData[0] = 0x03;
            cmdData[1] = 0x01;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), timeout);
            if (retval == GPS_RESPONSE.ACK)
            {
                byte[] retCmd = new byte[128];
                retval = WaitReturnCommand(0x81, retCmd, 1000);

                crc = ((uint)retCmd[6] << 8) + retCmd[7];
            }
            return retval;
        }
Ejemplo n.º 7
0
        public GPS_RESPONSE NoNmeaOutput()
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[2];
            cmdData[0] = 0x09;
            cmdData[1] = 0x00;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 1000);
            return retval;
        }
Ejemplo n.º 8
0
        public GPS_RESPONSE ChangeBaudRate(int timeout, byte baudrateIdx)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[4];
            cmdData[0] = 0x05;
            cmdData[1] = 0x0;
            cmdData[2] = baudrateIdx;
            cmdData[3] = 0x00;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), timeout);
            return retval;
        }
Ejemplo n.º 9
0
        public GPS_RESPONSE FactoryReset()
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[2];
            cmdData[0] = 0x04;
            cmdData[1] = 0x01;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 5000);
            return retval;
        }
Ejemplo n.º 10
0
        public GPS_RESPONSE GetRegister(int timeout, UInt32 regAddr, ref UInt32 data)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;

            byte[] cmdData = new byte[5];
            byte[] recv_buff = new byte[128];

            cmdData[0] = 0x71;
            cmdData[1] = (byte)(regAddr >> 24 & 0xFF);
            cmdData[2] = (byte)(regAddr >> 16 & 0xFF);
            cmdData[3] = (byte)(regAddr >> 8 & 0xFF);
            cmdData[4] = (byte)(regAddr & 0xFF);

            BinaryCommand cmd = new BinaryCommand(cmdData);

            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), timeout);
            if (retval == GPS_RESPONSE.ACK)
            {
                byte[] retCmd = new byte[128];
                retval = WaitReturnCommand(0xc0, retCmd, 1000);
                data = (UInt32)retCmd[5] << 24 | (UInt32)retCmd[6] << 16 |
                    (UInt32)retCmd[7] << 8 | (UInt32)retCmd[8];
            }
            return retval;
        }
Ejemplo n.º 11
0
        public GPS_RESPONSE ConfigNoOutput(int timeout)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[2];
            cmdData[0] = 0x09;
            cmdData[1] = 0x02;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), timeout);
            return retval;
        }
Ejemplo n.º 12
0
        public GPS_RESPONSE ConfigNmeaOutput(byte gga, byte gsa, byte gsv, byte gll, byte rmc, byte vtg, byte zda, byte attr)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[9];
            cmdData[0] = 0x08;
            cmdData[1] = gga;
            cmdData[2] = gsa;
            cmdData[3] = gsv;
            cmdData[4] = gll;
            cmdData[5] = rmc;
            cmdData[6] = vtg;
            cmdData[7] = zda;
            cmdData[8] = attr;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 2000);
            return retval;
        }
Ejemplo n.º 13
0
        public GPS_RESPONSE ConfigMessageOutput(byte type)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[3];
            cmdData[0] = 0x09;
            cmdData[1] = type;
            cmdData[2] = 0;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 2000);
            return retval;
        }
Ejemplo n.º 14
0
        public GPS_RESPONSE SetRegister(int timeout, UInt32 regAddr, UInt32 data)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;

            byte[] cmdData = new byte[9];
            byte[] recv_buff = new byte[128];

            cmdData[0] = 0x72;
            cmdData[1] = (byte)(regAddr >> 24 & 0xFF);
            cmdData[2] = (byte)(regAddr >> 16 & 0xFF);
            cmdData[3] = (byte)(regAddr >> 8 & 0xFF);
            cmdData[4] = (byte)(regAddr & 0xFF);
            cmdData[5] = (byte)(data >> 24 & 0xFF);
            cmdData[6] = (byte)(data >> 16 & 0xFF);
            cmdData[7] = (byte)(data >> 8 & 0xFF);
            cmdData[8] = (byte)(data & 0xFF);

            BinaryCommand cmd = new BinaryCommand(cmdData);

            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), timeout);
            return retval;
        }
Ejemplo n.º 15
0
        public GPS_RESPONSE QueryChannelClockOffset(Int32 gdClockOffset, UInt32 prn, UInt32 freq, ref Int32 clkData)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[9];
            cmdData[0] = 0x7C;
            cmdData[1] = (byte)(gdClockOffset >> 24 & 0xFF);;
            cmdData[2] = (byte)(gdClockOffset >> 16 & 0xFF);;
            cmdData[3] = (byte)(gdClockOffset >> 8 & 0xFF);;
            cmdData[4] = (byte)(gdClockOffset & 0xFF);;
            cmdData[5] = (byte)(prn >> 8 & 0xFF);
            cmdData[6] = (byte)(prn & 0xFF);
            cmdData[7] = (byte)(freq >> 8 & 0xFF);
            cmdData[8] = (byte)(freq & 0xFF);

            BinaryCommand cmd = new BinaryCommand(cmdData);

            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 2000);
            if (retval == GPS_RESPONSE.ACK)
            {
                byte[] retCmd = new byte[128];
                retval = WaitReturnCommand(0xFF, retCmd, 2000);
                clkData = (Int32)((UInt32)retCmd[5] << 24 | (UInt32)retCmd[6] << 16 |
                    (UInt32)retCmd[7] << 8 | (UInt32)retCmd[8]);
            }
            return retval;
        }
Ejemplo n.º 16
0
        public GPS_RESPONSE StartDownload(byte baudrateIdx)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[6];
            cmdData[0] = 0x0B;
            cmdData[1] = baudrateIdx;
            cmdData[2] = 0x0;
            cmdData[3] = 0x0;
            cmdData[4] = 0x0;
            cmdData[5] = 0x0;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 3000);
            return retval;
        }
Ejemplo n.º 17
0
        public GPS_RESPONSE ChangeBaudrate(byte baudrateIndex, byte mode, bool noDelay)
        {
            GPS_RESPONSE retval = GPS_RESPONSE.NONE;
            byte[] cmdData = new byte[4];
            cmdData[0] = 0x05;
            cmdData[1] = 0x00;
            cmdData[2] = baudrateIndex;
            cmdData[3] = mode;

            BinaryCommand cmd = new BinaryCommand(cmdData);
            retval = SendCmdAck(cmd.GetBuffer(), cmd.Size(), 2000);
            if (retval == GPS_RESPONSE.ACK)
            {
                if (!noDelay)
                {
                    Thread.Sleep(1000);
                }
                serial.Close();
                Open(serial.PortName, baudrateIndex);
            }
            return retval;
        }