Skip to content

Commit

Permalink
Merge branch 'rbsm_console_edits' into buckley_unify_style
Browse files Browse the repository at this point in the history
  • Loading branch information
grypoB committed Dec 3, 2016
2 parents 0159653 + 3395fe5 commit fa102c6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 26 deletions.
97 changes: 72 additions & 25 deletions offline/debugging/rbsm_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,50 @@
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)

screenCopy = None
screen_copy = None

#Create a dictionary of message headers
#TODO create it from ../../real_time/rbsm_config.txt
mid_to_str = {
0: "ENC_TICKS_LAST",
1: "ENC_TICKS_RESET",
5: "ENC_RESET_REQUEST",
6: "ENC_RESET_CONFIRM",
17: "MEGA_TELEOP_BRAKE_COMMAND",
18: "MEGA_AUTON_BRAKE_COMMAND",
19: "MEGA_STEER_COMMAND",
20: "MEGA_STEER_ANGLE",
21: "MEGA_BRAKE_STATE",
22: "MEGA_AUTON_STATE" ,
23: "MEGA_BATTERY_LEVEL",
24: "MEGA_STEER_FEEDBACK",
30: "COMP_HASH",
253: "MEGA_TIMESTAMP",
254: "ERROR",
255: "DEVICE_ID"
}
# startOfValues is the comment before start of values for dict
# takeout is what needs to be taken out from the beginning of the values in dict
# if it is in the rbsm_config.txt file
def create_bit_to_str(start_of_values, takeout=""):
dict = {}
settings_file = None
try:
settings_file = open("../../real_time/rbsm_config.txt")
except:
print("Error! Unable to find real_time/rbsm_headers.txt\n")
sys.exit(1)
# when the correct headers found
headers_found = False
# when to stop looking for headers
end_headers = False
# go through each line to find the message headers
for line_num, line in enumerate(settings_file):
# to give right name takes out RBSM_MID_ if that is at beginning cause "RBSM_MID_" unneeded
if(line[0:len(takeout)] == takeout):
line = line[len(takeout):]
# key is in the part after , and value is before
if(headers_found):
definition = line.split(", ")
# if there are not enough values or too many, then line is assumed to be
# end of the parts with message headers
if(len(definition)!=2):
end_headers = True
break
# sets the key to equal the message header
dict[int(definition[1])] = definition[0]
elif(line[0:len(start_of_values)+3]=="// " + start_of_values):
# the string that is found is what symbolizes when message headers begin on
# next line
headers_found = True
# when the headers end do not care about anything else so breaks
if(end_headers):
break
return dict

mid_to_str = create_bit_to_str("RBSM Headers", "RBSM_MID_")
eid_to_str = create_bit_to_str("Error Message Bits", "RBSM_EID_")

def redraw(state):
screen = state["screen"]
Expand All @@ -70,10 +92,33 @@ def redraw(state):
message_cache[mid]["update_time"])
screen.addstr(row_id, 2, s)

# with open('someshit.txt', 'at') as f:
# f.write(s + "\n")

row_id = row_id + 1

#adding space and then error
screen.addstr(row_id, 2, "")
screen.addstr(row_id+1, 2, "--------ERRORS---------")
# since last steps went through 2 rows adding 2 to row_id
row_id = row_id + 2
# finds which value is error
error = 254
for key in mid_to_str.keys():
if(mid_to_str[key]=="ERROR"):
error = key
# check if key is even in message_cache
if(error in message_cache.keys()):
error_message = message_cache[error]["data"]
# max bit that has associated error
maxBit = max(eid_to_str.keys())
for bit in xrange(maxBit+1):
if(error_message%2==1 and bit in eid_to_str.keys()):
wipeScreenAndPost(screen, eid_to_str[bit], row_id)
row_id = row_id + 1
# can eliminate previous bit by diving by 2
error_message = error_message/2
# adding -- so that if there is nothing between error and this then no error
wipeScreenAndPost(screen, "------------------------", row_id)
# to make sure row below BottomLine clean:
wipeScreenAndPost(screen, "", row_id+1)


# update status line
Expand All @@ -86,6 +131,10 @@ def redraw(state):

screen.refresh()

def wipeScreenAndPost(screen, str, pos):
# long empty space to wipe line clean
screen.addstr(pos, 2, " ")
screen.addstr(pos, 2, str)

def rbsm_worker(state):
message_cache = state["message_cache"]
Expand Down Expand Up @@ -152,8 +201,6 @@ def command_worker(state):
# standard ascii characters
elif(new_char < 128) and len(state["command_line"]) < INPUTUPPERBOUND:
state["command_line"] += chr(new_char)
with open('someshit.txt', 'at') as f:
f.write(state["command_line"])

# redraw(state)

Expand Down
5 changes: 4 additions & 1 deletion real_time/rbsm_config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//
// note for maintaining this file:
// before each set of values and keys, put "// name of category"
// example: "// RBSM Headers"
// this format is required by offline/debugging/rbsm_console.py (l.74)

// RBSM Headers
RBSM_MID_ENC_TICKS_RESET, 1
Expand Down

0 comments on commit fa102c6

Please sign in to comment.