added exception drop in uart rx tree

Fri, 16 Dec 2011 00:24:35 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Fri, 16 Dec 2011 00:24:35 +0100
changeset 85
a637228562a7
parent 84
39d361d87755
child 86
79fb119cf3c3

added exception drop in uart rx tree

slotUI/SlotCli.py file | annotate | diff | comparison | revisions
--- a/slotUI/SlotCli.py	Fri Dec 16 00:15:14 2011 +0100
+++ b/slotUI/SlotCli.py	Fri Dec 16 00:24:35 2011 +0100
@@ -192,102 +192,109 @@
                     "Last RX: %19s" % rx, curses.color_pair(2))
                 self.scr.refresh()
                 # we have received something
-                data = rx.split(":")
-                if rx[:2] == "L:":
-                    # update lap time info
-                    l = int(data[2], 16)
-                    slot = int(data[3]) - 1
-                    t = int(data[4], 16) / 2000.00
-                    self.sysclk = int(data[5], 16) / 2000.00
-                    self.slot[slot]["laps"] = l
-                    self.slot[slot]["last"] = t
-                    self.slot[slot]["clk"] = self.sysclk
-                    if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): self.slot[slot]["best"] = t
-                    if self.bestlap > t:
-                        trigger_sound("lap_record")
-                        self.bestlap = t
+                try:
+                    data = rx.split(":")
+                    if rx[:2] == "L:":
+                        # update lap time info
+                        l = int(data[2], 16)
+                        slot = int(data[3]) - 1
+                        t = int(data[4], 16) / 2000.00
+                        self.sysclk = int(data[5], 16) / 2000.00
+                        self.slot[slot]["laps"] = l
+                        self.slot[slot]["last"] = t
+                        self.slot[slot]["clk"] = self.sysclk
+                        if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0):
+                            self.slot[slot]["best"] = t
+                        if self.bestlap > t:
+                            trigger_sound("lap_record")
+                            self.bestlap = t
 
-                    self.slot[slot]["status"] = "IN-RACE"
-                    self.render_slots()
+                        self.slot[slot]["status"] = "IN-RACE"
+                        self.render_slots()
 
-                if rx[:2] == "F:":
-                    # update fuel level
-                    slot = int(data[1])
-                    f = int(data[2], 16)
-                    f = f / 100 # fuel in percent
-                    self.sysclk = int(data[3], 16) / 2000.00
-                    self.slot[slot]["fuel_last"] = self.slot[slot]["fuel"]
-                    self.slot[slot]["fuel"] = f
-                    if self.slot[slot]["fuel_last"] != f:
-                        # 10 percent fuel, set speed limit for car to 8
-                        if (self.slot[slot]["fuel_last"] == 11) and (f == 10):
-                            # warning sound
-                            trigger_sound("fuel_warning1")
-                            cli.box.speedlimit(slot, 8)
-                        # 5 percent, set speed limit for car to 4
-                        if (self.slot[slot]["fuel_last"] == 6) and (f == 5):
-                            # warning sound
-                            trigger_sound("fuel_warning2")
-                            cli.box.speedlimit(slot, 4)
-                        if (self.slot[slot]["fuel_last"] == 1) and (f == 0):
-                            # set speedlimit to 2
-                            cli.box.speedlimit(slot, 3)
-                        if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20):
-                            cli.box.speedlimit(slot, 15)
-                        if (self.slot[slot]["fuel_last"] < f) and (f == 100):
-                            trigger_sound("fuel_full")
-                    self.render_slots()
+                    if rx[:2] == "F:":
+                        # update fuel level
+                        slot = int(data[1])
+                        f = int(data[2], 16)
+                        f = f / 100 # fuel in percent
+                        self.sysclk = int(data[3], 16) / 2000.00
+                        self.slot[slot]["fuel_last"] = self.slot[slot]["fuel"]
+                        self.slot[slot]["fuel"] = f
+                        if self.slot[slot]["fuel_last"] != f:
+                            if (self.slot[slot]["fuel_last"] == 11) and (f == 10):
+                                # 10 percent fuel, set speed limit for car to 8
+                                # warning sound
+                                trigger_sound("fuel_warning1")
+                                cli.box.speedlimit(slot, 8)
+                            if (self.slot[slot]["fuel_last"] == 6) and (f == 5):
+                                # 5 percent, set speed limit for car to 4
+                                # warning sound
+                                trigger_sound("fuel_warning2")
+                                cli.box.speedlimit(slot, 4)
+                            if (self.slot[slot]["fuel_last"] == 1) and (f == 0):
+                                # fuel empty
+                                # set speedlimit to 3
+                                cli.box.speedlimit(slot, 3)
+                            if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20):
+                                cli.box.speedlimit(slot, 15)
+                            if (self.slot[slot]["fuel_last"] < f) and (f == 100):
+                                trigger_sound("fuel_full")
+                        self.render_slots()
 
