搭建基于GPS (NMEA)的NTP卫星校时服务器

Synopsis

Address: 127.127.20.u
Reference ID: GPS
Driver ID: GPS_NMEA
Serial Port: /dev/gpsu; 4800 – 115200 bps, 8-bits, no parity
Serial Port: /dev/gpsppsu; for just the PPS signal (this is tried first for PPS, before /dev/gpsu)
Serial Port: /dev/gpsu; symlink to server:port (for nmead)
Features: tty_clk

Description

This driver supports GPS receivers with the $GPRMC, $GPGLL, $GPGGA, $GPZDA and $GPZDG NMEA sentences by default.  Note that Accord’s custom NMEA sentence $GPZDG reports using the GPS timescale, while the rest of the sentences report UTC.  The difference between the two is a whole number of seconds which increases with each leap second insertion in UTC.  To avoid problems mixing UTC and GPS timescales, the driver disables processing of UTC sentences once $GPZDG is received.

The driver expects the receiver to be set up to transmit at least one supported sentence every second.

The accuracy depends on the receiver used. Inexpensive GPS models are available with a claimed PPS signal accuracy of 1 μs or better relative to the broadcast signal. However, in most cases the actual accuracy is limited by the precision of the timecode and the latencies of the serial interface and operating system.

If the Operating System supports PPSAPI (RFC 2783), fudge flag1 1 enables its use.

The various GPS sentences that this driver recognises look like this:
(others quietly ignored)

SentenceVendor
$GPRMC,UTC,POS_STAT,LAT,LAT_REF,LON,LON_REF,SPD,HDG,DATE,MAG_VAR,MAG_REF*CS<cr><lf>
$GPGLL,LAT,LAT_REF,LON,LON_REF,UTC,POS_STAT*CS<cr><lf>
$GPGGA,UTC,LAT,LAT_REF,LON,LON_REF,FIX_MODE,SAT_USED,HDOP,ALT,ALT_UNIT,GEO,G_UNIT,D_AGE,D_REF*CS<cr><lf>
$GPZDA,UTC,DD,MM,YYYY,TH,TM,*CS<cr><lf>
$GPZDG,GPSTIME,DD,MM,YYYY,AA.BB,V*CS<cr><lf>Accord
SymbolMeaning and Format
UTCTime of day on UTC timescale. Hours, minutes and seconds [fraction (opt.)]. (hhmmss[.fff])
POS_STATPosition status. (A = Data valid, V = Data invalid)
LATLatitude (llll.ll)
LAT_REFLatitude direction. (N = North, S = South)
LONLongitude (yyyyy.yy)
LON_REFLongitude direction (E = East, W = West)
SPDSpeed over ground. (knots) (x.x)
HDGHeading/track made good (degrees True) (x.x)
DATEDate (ddmmyy)
MAG_VARMagnetic variation (degrees) (x.x)
MAG_REFMagnetic variation (E = East, W = West)
FIX_MODEPosition Fix Mode (0 = Invalid, >0 = Valid)
SAT_USEDNumber of Satellites used in solution
HDOPHorizontal Dilution of Precision
ALTAntenna Altitude
ALT_UNITAltitude Units (Metres/Feet)
GEOGeoid/Elipsoid separation
G_UNITGeoid units (M/F)
D_AGEAge of last DGPS Fix
D_REFReference ID of DGPS station
GPSTIMETime of day on GPS timescale. Hours, minutes and seconds [fraction (opt.)]. (hhmmss[.f])
DDDay of the month (1-31)
MMMonth of the year (1-12)
YYYYYear
AA.BBDenotes the signal strength (should be < 05.00)
VGPS sync status
   ‘0’ => INVALID time,
   ‘1’ => accuracy of +/- 20ms,
   ‘2’ => accuracy of +/- 100ns
CS Checksum
<cr><lf>Sentence terminator.

The ‘mode’ byte

Specific GPS sentences and bitrates may be selected by setting bits of the ‘mode’ in the server configuration line:
  server 127.127.20.x mode X

BitDecimalHexMeaning
011process $GPMRC
122process $GPGGA
244process $GPGLL
388process $GPZDA or $GPZDG
4-600linespeed 4800 bps
160x10linespeed 9600 bps
320x20linespeed 19200 bps
480x30linespeed 38400 bps
640x40linespeed 57600 bps
800x50linespeed 115200 bps
71280x80Write the sub-second fraction of the receive time stamp to the clockstat file for all recognised NMEA sentences. This can be used to get a useful value for fudge time2.
Caveat: This will fill your clockstat file rather fast. Use it only temporarily to get the numbers for the NMEA sentence of your choice.
82560x100process $PGRMF
9-150xFE00reserved – leave 0
16655360x10000Append extra statistics to the clockstats line. Details below.

