示例#1
0
    def set_session(self, mode, message):
        self.HEADER_BYTES = 1 if len(message) <= 300 else 2
        self.PROFILE = SigfoxProfile("UPLINK", mode, self.HEADER_BYTES)
        self.MESSAGE = message
        fragmenter = Fragmenter(self.PROFILE, message)
        self.FRAGMENTS = fragmenter.fragment()

        if self.LOGGER is not None:
            self.LOGGER.FRAGMENTATION_TIME = self.LOGGER.CHRONO.read()
            self.LOGGER.debug("fragmentation time -> {}".format(self.LOGGER.FRAGMENTATION_TIME))

        if len(self.FRAGMENTS) > (2 ** self.PROFILE.M) * self.PROFILE.WINDOW_SIZE:
            raise RuleSelectionError

        self.LAST_WINDOW = (len(self.FRAGMENTS) - 1) // self.PROFILE.WINDOW_SIZE
        self.ATTEMPTS = 0
示例#2
0
	payload = bytearray(f)

# Initialize variables.
total_size = len(payload)
current_size = 0
percent = round(0, 2)
ack = None
last_ack = None
i = 0
current_window = 0
profile_uplink = Sigfox("UPLINK", "ACK ON ERROR")
profile_downlink = Sigfox("DOWNLINK", "NO ACK")
the_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Fragment the file.
fragmenter = Fragmenter(profile_uplink, payload)
fragment_list = fragmenter.fragment()

# The fragment sender MUST initialize the Attempts counter to 0 for that Rule ID and DTag value pair
# (a whole SCHC packet)
attempts = 0
retransmitting = False
fragment = None

if len(fragment_list) > (2 ** profile_uplink.M) * profile_uplink.WINDOW_SIZE:
	print(len(fragment_list))
	print((2 ** profile_uplink.M) * profile_uplink.WINDOW_SIZE)
	print("The SCHC packet cannot be fragmented in 2 ** M * WINDOW_SIZE fragments or less. A Rule ID cannot be selected.")
	# What does this mean?

# Start sending fragments.
示例#3
0
    SCHC_POST_URL = "https://us-central1-wyschc-niclabs.cloudfunctions.net/schc_receiver"
    REASSEMBLER_URL = "https://us-central1-wyschc-niclabs.cloudfunctions.net/reassemble"
    CLEANUP_URL = "https://us-central1-wyschc-niclabs.cloudfunctions.net/cleanup"

elif args.mode == 'local':
    SCHC_POST_URL = "https://localhost:5000/schc_receiver"
    REASSEMBLER_URL = "https://localhost:5000/reassembler"
    CLEANUP_URL = "https://localhost:5000/cleanup"

if args.clean or args.cleanonly:
    _ = requests.post(url=CLEANUP_URL, json={"header_bytes": header_bytes})
    if args.cleanonly:
        exit(0)

# Fragment the file.
fragmenter = Fragmenter(profile_uplink, message)
fragment_list = fragmenter.fragment()
last_window = (len(fragment_list) - 1) // window_size

# The fragment sender MUST initialize the Attempts counter to 0 for that Rule ID and DTag value pair
# (a whole SCHC packet)
attempts = 0
fragment = None

if len(fragment_list) > (2**profile_uplink.M) * window_size:
    print(len(fragment_list))
    print((2**profile_uplink.M) * window_size)
    print(
        "ERROR: The SCHC packet cannot be fragmented in 2 ** M * WINDOW_SIZE fragments or less. A Rule ID cannot be "
        "selected.")
    exit(1)
示例#4
0
# if protocol_name == "SIGFOX":
# 	protocol = Sigfox(direction, mode)

profile = Sigfox("UPLINK", "ACK ON ERROR")
MTU = profile.MTU

with open("pollito_14x14.png", "rb") as data:
    f = data.read()
    payload = bytearray(f)

print("The payload to be transmitted is: " + str(payload))

test_header = Header(profile, rule_id="RR", dtag="D", w="WW", fcn="000", c=0)
test_header.test()

fragmenter = Fragmenter(profile, payload)
fragment_list = fragmenter.fragment()

print("Fragments:")
for fragment in fragment_list:
    print(fragment)

if Fragment(profile, fragment_list[-1]).is_all_1() is True:
    print("All-1 condition satisfied")
else:
    print("All-1 condition NOT satisfied")

# print("Rebuilding message...")
#
# reassembler = Reassembler(profile, fragment_list)
# rebuild = reassembler.reassemble()