-                if rx[:1] == "~":
-                    # jumpstart occured
-                    slot = int(rx[1:2])
-                    t = int(data[1], 16) / 2000.00
-                    self.slot[slot]["jumpstart"] = t
-                    self.slot[slot]["status"] = "Jumpstart!"
+                    if rx[:1] == "~":
+                        # jumpstart occured
+                        slot = int(rx[1:2])
+                        t = int(data[1], 16) / 2000.00
+                        self.slot[slot]["jumpstart"] = t
+                        self.slot[slot]["status"] = "Jumpstart!"
 
-                if rx[:3] == "RW:":
-                    # ResponseWire packet, do nothing at the moment, just decode
-                    slot = int(data[1])
-                    devtype = int(data[2])
-                    sender = int(data[3], 16)
-                    status = int(data[4], 16)
-                    self.sysclk = int(data[5], 16)
-                    if (devtype == 4):
-                        # pitlane sent something
-                        if (status == 5):
-                            self.slot[slot]["status"] = "PITLANE"
-                            trigger_sound("pitlane_enter")
-                        if (status == 6):
-                            self.slot[slot]["status"] = "IN-RACE"
-                            trigger_sound("pitlane_exit")
+                    if rx[:3] == "RW:":
+                        # ResponseWire packet, do nothing at the moment, just decode
+                        slot = int(data[1])
+                        devtype = int(data[2])
+                        sender = int(data[3], 16)
+                        status = int(data[4], 16)
+                        self.sysclk = int(data[5], 16)
+                        if (devtype == 4):
+                            # pitlane sent something
+                            if (status == 5):
+                                self.slot[slot]["status"] = "PITLANE"
+                                trigger_sound("pitlane_enter")
+                            if (status == 6):
+                                self.slot[slot]["status"] = "IN-RACE"
+                                trigger_sound("pitlane_exit")
 
-                    self.render_slots()
+                        self.render_slots()
 
-                if rx == "!RACE PREPARE":
-                    # reset current race status
-                    # and display PREPARE PHASE
-                    self.reset_slots()
-                    for slot in range(MAXSLOTS):
-                        self.slot[slot]["status"] = "Prepare"
-                    trigger_sound("race_prepare")
+                    if rx == "!RACE PREPARE":
+                        # reset current race status
+                        # and display PREPARE PHASE
+                        self.reset_slots()
+                        for slot in range(MAXSLOTS):
+                            self.slot[slot]["status"] = "Prepare"
+                        trigger_sound("race_prepare")
+
+                    if rx == "!RACE START":
+                        for slot in range(MAXSLOTS):
+                            if self.slot[slot]["status"] == "~~~~~~~~~~":
+                                self.slot[slot]["status"] = "Idle"
+                        trigger_sound("race_start")
 
-                if rx == "!RACE START":
-                    for slot in range(MAXSLOTS):
-                        if self.slot[slot]["status"] == "~~~~~~~~~~":
-                            self.slot[slot]["status"] = "Idle"
-                    trigger_sound("race_start")
+                    if rx == "!COUNTDOWN":
+                        # countdown initiated
+                        for slot in range(MAXSLOTS):
+                            self.slot[slot]["status"] = "~~~~~~~~~~"
+                        trigger_sound("countdown_start")
 
-                if rx == "!COUNTDOWN":
-                    # countdown initiated
-                    for slot in range(MAXSLOTS):
-                        self.slot[slot]["status"] = "~~~~~~~~~~"
-                    trigger_sound("countdown_start")
+                    self.scr.addstr(10,31,
+                        "Race Timer: %7.3f min" % (self.sysclk / 60),
+                        curses.color_pair(2))
 
-                self.scr.addstr(10,31,
-                    "Race Timer: %7.3f min" % (self.sysclk / 60),
-                    curses.color_pair(2))
+                    self.scr.refresh()
 
-                self.scr.refresh()
+                except Exception:
+                    trigger_sound("data_error")
+                    pass
 
         # terminate
         curses.nocbreak()

mercurial