-
Notifications
You must be signed in to change notification settings - Fork 2
/
threads.py
99 lines (82 loc) · 3.44 KB
/
threads.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
# coding=utf-8
from Queue import Queue
from twisted.python import log
import misc
from gs_interface import GroundStationInterface, OperativeUDPThreadReceive
from gs_interface import OperativeUDPThreadSend
from gs_interface import OperativeTCPThread, OperativeKISSThread
"""
Copyright 2016 Samuel Góngora García
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
:Author:
Samuel Góngora García ([email protected])
"""
__author__ = '[email protected]'
class Threads(object):
workerUDPThreadSend = None
def __init__(self, CONNECTION_INFO, gsi):
self.UDPSignal = True
self.serialSignal = True
self.TCPSignal = True
self.tcp_queue = Queue()
self.udp_queue = Queue()
self.serial_queue = Queue()
self.CONNECTION_INFO = misc.get_data_local_file(
settingsFile='.settings')
self.gsi = gsi
def runUDPThreadReceive(self):
self.CONNECTION_INFO = misc.get_data_local_file(
settingsFile='.settings')
self.workerUDPThreadReceive = OperativeUDPThreadReceive(
self.udp_queue, self.sendData, self.UDPSignal, self.CONNECTION_INFO
)
self.workerUDPThreadReceive.start()
def stopUDPThreadReceive(self):
self.workerUDPThreadReceive.stop()
def runUDPThreadSend(self):
self.CONNECTION_INFO = misc.get_data_local_file(
settingsFile='.settings')
self.workerUDPThreadSend = OperativeUDPThreadSend(self.CONNECTION_INFO)
def UDPThreadSend(self, message):
if not self.workerUDPThreadSend:
log.msg(
'>>> No UDP Thread Send, dropping message, msg = ' + str(
message
)
)
else:
self.workerUDPThreadSend.send(message)
def runKISSThreadReceive(self):
self.CONNECTION_INFO = misc.get_data_local_file(
settingsFile='.settings')
self.workerKISSThread = OperativeKISSThread(self.serial_queue,
self.sendData,
self.serialSignal,
self.CONNECTION_INFO)
self.workerKISSThread.start()
def stopKISSThread(self):
self.workerKISSThread.stop()
def KISSThreadSend(self, message):
self.workerKISSThread.send(message)
# To-do
def runTCPThread(self):
self.CONNECTION_INFO = misc.get_data_local_file(
settingsFile='.settings')
self.workerTCPThread = OperativeTCPThread(self.tcp_queue,
self.sendData,
self.TCPSignal,
self.CONNECTION_INFO)
self.workerTCPThread.start()
# Stop TCP thread
def stopTCPThread(self):
self.workerTCPThread.stop()
def sendData(self, result):
self.gsi._manageFrame(result)