Esempio n. 1
0
def main():
    if len(sys.argv) != 2:
        print "Usage: fork <label>"
        exit_program()

    led_no = int(ord(sys.argv[1].lower()) - ord('a'))
    if led_no < 0 or led_no > 7:
        print "Usage: fork <label>\nlabel must be a letter between a and h"
        exit_program()

    mqtt_client.will_set(mqtt_topic, '___Will of FORK %s___' % fork.name, 0,
                         False)
    mqtt_client.on_message = on_message
    mqtt_client.loop_start()

    fork.name = sys.argv[1]
    fork.led_no = led_no

    send_message("FORK '%s' is in da house (on led %d)" % (fork.name,
                 fork.led_no))

    led = mraa.Gpio(fork.led_no + 2)
    led.dir(mraa.DIR_OUT)
    led.write(ON)

    while True:
        while fork.in_use:
            led.write(OFF)
            time.sleep(0.1)
            led.write(ON)
            time.sleep(0.1)

        # send_message("FORK %s stayin' alive" % fork.name)
        time.sleep(0.5)
Esempio n. 2
0
def main():
    #    if len(sys.argv) != 2:
    #        print("Usage: fluent <led_no>")
    #        exit_program()

    #    fluent.id = int(sys.argv[1])
    mqtt_client.will_set(mqtt_topic, '___Will of FLUENTS___', 0, False)
    mqtt_client.on_message = on_message
    mqtt_client.loop_start()

    root = tk.Tk()
    gui = Ledison(root)
    for i in range(0, 8):
        c = Circle(gui,
                   i,
                   40 + 40 * i,
                   40,
                   15,
                   fill="#BBB",
                   outline="white",
                   width=1)
        if i in range(0, 2):
            c.on_color = "green"
        elif i in range(2, 4):
            c.on_color = "blue"
        elif i in range(4, 6):
            c.on_color = "orange"
        else:
            c.on_color = "red"
        leds.append(c)
        c.write(OFF)

    send_message("<LEDison> FLUENT is ready to rock")
    root.mainloop()
    exit_program()
Esempio n. 3
0
def main():
    global gui
    if len(sys.argv) != 3:
        print "Usage: ledison <id> <next_id>"
        exit_program()

    mqtt_client.will_set(mqtt_topic, '___Will of LEDison___', 0,
                         False)
    mqtt_client.on_message = on_message
    mqtt_client.loop_start()

    root = tk.Tk()
    gui = Ledison(root, int(sys.argv[1]), int(sys.argv[2]))
    for i in range(0, 8):
        c = Circle(gui, i, 40 + 40 * i, 40, 15, fill="#BBB", outline="white",
                   width=1)
        if i in range(0, 2):
            c.on_color = "green"
        elif i in range(2, 4):
            c.on_color = "blue"
        elif i in range(4, 6):
            c.on_color = "orange"
        else:
            c.on_color = "red"
        leds.append(c)
        c.write(OFF)

    # start election in contention
    leds[0].write(ON)
    leds[1].write(ON)
    root.mainloop()
    exit_program()
Esempio n. 4
0
def main():
    global node
    if len(sys.argv) != 3:
        print "Usage: node <id> <next_id>"
        exit_program()

    node = Node(int(sys.argv[1]), int(sys.argv[2]))
    mqtt_client.will_set(mqtt_topic, "__WILL OF NODE %d__" % node.id, 0, False)
    mqtt_client.on_message = on_message
    mqtt_client.loop_start()

    if node.id == 0:
        node.initiator = True

    # start election in contention
    if EDISON:
        leds[0].write(ON)
        leds[1].write(ON)

    if node.initiator and node.state == Status.MAIN:
        time.sleep(1)
        node.send_id(node.id)

    while True:
        time.sleep(0.5)
Esempio n. 5
0
def main():
    mqtt_client.will_set(mqtt_topic, "___Will of SAFETY PROPERTY___", 0, False)
    mqtt_client.on_message = on_message
    mqtt_client.loop_start()

    update_properties()

    while True:
        time.sleep(1.0)

    exit_program()
Esempio n. 6
0
def main():
    mqtt_client.on_message = on_message
    mqtt_client.will_set(mqtt_topic, "Will of Asserter\n\n", 0, False)
    mqtt_client.loop_start()

    description = "assert DONT_GET_FOOLED = " \
                  "forall[i:1..Max] forall[j:0..(i-1)] []!(send_leader[i][j])"
    send_message("LABELA %s" % description)

    while True:
        time.sleep(1)
Esempio n. 7
0
def main():
    global gui
    root = tk.Tk()
    top_frame = tk.Frame()
    top_frame.pack()
    bottom_frame = tk.Frame(highlightthickness=2,
                            highlightbackground="black",
                            highlightcolor="black")
    bottom_frame.pack(side=tk.BOTTOM)
    gui = Gui(root, top_frame, bottom_frame)

    mqtt_client.will_set(mqtt_topic, '___Will of GUI___', 0, False)
    mqtt_client.on_message = on_message
    mqtt_client.loop_start()

    gui.part_a()
    gui.part_b()

    root.mainloop()
    exit_program()
Esempio n. 8
0
def main():
    global assertParam
    global assertName
    global assertDescription
    global fluent

    if len(sys.argv) < 2:
        print "Invalid number of arguments, usage : " \
              "python assert.py <assert parameter>"
        exit_program()

    assertParam = int(sys.argv[1])
    fluent = Fluent(assertParam)
    mqtt_client.on_message = on_message
    mqtt_client.will_set(mqtt_topic, "Will of Asserter\n\n", 0, False)
    mqtt_client.loop_start()

    assertName = "VALID%d" % assertParam
    assertDescription = "(!send_leader[%d][k:IDS] W send_id[%d][k:IDS])" % \
                 (assertParam, assertParam)
    send_message("LABELA assert %s = %s" % (assertName, assertDescription))

    while True:
        time.sleep(1)