本文整理汇总了Python中fysom.Fysom.enable方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.enable方法的具体用法?Python Fysom.enable怎么用?Python Fysom.enable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fysom.Fysom
的用法示例。
在下文中一共展示了Fysom.enable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainThread
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import enable [as 别名]
class MainThread(threading.Thread):
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, verbose=None):
super(MainThread, self).__init__(group, target, name, args, kwargs, verbose)
# load settings file
self.cfg = get_settings()
# this is used to stop the arming thread
self.pill2kill = None
# keep a buzzer object to stop it from every function. same for the receiver433
self.buzzer = None
# prepare a queue to share data between this threads and other thread
self.shared_queue_keyborad = Queue.Queue()
self.shared_queue_rfid_reader = Queue.Queue()
self.shared_queue_433_receiver = Queue.Queue()
self.shared_queue_message_from_api = Queue.Queue()
# create an object to manage the screen
try:
self.screen_manager = AdafruitScreenManager()
except IOError:
raise Exception("No connection with the screen")
# create an object to manage the arduino
self.arduino = ArduinoManager()
try:
self.arduino.ping()
except IOError:
self.screen_manager.set_arduino_connection_missing()
sys.exit(0)
# run the keypad thread
self.keypad_thread = MatrixKeypadManager(self.shared_queue_keyborad)
self.keypad_thread.start()
# run the thread that handle RFID
rfid = RFIDrc522Manager(self.shared_queue_rfid_reader)
rfid.start()
# keep 433 receiver thread object in mind
self.receiver443 = None
# create the flask rest api
app = Flask(__name__)
flask_api = FlaskAPI(app, self.shared_queue_message_from_api, self)
flask_api.start()
# Save a buffer where we put each typed number
self.code_buffer = ""
self.last_state = "disabled"
# create the state machine
self.fsm = Fysom({'initial': self._get_initial_state(),
'events': [
{'name': 'arm', 'src': 'disabled', 'dst': 'arming'},
{'name': 'enable', 'src': 'arming', 'dst': 'enabled'},
{'name': 'intrusion', 'src': 'enabled', 'dst': 'waiting_code'},
{'name': 'alarm', 'src': 'waiting_code', 'dst': 'alarming'},
{'name': 'disable', 'src': ['arming', 'enabled', 'waiting_code', 'alarming'],
'dst': 'disabled'}],
'callbacks': {
'ondisabled': self.ondisabled,
'onarming': self.onarming,
'onenabled': self.onenabled,
'onwaiting_code': self.onwaiting_code,
'onalarming': self.onalarming}
})
def run(self):
print "Run main thread"
while True:
if not self.shared_queue_keyborad.empty():
val = self.shared_queue_keyborad.get()
print "Key received from keypad: ", val
if val == "D":
self.screen_manager.switch_light()
elif val == "C":
# cancel only if we were in arming status
if self.fsm.current == "arming":
self.fsm.disable()
else:
# we add a star to the screen
self.screen_manager.add_star()
# add the value to the buffer
self.code_buffer += str(val)
# if we have 4 number we can test the code
if len(self.code_buffer) == 4:
self._test_pin_code()
self.code_buffer = ""
if not self.shared_queue_rfid_reader.empty():
val = self.shared_queue_rfid_reader.get()
print "Received UID from RFID ", val
self._test_rfid_uid(val)
if not self.shared_queue_433_receiver.empty():
val = self.shared_queue_433_receiver.get()
print "Received UID from 433 receiver ", val
self._test_433_uid(val)
time.sleep(0.1)
#.........这里部分代码省略.........
示例2: gemHandler
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import enable [as 别名]
class gemHandler(secsHandler):
"""Baseclass for creating Host/Equipment models. This layer contains GEM functionality. Inherit from this class and override required functions.
:param address: IP address of remote host
:type address: string
:param port: TCP port of remote host
:type port: integer
:param active: Is the connection active (*True*) or passive (*False*)
:type active: boolean
:param session_id: session / device ID to use for connection
:type session_id: integer
:param name: Name of the underlying configuration
:type name: string
:param event_handler: object for event handling
:type event_handler: :class:`secsgem.common.EventHandler`
:param custom_connection_handler: object for connection handling (ie multi server)
:type custom_connection_handler: :class:`secsgem.hsmsConnections.HsmsMultiPassiveServer`
"""
ceids = secsHandler.ceids
"""Dictionary of available collection events, CEID is the key
:param name: Name of the data value
:type name: string
:param CEID: Collection event the data value is used for
:type CEID: integer
"""
dvs = secsHandler.dvs
"""Dictionary of available data values, DVID is the key
:param name: Name of the collection event
:type name: string
:param dv: Data values available for collection event
:type dv: list of integers
"""
alarms = secsHandler.alarms
"""Dictionary of available alarms, ALID is the key
:param alarmText: Description of the alarm
:type alarmText: string
:param ceidOn: Collection event for activated alarm
:type ceidOn: integer
:param ceidOff: Collection event for deactivated alarm
:type ceidOff: integer
"""
rcmds = secsHandler.rcmds
"""Dictionary of available remote commands, command is the key
:param params: description of the parameters
:type params: list of dictionary
:param CEID: Collection events the remote command uses
:type CEID: list of integers
"""
def __init__(self, address, port, active, session_id, name, event_handler=None, custom_connection_handler=None):
secsHandler.__init__(self, address, port, active, session_id, name, event_handler, custom_connection_handler)
self.logger = logging.getLogger(self.__module__ + "." + self.__class__.__name__)
# not going to HOST_INITIATED_CONNECT because fysom doesn't support two states. but there is a transistion to get out of EQUIPMENT_INITIATED_CONNECT when the HOST_INITIATED_CONNECT happens
self.communicationState = Fysom({
'initial': 'DISABLED', # 1
'events': [
{'name': 'enable', 'src': 'DISABLED', 'dst': 'ENABLED'}, # 2
{'name': 'disable', 'src': ['ENABLED', 'NOT_COMMUNICATING', 'COMMUNICATING', 'EQUIPMENT_INITIATED_CONNECT', 'WAIT_DELAY', 'WAIT_CRA', "HOST_INITIATED_CONNECT", "WAIT_CR_FROM_HOST"], 'dst': 'DISABLED'}, # 3
{'name': 'select', 'src': 'NOT_COMMUNICATING', 'dst': 'EQUIPMENT_INITIATED_CONNECT'}, # 5
{'name': 'communicationreqfail', 'src': 'WAIT_CRA', 'dst': 'WAIT_DELAY'}, # 6
{'name': 'delayexpired', 'src': 'WAIT_DELAY', 'dst': 'WAIT_CRA'}, # 7
{'name': 'messagereceived', 'src': 'WAIT_DELAY', 'dst': 'WAIT_CRA'}, # 8
{'name': 's1f14received', 'src': 'WAIT_CRA', 'dst': 'COMMUNICATING'}, # 9
{'name': 'communicationfail', 'src': 'COMMUNICATING', 'dst': 'NOT_COMMUNICATING'}, # 14
{'name': 's1f13received', 'src': ['WAIT_CR_FROM_HOST', 'WAIT_DELAY', 'WAIT_CRA'], 'dst': 'COMMUNICATING'}, # 15 (WAIT_CR_FROM_HOST is running in background - AND state - so if s1f13 is received we go all communicating)
],
'callbacks': {
'onWAIT_CRA': self._onStateWaitCRA,
'onWAIT_DELAY': self._onStateWaitDelay,
'onleaveWAIT_CRA': self._onStateLeaveWaitCRA,
'onleaveWAIT_DELAY': self._onStateLeaveWaitDelay,
'onCOMMUNICATING': self._onStateCommunicating,
# 'onselect': self.onStateSelect,
},
'autoforward': [
{'src': 'ENABLED', 'dst': 'NOT_COMMUNICATING'}, # 4
{'src': 'EQUIPMENT_INITIATED_CONNECT', 'dst': 'WAIT_CRA'}, # 5
{'src': 'HOST_INITIATED_CONNECT', 'dst': 'WAIT_CR_FROM_HOST'}, # 10
]
})
self.waitCRATimer = None
self.commDelayTimer = None
self.commDelayTimeout = 10
self.reportIDCounter = 1000
self.reportSubscriptions = {}
self.registerCallback(1, 1, self.S1F1Handler)
#.........这里部分代码省略.........