Beispiel #1
0
def d(v):
    try:
        image_path = v
        imp = image_path.rfind('.')
        extension = image_path[imp + 1:]
        if extension.lower() != 'png':
            messagebox.showerror("ERROR", "Invalid file type")
        if not os.path.exists(image_path):
            messagebox.showerror("ERROR", "File does not exists")
        else:
            l1 = dec.decode(image_path)
            if l1[0] == 'True':
                new_file_path = image_path[0:imp] + '_dec.txt'
                f = open(new_file_path, 'w')
                f.write(l1[1])
                f.close()
                response = messagebox.showinfo(
                    "Info",
                    "Image decoded successfully, New text file path: " +
                    new_file_path)
                if response == "ok":
                    r = messagebox.askyesno("Quit", "Do you wish to continue?")
                    if r == 0:
                        top3.withdraw()
                        root.quit()
                    else:
                        top3.withdraw()
                        guid()
            if l1[0] == False:
                messagebox.showerror("ERROR", "Image has no encoded data")
    except Exception as e:
        messagebox.showerror("ERROR", "\nIssue: " + str(e))
Beispiel #2
0
def test(path, msg):

    # encode(path, msg)

    txt = decode(path)
    for i in txt:
        print(i, end='')
Beispiel #3
0
def record_f_er_br(am, filename, freq_params, br_params):
    min_freq, max_freq, freq_div = freq_params
    min_br, max_br, br_div = br_params

    frequencies = [
        min_freq + (max_freq - min_freq) * i / freq_div
        for i in range(freq_div)
    ]
    bit_rates = [
        min_br + (max_br - min_br) * i / br_div for i in range(br_div)
    ]

    fr = []
    er = []
    br = []
    for freq in frequencies:
        for phy_bit_rate in bit_rates:
            print('Frequency: {}'.format(freq))
            print('bit_rate: {}'.format(phy_bit_rate))

            hamming = False
            enc.encode('bin.wav',
                       testbits, [freq],
                       phy_bit_rate,
                       hamming=hamming)
            am.playrec('bin.wav', '_bin.wav', plot_ideal_signal=False)
            ans = dec.decode('_bin.wav',
                             phy_bit_rate,
                             len(testbits), [freq],
                             hamming=hamming,
                             plot_sync=False,
                             plot_main=False)

            # print(ans)
            # print(list(tests.testbits))

            error = utils.calc_error(testbits, ans)
            # utils.plot_smooth_error_graph(tests.testbits, ans)

            if list(ans) == list(testbits):
                print("YEET!")
            else:
                print("S***E")
            print('')

            fr.append(freq)
            br.append(phy_bit_rate)
            er.append(error)

    with open(filename, 'a') as f:
        for i in zip(fr, er, br):
            f.write('{}, {}, {}\n'.format(i[0], i[1], i[2]))
Beispiel #4
0
def single_test(data, compression, freqs, coding, modulation, **kwargs):

    enc.encode(data, compression, freqs, coding, modulation, **kwargs)
    am.playrec('bin.wav', '_bin.wav')
    ans = dec.decode(len(data), compression, freqs, coding, modulation,
                     **kwargs)  # hamming plot_sync plot_main plot_conv

    error = utils.calc_error_per_freq(data, ans, freqs)

    if kwargs.get('plot_errors'):
        utils.plot_smooth_error_graph(data, ans)

    if list(ans) == list(data):
        print("YEET!")
    else:
        print("S***E")

    return ans
def main():
    data = list(str(input('Enter message')))
    encoded_packets = encode(data, encoding)
    retransmissions = 0
    received_data = []

    for encoded_packet in encoded_packets:
        copy = str(encoded_packet)
        tmp = transmit(encoded_packet, 0.8)

        while not check_control_sum(tmp):
            retransmissions += 1
            encoded_packet = BitArray(copy)
            tmp = transmit(encoded_packet, 0.8)

        received_data.append(decode(tmp))

        actual_number_of_errors(data, received_data, filepath_results)
        with open(filepath_results, 'a') as results:
            results.write(f'{retransmissions}\n')
