This repository has been archived by the owner on Nov 7, 2020. It is now read-only.
forked from bikrama/ymodem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYMTask.py
96 lines (73 loc) · 2.66 KB
/
YMTask.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
import math
class TaskState:
ERROR = -99
ABORTED = -1
PREPARED = 0
RUNNING = 1
FINISHED = 2
class SendTask(object):
def __init__(self):
self._state = TaskState.PREPARED
self._task_name = ""
self._task_size = 0
self._task_packets = 0
self._last_valid_packets_size = 0
self._sent_packets = 0
self._missing_sent_packets = 0
self._valid_sent_packets = 0
self._valid_sent_bytes = 0
def inc_sent_packets(self):
self._sent_packets += 1
def inc_missing_sent_packets(self):
self._missing_sent_packets += 1
def inc_valid_sent_packets(self):
self._valid_sent_packets += 1
def add_valid_sent_bytes(self, this_valid_sent_bytes):
self._valid_sent_bytes += this_valid_sent_bytes
def get_valid_sent_packets(self):
return self._valid_sent_packets
def get_valid_sent_bytes(self):
return self._valid_sent_bytes
def set_task_name(self, data_name):
self._task_name = data_name
def set_task_size(self, data_size):
self._task_size = data_size
self._task_packets = math.ceil(data_size / 1024)
self._last_valid_packets_size = data_size % 1024
class ReceiveTask(object):
def __init__(self):
self._state = TaskState.PREPARED
self._task_name = ""
self._task_size = 0
self._task_packets = 0
self._last_valid_packets_size = 0
self._received_packets = 0
self._missing_received_packets = 0
self._valid_received_packets = 0
self._valid_received_bytes = 0
def inc_received_packets(self):
self._received_packets += 1
def inc_missing_received_packets(self):
self._missing_received_packets += 1
def inc_valid_received_packets(self):
self._valid_received_packets += 1
def add_valid_received_bytes(self, this_valid_received_bytes):
self._valid_received_bytes += this_valid_received_bytes
def get_task_packets(self):
return self._task_packets
def get_last_valid_packet_size(self):
return self._last_valid_packets_size
def get_valid_received_packets(self):
return self._valid_received_packets
def get_valid_received_bytes(self):
return self._valid_received_bytes
def set_task_name(self, data_name):
self._task_name = data_name
def set_task_size(self, data_size):
self._task_size = data_size
self._task_packets = math.ceil(data_size / 1024)
self._last_valid_packets_size = data_size % 1024
def get_task_name(self):
return self._task_name
def get_task_size(self):
return self._task_size