Ejemplo n.º 1
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()
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def control_c_handler(signum, frame):
    for p in property_list:
        actions = p.alphabet
        if "<>" in actions[p.status][1]:
            send_message("UPDATEB VIOLATION OF PROPERTY %s" % p.name)
        else:
            send_message("UPDATEB %s EXITING GRACEFULLY" % p.name)
    exit_program()
Ejemplo n.º 4
0
def update_properties():
    label_str = ""

    for i in range(0, len(property_list)):
        if i != 0:
            label_str = label_str + "\n"
        label_str = label_str + ("%s" % property_list[i])

    send_message("LABELB %s" % label_str)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def on_message(client, userdata, msg):
    message = msg.payload

    # we are only interested in leader actions for this assert
    split = message.split(" ")
    if not split[3] == "LEADER":
        return

    send_message("UPDATEA DONT_GET_FOOLED : %s" % message)

    recipient = int(split[4])
    leader = int(split[5])
    if recipient > leader:
        send_message("UPDATEA DONT_GET_FOOLED : ASSERTFAILED")
Ejemplo n.º 7
0
def on_message(client, userdata, msg):
    global systemStatus
    message = msg.payload

    # we are only interested in election/leader actions for this assert
    split = message.split(" ")
    if not split[3] in ["ELECTION", "LEADER"]:
        return

    # Check the status of the fluent here after receiving the
    # messages
    fluent.checkFluent(message)
    if fluent.status == FluentStatus.ON:
        systemStatus = AssertStatus.HOMEFREE

    if systemStatus == AssertStatus.HOMEFREE:
        send_message("UPDATEA %s : %s" % (assertName, message))
    elif systemStatus != AssertStatus.HOMEFREE:
        send_message("UPDATEA %s : %s" % (assertName, message))
        split = message.split(" ")
        if "LEADER" == split[3]:
            recipient = int(split[4])
            leader = int(split[5])
            if leader == assertParam and systemStatus == AssertStatus.BEGIN:
                systemStatus = AssertStatus.ERROR
                send_message("UPDATEA %s : ASSERTFAILED" % assertName)
Ejemplo n.º 8
0
def on_message(client, userdata, msg):
    splits = msg.payload.split(' ', 3)

    for p in property_list:
        found = False
        actions = p.alphabet
        for i in range(0, len(actions)):
            if actions[i][0] == splits[3]:
                found = True
                break

        if found:
            send_message("UPDATEB %s %s %s: %s" %
                         (splits[0], splits[1], p.name, splits[3]))
            if actions[p.status][0] == splits[3]:
                p.status = (p.status + 1) % len(p.alphabet)
            elif "<>" in actions[p.status][1]:
                print("ALPHABET ACTION SEEN, STILL WAITING FOR EVENTUALLY")
            else:
                send_message("UPDATEB VIOLATION OF PROPERTY %s" % p.name)

    if found:
        update_properties()
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def on_message(client, userdata, msg):
    # we only listen for messages from
    # print msg.payload
    splits = msg.payload.split(' ')
    if splits[3] == "REQUEST":
        if splits[4] == fork.name:
            if fork.in_use:
                send_message("FORKBUSY %s %d" % (fork.name, int(splits[5])))
            else:
                print(msg.payload)
                send_message("FORKAVAIL %s %d" % (fork.name, int(splits[5])))
                fork.in_use = True
    elif splits[3] == "REPLACE":
        if splits[4] == fork.name:
            print(msg.payload)
            send_message("FORKREPL %s" % fork.name)
            fork.in_use = False
Ejemplo n.º 11
0
def on_message(client, userdata, msg):
    message = msg.payload
    splits = message.split(' ')
    action = splits[3]
    if action in ["LABELA", "LABELB", "UPDATEA", "UPDATEB"]:
        return
    to_id = int(splits[4])

    # we are only interested in messages that are sent to our node id
    if to_id == gui.id:
        print(msg.payload)

        if action == "ELECTION":
            leader = int(splits[5])
            if gui.state == Status.DECIDE:
                print("trying to decide")
            elif gui.state == Status.BOWOUT:
                gui.send_id(leader)
            elif gui.state in [Status.ANNOUNCE, Status.WAITING,
                               Status.WORKING, Status.IDLE]:
                print("already had an election, cheating?")
            else:  # gui.state == Status.MAIN
                gui.state = Status.DECIDE
                if leader > gui.id:
                    for i in range(0, 8):
                        if i == 0:
                            leds[i].write(ON)
                        else:
                            leds[i].write(OFF)
                    gui.send_id(leader)
                    gui.state = Status.BOWOUT
                elif leader < gui.id:
                    gui.state = Status.MAIN
                    gui.send_id(gui.id)
                else:
                    gui.state = Status.ANNOUNCE
                    gui.send_leader(gui.id)
                    gui.state = Status.WAITING

        elif action == "LEADER":
            leader = int(splits[5])
            if gui.state in [Status.MAIN, Status.DECIDE, Status.WORKING,
                             Status.IDLE]:
                # not in a state to accept leader message, cheating?
                print("maybe cheating")
            elif gui.state == Status.BOWOUT:
                if leader > gui.id:
                    gui.send_leader(leader)
                    send_message("WORKING %d" % gui.id)
                    gui.state = Status.WORKING
                elif leader == gui.id:
                    print("received invalid leader id")
            elif gui.state in [Status.ANNOUNCE, Status.WAITING]:
                if leader == gui.id:
                    for i in range(0,8):
                        if i < 3:
                            leds[i].write(ON)
                        else:
                            leds[i].write(OFF)
                    send_message("WORKING %d" % gui.id)
                    gui.state = Status.WORKING
                else:
                    print("should not receive multiple leaders")
Ejemplo n.º 12
0
 def send_leader(self, id):
     time.sleep(1)
     send_message("LEADER %d %d" % (self.next_id, id))
Ejemplo n.º 13
0
 def send_id(self, id):
     time.sleep(1)
     send_message("ELECTION %d %d" % (self.next_id, id))