Beispiel #6
0
def recieve(freqs, bit_rates, **kwargs):
    print('Frequencies: {}'.format(freqs))
    print('Min freq: {}, Max freq: {}'.format(min(freqs), max(freqs)))
    print('bit_rates: {}'.format(bit_rates))

    hamming = False

    t = float(input('>>Enter recording duration: '))
    no_of_bits = int(input('>>Enter number of bits: '))
    input('>>Press enter to start')
    am.record('_bin.wav', t)
    am.sd.wait()

    ans = dec.decode('_bin.wav',
                     bit_rates,
                     no_of_bits,
                     freqs,
                     hamming=hamming,
                     plot_sync=False,
                     plot_main=False,
                     plot_conv=False)

    return ans
            data["vertical_accuracy"] = msg.vert_acc

        data["course"] = msg.course if msg.course != 0.0 else None
        data["speed"] = msg.speed if msg.speed != 0.0 else None
        data["floor"] = msg.floor if msg.floor != 0 else None
    elif msg.message_type == SensorData.MESSAGE_TYPE_BATTERY:
        data["bat_level"] = msg.bat_level
        data["bat_state"] = get_enum_str(msg, "bat_state", msg.bat_state)
    else:
        raise NotImplementedError("found unknown message type")

    return json.dumps(data)


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: ./decode_sensor_data.py input.pb output.json")
        exit(1)

    input_fn = sys.argv[1]
    output_fn = sys.argv[2]

    if not os.path.exists(input_fn):
        print("Error: input file does not exist:", input_fn)
        exit(1)
    if os.path.exists(output_fn):
        print("Error: output file exists:", output_fn)
        exit(1)

    write_messages(decode(input_fn, SensorData), msg_to_json, output_fn)
Beispiel #8
0
def msg_to_json(msg):
    """ Create JSON from message """
    data = {}

    data["epoch"] = str(datetime.fromtimestamp(msg.epoch))

    if msg.prompt_type == PromptResponse.PROMPT_TYPE_ACTIVITY_QUERY:
        data["label"] = msg.user_activity_label
    else:
        raise NotImplementedError("found unknown message type")

    return json.dumps(data)


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: ./decode_responses.py input.pb output.json")
        exit(1)

    input_fn = sys.argv[1]
    output_fn = sys.argv[2]

    if not os.path.exists(input_fn):
        print("Error: input file does not exist:", input_fn)
        exit(1)
    if os.path.exists(output_fn):
        print("Error: output file exists:", output_fn)
        exit(1)

    write_messages(decode(input_fn, PromptResponse), msg_to_json, output_fn)
Beispiel #9
0
def main(argv):
    plot_data(decode(FLAGS.input, SensorData))
Beispiel #10
0
from arrived import simple_encoding, noisy_simple_received_message, complex_encoding, noisy_complex_received
from Lagrange import make_vandermonde_matrix
from decoding import decode, retrieve_message

#print(simple_encoding)
#print("***********")
vandermonde, trimmed_received = make_vandermonde_matrix(noisy_complex_received)
#print("****")
#print(trimmed_received)
#print("*******")
original_poly = decode(vandermonde, trimmed_received)
#print(original_poly)
original_message = retrieve_message(original_poly)

print(original_message)


Beispiel #11
0
                                                   [pt_prev, pt, pt, pt_prev]),
                                               altitude_mode='absolute')
                p.begin = ts_prev
                p.end = ts
                f.append(p)

            i += 1
            pt_prev = pt
            ts_prev = ts

    with open(output_filename, "w") as f:
        f.write(k.to_string(prettyprint=True))


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: ./kml.py input.pb output.kml")
        exit(1)

    input_fn = sys.argv[1]
    output_fn = sys.argv[2]

    if not os.path.exists(input_fn):
        print("Error: input file does not exist:", input_fn)
        exit(1)
    if os.path.exists(output_fn):
        print("Error: output file exists:", output_fn)
        exit(1)

    write_kml(decode(input_fn, SensorData), output_fn)
Beispiel #12
0
from encoding import encode
from decoding import decode
from additional import create_argument_parser

parser = create_argument_parser()
args = parser.parse_args()

if not args.encode is None:
    encode(args.encode[0], args.encode[1], args.encode[2],
           args.bit_count)
elif not args.decode is None:
    decode(args.decode[0], args.decode[1])
else:
    print("You don't specified neither -e nor -d option")
    exit(1)
Beispiel #13
0
from image_process_try import return_to_ophir
#from image_processing_advanced import return_to_ophir
from encoding import encode
from decoding import decode, decode_raw
from color_state import State
import time
import os
import sys

if __name__ == '__main__':
    states = return_to_ophir()  #.split(State(2, 2, 2, 2, 2))
    #states = [g for g in states if len(g) > 0]

    text = decode(states)  # decode(states[0])
    f = open("output.txt", "w")
    f.write(text)
    f.close()
    with open("big.txt", "w") as f:
        f.write(decode(states[1]))

    with open("output.bmp", "wb") as f:
        f.write(decode_raw(states[2]))
Beispiel #14
0
from encoding import encode
from decoding import decode

DS_FACT = 2
BLK_SIZE = 8

for q in [6]:
    filename = 'data/videorecord_dct_q' + str(q) + '.txt'
    print('Encoding file: ' + filename)
    encode(filename,
           25,
           writeToFile=True,
           N=DS_FACT,
           BLK_SIZE=BLK_SIZE,
           QUAL_FACT=q)
    print('Decoding file: ' + filename)
    decode(filename, N=DS_FACT, BLK_SIZE=BLK_SIZE, QUAL_FACT=q)