kopia lustrzana https://github.com/sq5t/ic-705-tools
89 wiersze
2.5 KiB
Python
Executable File
89 wiersze
2.5 KiB
Python
Executable File
#!/usr/bin/env python3.6
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
# Copyright 2008,2009 Free Software Foundation, Inc.
|
|
#
|
|
# This application 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, or (at your option)
|
|
# any later version.
|
|
#
|
|
# This application 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, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
#
|
|
|
|
import socket
|
|
import struct
|
|
|
|
# Function to convert
|
|
def listToString(s):
|
|
|
|
# initialize an empty string
|
|
str1 = " "
|
|
|
|
# return string
|
|
return (str1.join(s))
|
|
|
|
# ip address of IC-705 connected to WiFi
|
|
tcp_ip = '10.155.0.157'
|
|
# standard tcp port for this transsmision
|
|
tcp_port = 60000
|
|
|
|
# open test.jpg
|
|
f = open("test.jpg", 'rb')
|
|
f.seek(0,2)
|
|
file_size = f.tell().to_bytes(3, byteorder='big')
|
|
f.seek(0)
|
|
|
|
command = b'\x01\x00\x00\x00\x00\x04\x00\x00\x00' # command for file transfer to radio
|
|
cmd_ack = b'\x01\x01\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00' # command acknowledge
|
|
rcv_ack = b'\x01\x02\x00\x00\x00\x02\x00\x00\x04\x00' # receive acknowledge
|
|
send_next = b'\x01\x03\x00\x00\x04\x03\x00\x00\x01' # header of next part of picture
|
|
send_last = b'\x01\x03\x00\x00\x00\x74\x00\x00\x01' # header of last part of picture
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.connect((tcp_ip, tcp_port))
|
|
message_tmp = command + file_size
|
|
s.send(message_tmp)
|
|
s.setblocking(1)
|
|
|
|
data = s.recv(22)
|
|
answer = cmd_ack + rcv_ack
|
|
|
|
if(data == cmd_ack):
|
|
data = s.recv(22)
|
|
if(data != rcv_ack):
|
|
print("No 'receive ack' received from radio")
|
|
exit()
|
|
elif(data != answer):
|
|
if(data != cmd_ack):
|
|
print("No 'command ack' received from radio")
|
|
print(data)
|
|
exit()
|
|
|
|
while True:
|
|
piece = f.read(1024)
|
|
if not piece:
|
|
break
|
|
piece_size = len(piece).to_bytes(2, byteorder='big')
|
|
if(len(piece)==1024):
|
|
to_send = send_next + piece_size + piece
|
|
s.send(to_send)
|
|
data = s.recv(10)
|
|
while (len(data) == 0):
|
|
data = s.recv(10)
|
|
if(data != rcv_ack):
|
|
print("Error, 'receive ack' not received.")
|
|
exit()
|
|
else:
|
|
to_send = send_last + piece_size + piece
|
|
s.send(to_send)
|
|
f.close()
|
|
s.close()
|