The default (mode 0) is to process all supported sentences at a linespeed of 4800 bps, which results in the first one received and recognised in each cycle being used.  If only specific sentences should be recognised, then the mode byte must be chosen to enable only the selected ones.  Multiple sentences may be selected by adding their mode bit values, but of those enabled still only the first received sentence in a cycle will be used.  Using more than one sentence per cycle is impossible, because

  • there is only fudge time2 available to compensate for transmission delays but every sentence would need a different one and
  • using more than one sentence per cycle overstuffs the internal data filters.

The driver uses 4800 bits per second by default, but faster bitrates can be selected using bits 4 to 6 of the mode field.

Caveat: Using higher line speeds does not necessarily increase the precision of the timing device.  Higher line speeds are not necessarily helpful for the NMEA driver, either.  They can be used to accomodate for an amount of data that does not fit into a 1-second cycle at 4800 bps, but high-speed high-volume NMEA data is likely to cause trouble with the serial line driver since NMEA supports no protocol handshake.  Any device that is exclusively used for time synchronisation purposes should be configured to transmit the relevant data only, e.g. one $GPRMC or $GPZDA per second, at a linespeed of 4800 bps or 9600 bps.

Monitor Data

The last GPS sentence that is accepted or rejected is written to the clockstats file and available with ntpq -c clockvar. (Logging the rejected sentences lets you see/debug why they were rejected.) Filtered sentences are not logged.

If the 0x10000 mode bit is on and clockstats is enabled, several extra counters will be appended to the NMEA sentence that gets logged. For example:

56299 76876.691 127.127.20.20 $GPGGA,212116.000,3726.0785,N,12212.2605,W,1,05,2.0,17.0,M,-25.7,M,,0000*5C  228 64 0 0 64 0
ColumnSampleMeaning
156299MJD
276876.691Time of day in seconds
3127.127.20.20IP Address from server config line
4$GPGGA,…0*5CNMEA Sentence
5228Number of sentences received
664Number of sentences accepted and used for timekeeping
70Number of sentences rejected because they were marked invalid (poor signal)
80Number of sentences rejected because of bad checksum or invalid date/time
964Number of sentences filtered by mode bits or same second
100Number of PPS pulses used, overrides NMEA sentences

Sentences like $GPGSV that don’t contain the time will get counted in the total but otherwise ignored.

Configuring NMEA Refclocks might give further useful hints for specific hardware devices that exhibit strange or curious behaviour.

To make a specific setting, select the corresponding decimal values from the mode byte table, add them all together and enter the resulting decimal value into the clock configuration line.

Setting up the Garmin GPS-25XL

Switch off all output with by sending it the following string.

"$PGRMO,,2<cr><lf>"

Now switch only $GPRMC on by sending it the following string.

"$PGRMO,GPRMC,1<cr><lf>"

On some systems the PPS signal isn’t switched on by default. It can be switched on by sending the following string.

"$PGRMC,,,,,,,,,,,,2<cr><lf>"

Fudge Factors

time1 time Specifies the PPS time offset calibration factor, in seconds and fraction, with default 0.0. time2 time Specifies the serial end of line time offset calibration factor, in seconds and fraction, with default 0.0. stratum number Specifies the driver stratum, in decimal from 0 to 15, with default 0. refid string Specifies the driver reference identifier, an ASCII string from one to four characters, with default GPS. flag1 0 | 1 Disable PPS signal processing if 0 (default); enable PPS signal processing if 1. flag2 0 | 1 If PPS signal processing is enabled, capture the pulse on the rising edge if 0 (default); capture on the falling edge if 1. flag3 0 | 1 If PPS signal processing is enabled, use the ntpd clock discipline if 0 (default); use the kernel discipline if 1. flag4 0 | 1 Obscures location in timecode: 0 for disable (default), 1 for enable.

Additional Information

flag1, flag2, and flag3 are ignored under Windows.

原文链接:https://www.eecis.udel.edu/~mills/ntp/html/drivers/driver20.html

Win10恢复模式cmd下卸载驱动

I ran into following error with pnputil -e on the latest Windows 10 repair console:

No published driver packages were found on the system

I had to use dism

Listing drivers:

dism /image:c:\ /get-drivers

Removing a driver:

dism /image:c:\ /remove-driver /driver:oem#.inf

Use list vol inside diskpart to get the assigned drive letter of your windows partition and replace /image:c:\ with it

原文链接:https://superuser.com/questions/621604/how-to-uninstall-a-driver-from-recovery-console

用subprocess.Popen()解决popen中文报错

Python subprocess.Popen() is one of best way to call external application in python. It has two main advantages:

1.It can return the output of child program, which is better than os.system().

2.It can return the output of child program with byte type, which is better an os.popen().

In this tutorial, we will introduce python beginners how to use this function correctly and get the output of child program.

Preliminary

We import os library first.

import os

Create a command line

We will use subprocess.Popen() to run other applications, a command line (cmd) should be created.

For example:

