UofSSpaceTeam / roveberrypy

Software for the Rover 2014-2016
Educational Community License v2.0
3 stars 0 forks source link

Changed rover mesages from dictionary to named tuple #57

Closed ottopasuuna closed 7 years ago

ottopasuuna commented 7 years ago

I thought that implementing rover messages as dictionaries was not optimal as a message only has one key and one data element. Finding what the message's key is is awkward, and makes things like message routers (like the USBServer) anoying to implement. I changed messages to be a named tuple, which is in the standard python collections library and is like a regular tuple, but you can access the elements by name.

Example:

 my_message = RoverMessage("TestKey", [1, 2, 3])
 my_message[0] == my_message.key # True
 my_message[1] == my_message.data # True

Note that you never have to create instances of RoverMessage. This is done by the RoverProcess class. You only have to make sure you access message elements properly in message trigger methods.

List of changes: