forked from loughkb/IC-7300-time-sync
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Set_IC7300_time.py
99 lines (82 loc) · 3.14 KB
/
Set_IC7300_time.py
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
#!/usr/bin/env python3
''' Icom IC-7300 Time Synchronization
This program sets the clock of the Icom IC-7300 radio to the current time
of the computer. See "User Configurations" section below for program
options that must be set. This script requires the pyserial module. Add
this dependency with the `py -m pip install pyserial` command.
Copyright (C) 2020 Claus Niesen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import serial
import time
### User Configurations ###
#
# Baud rate for the CI-V interface of the Icom IC-7300.
#baudrate = 9600
baudrate = 115200
#
# Serial port of the computer on which the CI-V interface of the radio is connected.
#serialport = '/dev/ttyUSB0' # for Linux
#serialport = 'COM3' # for Windows
serialport = 'COM4'
#
# Swap the CLOCK and UTC times of the Icom IC-7300.
#swapclock = False # display local time on CLOCK
#swapclock = True # display UTC time on CLOCK (the UTC display will show local time)
swapclock = True
#
### end of user configurations ###
preamble = 'FEFE94E01A0500'
setDateCommand = '94'
setTimeCommand = '95'
setUtcOffsetCommand = '96'
postamble = 'FD'
responseOk = 'FEFEE094FBFD'
ser = serial.Serial(serialport, baudrate)
ser.timeout = 5
if (swapclock):
def getTime():
return time.gmtime()
else:
def getTime():
return time.localtime()
def sendCommand(command, data):
command = preamble + command + data + postamble
ser.write(bytes.fromhex(command))
ser.read_until(bytes.fromhex(postamble)) # the send command (why, oh why?)
response = ser.read_until(bytes.fromhex(postamble))
if (response != bytes.fromhex(responseOk)):
exit('Error: Command ' + command + ' did not receive OK from radio.')
print('Setting Icom clock to', getTime().tm_zone, '. This may take up to 1 minute to complete.')
# Set UTC offset on radio
if(time.localtime().tm_gmtoff < 0):
offsetData = time.strftime('%H%M', time.gmtime(time.localtime().tm_gmtoff * -1))
if (swapclock):
offsetData += '00'
else:
offsetData += '01'
else :
offsetData = time.strftime('%H%M', time.gmtime(time.localtime().tm_gmtoff))
if (swapclock):
offsetData += '01'
else:
offsetData += '00'
sendCommand(setUtcOffsetCommand, offsetData)
# Set date on radio
dateData = time.strftime('%Y%m%d', getTime())
sendCommand(setDateCommand, dateData)
# Set time on radio (top of minute)
while(time.localtime().tm_sec != 0):
pass
timeData = time.strftime('%H%M', getTime())
sendCommand(setTimeCommand, timeData)
ser.close()