cmd = r'c:\aria2\aria2c.exe -d f:\ -m 5 -o test.pdf https://example.com/test.pdf'

In this tutorial, we will execute aria2c.exe by python.

Execute a Child Program

We can use subprocess.Popen() to run cmd like below:

p1=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)

Here we set stdout=subprocess.PIPE, which means we will get the cmd output.

Get child program output

subprocess.Popen() will return the output of child program, we can read this output line by line.

    msg_content = ''
    for line in p1.stdout:
        print(line)
        l = line.decode(encoding="utf-8", errors="ignore")
        msg_content += l
    p1.wait()
    print(msg_content)

p1.wait() is very important, which will block python main process to read full output of child program.

Run this code, you may get the result.

python subprocess.popen() get child program output

From the result, we can find subprocess.Popen() will return the output of cmd with byte mode, we can convert it to string with encoding utf-8.

l = line.decode(encoding="utf-8", errors="ignore")

This will avoid UnicodeDecodeError.

原文链接:https://www.tutorialexample.com/implement-python-subprocess-popen-execute-an-external-command-and-get-output/

阻止Network Manager修改resolv.conf

I do not want network manager to add DNS servers received from DHCP to my /etc/resolv.conf.

When configuring from GUI/Connections/IPV4 and choose the method Automatic (address only) it still adds DNS servers received via DHCP.

Is it possible to do it per connection (specific ssid ?)

Answer:

One way to stop Network Manager from adding dns-servers to /etc/resolv.conf file is to do this:

First open the nm conf file /etc/NetworkManager/NetworkManager.conf:

sudo vim /etc/NetworkManager/NetworkManager.conf

And add this to the [main] section:

dns=none

Save and exit.

原文链接: https://askubuntu.com/questions/623940/network-manager-how-to-stop-nm-updating-etc-resolv-conf

VMware View 5.1 and SSL Certificate Replacement

The procedure to replace SSL certificates has changed in recently released VMware View 5.1 and differs from 5.0 or earlier versions. The main difference is that native Windows certificate store is used. Also it is now necessary to replace or at least to verify self signed certificates otherwise the View infrastructure will not work properly.
Which servers need to replace the certificates? View Connection Managers, Security servers and View Composer. Also vCenter certificate must be replaced or validated.
Although the certificate replacement procedure is described in the manual, the description is very brief and it took me some time to figure it out. I also found an existing blog post which takes different angle here: http://my-virt.alfadir.net/2012/05/generate-view-5-1-certificat/.

The Setup

My lab configuration is following. View Composer is installed together with vCenter. I have two View Connection Managers; one for internal connections and one for external internet connections. I do not use Security server as I use port forwarding to the external View Connection Manager. All servers are in the domain with Enterprise CA which uses self signed certificate.

View Composer Certificate

My View Composer server is coexisting with vCenter so I did not need to generate new certificate. I just imported the vCenter certificate from C:\ProgramData\VMware\VMware VirtualCenter\SSL into the local Windows certificate (Personal) store via MMC Certificates Snap-in.

Select the .pfx file which contains both private key and the certificate.

Now we have to stop the View Composer process and run SviConfig command to replace the certificate:

C:\Program Files (x86)\VMware\VMware View Composer>SviConfig.exe -operation=replacecertificate -delete=false
and select the new certificate.

Start the View Composer process again and check the status in the View Administrator.

View Connection Servers

Here we have to generate the certificates. To do this I am again using the Certificates Snap-in. However prior to that I needed to give both of my Connection Server access to Web Server certificate template.
On my CA open the Certificate Templates Management Console Snap-in and open properties of Web Server certificate template.

Open the security tab and add both View Connection computers and give them read, write and enroll permissions.

Now we can go to each Connection Server Certificates Snap-in and right click, select All Tasks and Request New Certificate.

Select Active Directory Enrollment Policy and Web Server certificate template.

Now we have to add FQDN and additional info to the certificate. Click the More information is required … link.
Type in the Common name (FQDN), Country, Locality, Organization and any other info that will be visible inside the certificate. If your Connection server uses different internal (viewcs2.fojta.com) and public (public.url.com) Fully Qualified Domain Names add both and do the same for the Type: DNS field. The end result should look like this:

And do not forget to make private key exportable in the Private Key tab / Key options.

Click enroll and finish.
Now we should see the newly created certificate. Last thing we need to do is to change the certificate Friendly Name to vdm. This can be done in the certificate properties. Also we have to rename the original certificate (vdm.old)

Once this is done we can restart the View services.
Repeat for all other View Connection servers and check the result in the View Administrator.

View Clients

As I said at the beginning my CA uses self signed certificate so I have to make sure all the non-domain PCs I use to connect to my View desktops imported the CA Root certificate into the Trusted Root Certification Authorities store.

原文地址: https://fojta.wordpress.com/2012/05/27/vmware-view-5-1-and-ssl-certificate-replacement/