def main(a, queue): try: import multiprocessing import threading from Webserver import WebSocketHandler from Webserver import MainHandler from Participant import Participant from Bulletin import Bulletin from Operator import Operator from Service import Service from Manufacturer import Manufacturer import Pump import time import json import datetime import RPi.GPIO as GPIO from PIL import Image import pygame from multiprocessing import Process, Queue import signal from random import randint import RFID GPIO.setmode(GPIO.BOARD) # CONSTANTS PIMP_GPIO = 13 #gpio 27 OUT_MANUFACTURER = 11 #gpio 17 OUT_SERVICE = 33 #gpio 13 ALARM_MANUFACTURER = 16 # gpio 23 ALARM_OPERATOR = 7 #gpio 4 ALARM_SERVICE = 38 #gpio 20 REPAIR_ASSET_GPIO = 40 # gpio 21 BREAK_ASSET_MANUALY_GPIO = 18 #gpio 24 SERVICE_BULLETIN_MANUFACTURER = 31 #gpio 6v SERVICE_BULLETIN_MANUFACTURER_MEASURE = 35 #gpio 19 SERVICE_BULLETIN_OPERATOR = 12 #gpio 18 SERVICE_BULLETIN_OPERATOR_MEASURRE = 15 #gpio 22 GPIO_to_repair_for_demo = 40 # gpio 21 # CATALOG OF RFID CHIPS' IDs THAT ARE ASSIGNED TO THE ASSETS IN THE FRONEND CATALOG = { 215: { 'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO }, 216: { 'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO }, 98: { 'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO }, 209: { 'id': 209, 'repairGPIO': REPAIR_ASSET_GPIO }, 133: { 'id': 133, 'repairGPIO': REPAIR_ASSET_GPIO } } GPIO.setup(GPIO_to_repair_for_demo, GPIO.IN) # CREATING PARTICIPANTS OBJECTS Manufacturer = Manufacturer( OUT_MANUFACTURER, service_bulletin_out=SERVICE_BULLETIN_MANUFACTURER, service_bullete_measure=SERVICE_BULLETIN_MANUFACTURER_MEASURE, alarm_out=ALARM_MANUFACTURER, bulletin=Bulletin(), catalog=CATALOG) Service = Service(OUT_SERVICE, alarm_out=ALARM_SERVICE) Operator = Operator( service_bulletin_out=SERVICE_BULLETIN_OPERATOR, service_bullete_measure=SERVICE_BULLETIN_OPERATOR_MEASURRE, alarm_out=ALARM_OPERATOR, pimp_gpio=PIMP_GPIO) # SETTING ALL OUTPUTS TO LOW GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.ALARM_out, GPIO.LOW) GPIO.output(Operator.ALARM_out, GPIO.LOW) GPIO.output(Service.ALARM_out, GPIO.LOW) global ASSET_INSTALLED ASSET_INSTALLED = True #variable for the emergency handling, if the pump is not discovered #global EMERGENCY ############################ ##SERVICE CAR HANDLING HELP-VARIABLES## #informed_to_remove_the_service_car = False ################################## GPIO.setup(BREAK_ASSET_MANUALY_GPIO, GPIO.IN) get_alife(Manufacturer.GPIO_out, Service.GPIO_out, Operator.Service_Bulletin_GPIO_out, BREAK_ASSET_MANUALY_GPIO) Participant.update_event(0) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) Operator.buy_asset(Manufacturer, queue, BREAK_ASSET_MANUALY_GPIO, Service, GPIO_to_repair_for_demo) while queue.empty(): # CHECKING IF THE ASSET IS ON THE RFID READER if not __builtin__.EMERGENCY: Operator.check_asset() #for the emergency case if __builtin__.EMERGENCY and not __builtin__.operator_connected: Participant.update_event(15) # IF NO ASSET ON THE RFID READER00 if not Operator.Has_asset and ASSET_INSTALLED: print "No Asset" if not Operator.User_informed_about_recent_update: Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = False Manufacturer.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_MANUFACTURER, GPIO.LOW) Manufacturer.Next_asset_update = 0 GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Service.GPIO_out, GPIO.LOW) # ASSET_INSTALLED=False #Operator.Asset.Next_Pimp = 0 Operator.Asset.Next_Break = 0 GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) Participant.update_event(1) Operator.buy_asset(Manufacturer, queue, BREAK_ASSET_MANUALY_GPIO, Service, GPIO_to_repair_for_demo) ##BULLETIN HANDLING### #Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer=True when the bulletin has been activated by the manufacturer (first blinking after start) #Manufacturer.Bulletin.Activated_for_the_communication=True when the bulletin is installed on the operator's side for the first time if Operator.Has_asset and ASSET_INSTALLED and not Operator.Asset.Broken: #Next_asset_update is 0 only after the start of the demo if not Manufacturer.Next_asset_update == 0: #one time bulletin activation at the manufacturer's site for the furthere communication if datetime.datetime.now( ) > Manufacturer.Next_asset_update and not Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and __builtin__.operator_connected: GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) if GPIO.input(Manufacturer. Service_Bulletin_GPIO_Measure) == 0: Participant.update_event(9) print "setting blletin true" Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = True Manufacturer.Bulletin_at_manufacturers_campus = True Manufacturer.bulletin_start_blinking(queue) else: #inform user to put the service bulletin to the manufacturer's site first to load the agreements Participant.update_event(14) else: #first update over the service bulletin after the demo has started Manufacturer.set_next_asset_update_time(22) #returning the activated bulletin to the manufacturer's site only causes the bulletin to blink signaling that it should be brought back to the operator's #if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 0 and not Manufacturer.Bulletin_at_manufacturers_campus: # Manufacturer.bulletin_start_blinking(queue) # Manufacturer.Bulletin_at_manufacturers_campus = True #Stoping blinking of the blue lamp at operator's site # Operator.bulletin_stop_blinking() if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input( Manufacturer.Service_Bulletin_GPIO_Measure ) == 0 and __builtin__.operator_connected: if not Manufacturer.Blinker_queue_bulletin.empty( ) or Manufacturer.Blinker_queue_bulletin == None: Manufacturer.bulletin_start_blinking(queue) Manufacturer.Bulletin_at_manufacturers_campus = True if not Operator.Blinker_queue_bulletin == None and Operator.Blinker_queue_bulletin.empty: Operator.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_OPERATOR, GPIO.LOW) #The moment the bulleting is plugged of the manufacturer's site if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input( Manufacturer.Service_Bulletin_GPIO_Measure ) == 1 and Manufacturer.Bulletin_at_manufacturers_campus and __builtin__.operator_connected: Manufacturer.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_MANUFACTURER, GPIO.LOW) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) Manufacturer.Bulletin_at_manufacturers_campus = False #start blinking operator Operator.bulletin_start_blinking(queue) if not Manufacturer.Next_asset_update == 0: if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input( Manufacturer.Service_Bulletin_GPIO_Measure ) == 1 and GPIO.input( Operator.Service_Bulletin_GPIO_Measure ) == 0 and not Manufacturer.Bulletin_at_manufacturers_campus and __builtin__.operator_connected: Manufacturer.Bulletin.Activated_for_the_communication = True if Operator.Blinker_queue_bulletin.empty( ) and not Operator.Blinker_queue_bulletin is None: #Stoping blinking of the blue lamp at operator's site Operator.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_OPERATOR, GPIO.LOW) #when the service bulletin is intalled on the operator's site the updates are intalled periodically if datetime.datetime.now( ) > Manufacturer.Next_asset_update: print "Informing" if not Operator.User_informed_about_recent_update: # Informing user about the service bulletin functionality only once at the beggining of the demo Participant.update_event(4) Operator.User_informed_about_recent_update = True # install bulletin first time Operator.bulletin_stop_blinking() GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) time.sleep(4) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) Manufacturer.set_next_asset_update_time() #Operator.install_bulletin(Manufacturer) #Operator.Asset.set_next_break() else: Manufacturer.inform_operator_about_Update( Operator) ##END BULLETIN HANDLING### # ASSET BREAK #MANUAL BREAK # can be issued by the presenter any time after the serice bulletin is installed by pressing the dedicated button if not Operator.Asset.Broken and __builtin__.operator_connected: #print Operator.Asset.broken_asset_security if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 0: Operator.Asset.broken_asset_security = Operator.Asset.broken_asset_security + 1 if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 1: Operator.Asset.broken_asset_security = 0 if Operator.Asset.broken_asset_security > 3: Operator.Asset.broken_asset_security = 0 Operator.Asset_is_working = False #RANDOM BREAK - happens once when the power pack and pump are installed, bulletin is activated if Operator.Asset.Pimped and Operator.Has_asset and ASSET_INSTALLED and not Operator.Asset.Broken and Manufacturer.Bulletin.Activated_for_the_communication and __builtin__.operator_connected: # can happen only after the standard scenario is completed - after the booting part is installed if Operator.Asset.First_time_random_break: if Operator.Asset.Next_Break == 0: Operator.Asset.set_next_break() if not Operator.Asset.Next_Break == 0: if datetime.datetime.now( ) > Operator.Asset.Next_Break and Operator.Asset_is_working and not Operator.Asset.Broken and Operator.Has_asset: print "not working" Operator.Asset.First_time_random_break = False Operator.Asset_is_working = False if not Operator.Asset_is_working and not Operator.Asset.Broken and __builtin__.operator_connected: Participant.handle_break(Service, Manufacturer, Operator, queue) # END ASSET BREAK ##HANDLING THE SERVICE CAR AND REPAIRING THE ASSET# Participant.handle_reparing(Operator, Service, Manufacturer, GPIO_to_repair_for_demo) ### END HANDLING THE SERVICE CAR AND REPAIRING THE ASSET## ####HANDLING ASSET BOOSTING if ASSET_INSTALLED and not Operator.Asset.Broken and Operator.Has_asset and __builtin__.operator_connected: print Operator.Asset.pimping if GPIO.input(Operator.Pimp_GPIO ) == 0 and Operator.Asset.pimping < 5: Operator.Asset.pimping += 1 if GPIO.input(Operator.Pimp_GPIO ) == 1 and Operator.Asset.pimping > 0: Operator.Asset.pimping -= 1 # remind to pimp the asset if not Manufacturer.Bulletin_at_manufacturers_campus and GPIO.input( Operator.Service_Bulletin_GPIO_Measure ) == 0 and not Operator.Asset.Pimped and Manufacturer.Bulletin.Activated_for_the_communication and Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer: if Operator.Asset.Next_Pimp == 0 and Manufacturer.Bulletin.Activated_for_the_communication: # FIRST REMINDER print "setting next pimp" print str(Manufacturer.Bulletin. Activated_for_the_communication) Operator.Asset.set_next_pimp_reminder(seconds_=8) else: if datetime.datetime.now() > Operator.Asset.Next_Pimp: # REMINDER EVENT print("updating event 10") Participant.update_event(10) GPIO.output(Service.GPIO_out, GPIO.HIGH) Operator.Asset.set_next_pimp_reminder() ##BOOSTING THE ASSET # if pimping>4 and not Operator.Asset.Pimped and not INFORMED_BULLETIN: if Operator.Asset.pimping == 5 and not Operator.Asset.Pimped: Operator.pimp_the_pump() GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) GPIO.output(Service.GPIO_out, GPIO.HIGH) time.sleep(10) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Service.GPIO_out, GPIO.LOW) if Operator.Asset.pimping == 0 and Operator.Asset.Pimped and not Operator.Asset.Broken and Operator.Has_asset: Operator.unpimp_the_pump(Service) Operator.Asset.Next_Break = 0 Operator.Asset.set_next_pimp_reminder() ##END BOOSTING THE ASSET print "stoped" except KeyboardInterrupt: # here you put any code you want to run before the program # exits when pressing CTRL+C GPIO.cleanup() http_server.stop()
def readRFID(service, operator, catalog, main_queue, manufacturer, BREAK_ASSET_MANUALY_GPIO, queue, GPIO_to_repair_for_demo): #global EMERGENCY broken_asset_security=0 broken=False event_updated=False switch_to_event_0=datetime.datetime.now()+datetime.timedelta(seconds=10) #global util global rdr rdr=RFID.RFID() Asset=None last_uid=0 #util = rdr.util() while not operator.Has_asset: while True and main_queue.empty(): #Demonstrate the asset break even if there is no asset #print broken_asset_security if not broken and __builtin__.operator_connected: print broken_asset_security if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 0: broken_asset_security = broken_asset_security + 1 if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 1: broken_asset_security = 0 if broken_asset_security > 3: broken_asset_security = 0 broken=True Participant.handle_break(service, manufacturer, operator, queue) if broken: broken=Participant.handle_reparing(operator, service, manufacturer, GPIO_to_repair_for_demo) print broken if not broken: #to return to the event 0 switch_to_event_0=datetime.datetime.now()+datetime.timedelta(seconds=10) event_updated=False if __builtin__.EMERGENCY and __builtin__.operator_connected: print "Emergency Buy" Asset=Operator.emergancy_asset(GPIO_to_repair_for_demo) operator.Has_asset=True break break if __builtin__.EMERGENCY and not __builtin__.operator_connected: Participant.update_event(15) break break if not switch_to_event_0==0: if datetime.datetime.now()>switch_to_event_0 and not event_updated and not broken: event_updated=True GPIO.output(manufacturer.GPIO_out, GPIO.LOW) GPIO.output(operator.Service_Bulletin_GPIO_out, GPIO.HIGH) Participant.update_event(0) manufacturer.Bulletin.Activated_for_communication=False manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = False print "bulletin "+ str(manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer) if not operator.Asset ==None: operator.Asset.Next_Pimp =0 try: manufacturer.Next_asset_update = 0 finally: operator.User_informed_about_recent_update=False switch_to_event_0=0 (error, tag_type) = rdr.request() if not error and not broken: #print "Tag detected" (error, uid) = rdr.anticoll() if not error: #print "UID: " + str(uid[1]) try: asset=catalog[uid[1]] Asset=Pump.Pump(rfid_identifier=asset['id'], gpio_in_to_repair=asset['repairGPIO']) GPIO.output(manufacturer.GPIO_out, GPIO.LOW) operator.Has_asset=True except KeyError, e: if not uid[1]==last_uid: print "The asset is not in the manufacturer's catalog, please try another asset" last_uid=uid[1] break
def main(a, queue): try: import multiprocessing import threading from Webserver import WebSocketHandler from Webserver import MainHandler from Participant import Participant from Bulletin import Bulletin from Operator import Operator from Service import Service from Manufacturer import Manufacturer import Pump import time import json import datetime import RPi.GPIO as GPIO from PIL import Image import pygame from multiprocessing import Process, Queue import signal from random import randint import RFID GPIO.setmode(GPIO.BOARD) # CONSTANTS PIMP_GPIO = 13 #gpio 27 OUT_MANUFACTURER = 11 #gpio 17 OUT_SERVICE = 33 #gpio 13 ALARM_MANUFACTURER = 16 # gpio 23 ALARM_OPERATOR = 7 #gpio 4 ALARM_SERVICE = 38 #gpio 20 REPAIR_ASSET_GPIO = 40 # gpio 21 BREAK_ASSET_MANUALY_GPIO = 18 #gpio 24 SERVICE_BULLETIN_MANUFACTURER = 31 #gpio 6v SERVICE_BULLETIN_MANUFACTURER_MEASURE = 35 #gpio 19 SERVICE_BULLETIN_OPERATOR = 12 #gpio 18 SERVICE_BULLETIN_OPERATOR_MEASURRE = 15 #gpio 22 GPIO_to_repair_for_demo=40 # gpio 21 # CATALOG OF RFID CHIPS' IDs THAT ARE ASSIGNED TO THE ASSETS IN THE FRONEND CATALOG = { 215: {'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO}, 216: {'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO}, 98: {'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO}, 209: {'id': 209, 'repairGPIO': REPAIR_ASSET_GPIO}, 133: {'id': 133, 'repairGPIO': REPAIR_ASSET_GPIO} } GPIO.setup(GPIO_to_repair_for_demo, GPIO.IN) # CREATING PARTICIPANTS OBJECTS Manufacturer = Manufacturer(OUT_MANUFACTURER, service_bulletin_out=SERVICE_BULLETIN_MANUFACTURER, service_bullete_measure=SERVICE_BULLETIN_MANUFACTURER_MEASURE, alarm_out=ALARM_MANUFACTURER, bulletin=Bulletin(), catalog=CATALOG) Service = Service(OUT_SERVICE, alarm_out=ALARM_SERVICE) Operator = Operator(service_bulletin_out=SERVICE_BULLETIN_OPERATOR, service_bullete_measure=SERVICE_BULLETIN_OPERATOR_MEASURRE, alarm_out=ALARM_OPERATOR, pimp_gpio=PIMP_GPIO) # SETTING ALL OUTPUTS TO LOW GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.ALARM_out, GPIO.LOW) GPIO.output(Operator.ALARM_out, GPIO.LOW) GPIO.output(Service.ALARM_out, GPIO.LOW) global ASSET_INSTALLED ASSET_INSTALLED = True #variable for the emergency handling, if the pump is not discovered #global EMERGENCY ############################ ##SERVICE CAR HANDLING HELP-VARIABLES## #informed_to_remove_the_service_car = False ################################## GPIO.setup(BREAK_ASSET_MANUALY_GPIO, GPIO.IN) get_alife(Manufacturer.GPIO_out, Service.GPIO_out, Operator.Service_Bulletin_GPIO_out, BREAK_ASSET_MANUALY_GPIO) Participant.update_event(0) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) Operator.buy_asset(Manufacturer, queue, BREAK_ASSET_MANUALY_GPIO, Service, GPIO_to_repair_for_demo) while queue.empty(): # CHECKING IF THE ASSET IS ON THE RFID READER if not __builtin__.EMERGENCY: Operator.check_asset() #for the emergency case if __builtin__.EMERGENCY and not __builtin__.operator_connected: Participant.update_event(15) # IF NO ASSET ON THE RFID READER00 if not Operator.Has_asset and ASSET_INSTALLED: print "No Asset" if not Operator.User_informed_about_recent_update: Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = False Manufacturer.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_MANUFACTURER, GPIO.LOW) Manufacturer.Next_asset_update = 0 GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Service.GPIO_out, GPIO.LOW) # ASSET_INSTALLED=False #Operator.Asset.Next_Pimp = 0 Operator.Asset.Next_Break = 0 GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) Participant.update_event(1) Operator.buy_asset(Manufacturer, queue, BREAK_ASSET_MANUALY_GPIO, Service, GPIO_to_repair_for_demo) ##BULLETIN HANDLING### #Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer=True when the bulletin has been activated by the manufacturer (first blinking after start) #Manufacturer.Bulletin.Activated_for_the_communication=True when the bulletin is installed on the operator's side for the first time if Operator.Has_asset and ASSET_INSTALLED and not Operator.Asset.Broken: #Next_asset_update is 0 only after the start of the demo if not Manufacturer.Next_asset_update == 0: #one time bulletin activation at the manufacturer's site for the furthere communication if datetime.datetime.now() > Manufacturer.Next_asset_update and not Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and __builtin__.operator_connected: GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) if GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 0: Participant.update_event(9) print "setting blletin true" Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = True Manufacturer.Bulletin_at_manufacturers_campus = True Manufacturer.bulletin_start_blinking(queue) else: #inform user to put the service bulletin to the manufacturer's site first to load the agreements Participant.update_event(14) else: #first update over the service bulletin after the demo has started Manufacturer.set_next_asset_update_time(22) #returning the activated bulletin to the manufacturer's site only causes the bulletin to blink signaling that it should be brought back to the operator's #if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 0 and not Manufacturer.Bulletin_at_manufacturers_campus: # Manufacturer.bulletin_start_blinking(queue) # Manufacturer.Bulletin_at_manufacturers_campus = True #Stoping blinking of the blue lamp at operator's site # Operator.bulletin_stop_blinking() if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 0 and __builtin__.operator_connected: if not Manufacturer.Blinker_queue_bulletin.empty() or Manufacturer.Blinker_queue_bulletin==None: Manufacturer.bulletin_start_blinking(queue) Manufacturer.Bulletin_at_manufacturers_campus = True if not Operator.Blinker_queue_bulletin==None and Operator.Blinker_queue_bulletin.empty: Operator.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_OPERATOR, GPIO.LOW) #The moment the bulleting is plugged of the manufacturer's site if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 1 and Manufacturer.Bulletin_at_manufacturers_campus and __builtin__.operator_connected: Manufacturer.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_MANUFACTURER, GPIO.LOW) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) Manufacturer.Bulletin_at_manufacturers_campus = False #start blinking operator Operator.bulletin_start_blinking(queue) if not Manufacturer.Next_asset_update == 0: if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input( Manufacturer.Service_Bulletin_GPIO_Measure) == 1 and GPIO.input(Operator.Service_Bulletin_GPIO_Measure)==0 and not Manufacturer.Bulletin_at_manufacturers_campus and __builtin__.operator_connected: Manufacturer.Bulletin.Activated_for_the_communication=True if Operator.Blinker_queue_bulletin.empty() and not Operator.Blinker_queue_bulletin is None: #Stoping blinking of the blue lamp at operator's site Operator.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_OPERATOR, GPIO.LOW) #when the service bulletin is intalled on the operator's site the updates are intalled periodically if datetime.datetime.now() > Manufacturer.Next_asset_update: print "Informing" if not Operator.User_informed_about_recent_update: # Informing user about the service bulletin functionality only once at the beggining of the demo Participant.update_event(4) Operator.User_informed_about_recent_update = True # install bulletin first time Operator.bulletin_stop_blinking() GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) time.sleep(4) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) Manufacturer.set_next_asset_update_time() #Operator.install_bulletin(Manufacturer) #Operator.Asset.set_next_break() else: Manufacturer.inform_operator_about_Update(Operator) ##END BULLETIN HANDLING### # ASSET BREAK #MANUAL BREAK # can be issued by the presenter any time after the serice bulletin is installed by pressing the dedicated button if not Operator.Asset.Broken and __builtin__.operator_connected: #print Operator.Asset.broken_asset_security if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 0: Operator.Asset.broken_asset_security = Operator.Asset.broken_asset_security + 1 if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 1: Operator.Asset.broken_asset_security = 0 if Operator.Asset.broken_asset_security > 3: Operator.Asset.broken_asset_security = 0 Operator.Asset_is_working = False #RANDOM BREAK - happens once when the power pack and pump are installed, bulletin is activated if Operator.Asset.Pimped and Operator.Has_asset and ASSET_INSTALLED and not Operator.Asset.Broken and Manufacturer.Bulletin.Activated_for_the_communication and __builtin__.operator_connected: # can happen only after the standard scenario is completed - after the booting part is installed if Operator.Asset.First_time_random_break: if Operator.Asset.Next_Break == 0: Operator.Asset.set_next_break() if not Operator.Asset.Next_Break == 0: if datetime.datetime.now() > Operator.Asset.Next_Break and Operator.Asset_is_working and not Operator.Asset.Broken and Operator.Has_asset: print "not working" Operator.Asset.First_time_random_break=False Operator.Asset_is_working = False if not Operator.Asset_is_working and not Operator.Asset.Broken and __builtin__.operator_connected: Participant.handle_break(Service, Manufacturer, Operator, queue) # END ASSET BREAK ##HANDLING THE SERVICE CAR AND REPAIRING THE ASSET# Participant.handle_reparing(Operator, Service, Manufacturer,GPIO_to_repair_for_demo) ### END HANDLING THE SERVICE CAR AND REPAIRING THE ASSET## ####HANDLING ASSET BOOSTING if ASSET_INSTALLED and not Operator.Asset.Broken and Operator.Has_asset and __builtin__.operator_connected: print Operator.Asset.pimping if GPIO.input(Operator.Pimp_GPIO) == 0 and Operator.Asset.pimping < 5: Operator.Asset.pimping += 1 if GPIO.input(Operator.Pimp_GPIO) == 1 and Operator.Asset.pimping > 0: Operator.Asset.pimping -= 1 # remind to pimp the asset if not Manufacturer.Bulletin_at_manufacturers_campus and GPIO.input( Operator.Service_Bulletin_GPIO_Measure) == 0 and not Operator.Asset.Pimped and Manufacturer.Bulletin.Activated_for_the_communication and Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer: if Operator.Asset.Next_Pimp == 0 and Manufacturer.Bulletin.Activated_for_the_communication: # FIRST REMINDER print "setting next pimp" print str(Manufacturer.Bulletin.Activated_for_the_communication) Operator.Asset.set_next_pimp_reminder(seconds_=8) else: if datetime.datetime.now() > Operator.Asset.Next_Pimp: # REMINDER EVENT print ("updating event 10") Participant.update_event(10) GPIO.output(Service.GPIO_out, GPIO.HIGH) Operator.Asset.set_next_pimp_reminder() ##BOOSTING THE ASSET # if pimping>4 and not Operator.Asset.Pimped and not INFORMED_BULLETIN: if Operator.Asset.pimping == 5 and not Operator.Asset.Pimped: Operator.pimp_the_pump() GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) GPIO.output(Service.GPIO_out, GPIO.HIGH) time.sleep(10) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Service.GPIO_out, GPIO.LOW) if Operator.Asset.pimping ==0 and Operator.Asset.Pimped and not Operator.Asset.Broken and Operator.Has_asset: Operator.unpimp_the_pump(Service) Operator.Asset.Next_Break = 0 Operator.Asset.set_next_pimp_reminder() ##END BOOSTING THE ASSET print "stoped" except KeyboardInterrupt: # here you put any code you want to run before the program # exits when pressing CTRL+C GPIO.cleanup() http_server.stop()