-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubscriber.py
More file actions
32 lines (24 loc) · 1.36 KB
/
Subscriber.py
File metadata and controls
32 lines (24 loc) · 1.36 KB
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
# David L. Flanagan, Mike Wilson, Jugal Lodaya, Jaidev Ramakrishna
# May 14, 2016
# Publisher.py
# Data structure representing a publisher on the central node.
from Command import Command
import SMPCentralNodeRequestHandler
class Subscriber(object):
"""Data structure representing a single subscriber in the CentralNode."""
def __init__(self, request, client_address, sensor_type=0):
"""Public constructor sets up all important variables."""
self.Key = client_address
self.Socket = request[1]
self.SensorType = sensor_type
self.TimeoutCount = 0
def SendCommand(self, cmd_code, pub_name):
"""Sends a command to the subscriber over the network. """
# Get the transaction id and create the command structure.
TxId = SMPCentralNodeRequestHandler.GetNextTransactionID()
command = Command().CreateFromParams(cmd_code, TxId, self.SensorType, pub_name)
#log the transaction, the Key is the client address in this case.
SMPCentralNodeRequestHandler.StoreTransaction(TxId, command, self.Socket, self.Key)
print "Sending: " + command.GetCommandString() + " <" + str(command) + ">"
# In a happy accident the subscribers key is actually the client address, so we just pass that into the send call.
self.Socket.sendto(command.GetPacket(), self.Key)