Port of new comms protocol from Makera Controller 0.9.12#341
Port of new comms protocol from Makera Controller 0.9.12#341SergeBakharev wants to merge 2 commits intodevelopfrom
Conversation
| if not app.playing and (not self.echosended) and (not self.echosending): | ||
| try: | ||
| if self.controller.stream: | ||
| self.echosending = True | ||
| self.controller.stream.send(b'echo echo\n') | ||
| echo = self.controller.stream.getc(10) | ||
| if echo == b'echo: echo': | ||
| self.message_popup.lb_content.text = tr._('Firmware version mismatch! \nPlease use a Controller with version V0.9.11 or earlier \nto upgrade the firmware to V1.0.4.') | ||
| self.message_popup.btn_ok.disabled = False | ||
| self.message_popup.open(self) | ||
| return | ||
| self.echosended = True | ||
| except: | ||
| print(sys.exc_info()[1]) |
There was a problem hiding this comment.
We have better ways of checking the firmware version since we directly have app.is_community_firmware and app.fw_version_digitized
Please replace for something easier to read that uses those two app attributes.
| curr_dir = os.path.join(sandbox_documents_path, 'gcodes') | ||
| local_path = os.path.join(os.path.dirname(curr_dir), remote_post_path) | ||
| else: # inserted | ||
| local_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), remote_post_path) |
There was a problem hiding this comment.
Unlike Makera our controller actually uses temp directories:
Please continue to use local_path = os.path.join(self.temp_dir, remote_post_path)
| #md5 = Utils.md5(self.uploading_file) | ||
| md5 = Utils.md5(displayname) | ||
| self.controller.uploadCommand(os.path.normpath(remotename)) | ||
| time.sleep(0.2) |
There was a problem hiding this comment.
This is arbitrary. Some time needs to be given for the machine decompress the file but it shouldn't be a fixed 0.2s.
| md5 = Utils.md5(tmp_filename) | ||
| self.controller.downloadCommand(self.downloading_file) | ||
| self.controller.pauseStream(0.2) | ||
| self.controller.pauseStream(0.0) |
There was a problem hiding this comment.
What does this do
| if kivy_platform == 'ios': | ||
| import tempfile | ||
| tmp_file = tempfile.gettempdir() | ||
| config_path = os.path.join(tmp_file, 'config.txt') | ||
| else: # inserted | ||
| config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config.txt') |
There was a problem hiding this comment.
Unlike makera we use temp directories, so this conditional business is not required. Please revert to config_path = os.path.join(self.temp_dir, 'config.txt')
| if kivy_platform == 'ios': | ||
| import tempfile | ||
| tmp_file = tempfile.gettempdir() | ||
| app.selected_local_filename = os.path.join(tmp_file, 'config.txt') | ||
| else: # inserted | ||
| app.selected_local_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config.txt') |
| local_path = join(expanduser('~'), 'Documents') | ||
| local_path = join(local_path, remote_post_path) | ||
| else: # inserted | ||
| local_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), remote_post_path) |
There was a problem hiding this comment.
Should use our version local_path = os.path.join(self.temp_dir, remote_post_path)
| echosended = False | ||
| echosending = False |
There was a problem hiding this comment.
This is used for some reason by makera as a way of version checking. Per cda5887#r2289714852 We have a better way. Please remove it.
| size = None | ||
|
|
||
| print(('putc(', repr(data), repr(size), ')')) | ||
| print(("putc(", repr(data), repr(size), ")")) |
There was a problem hiding this comment.
No print statements for debugging please. Use logger.debug()
| data = None | ||
|
|
||
| print(('getc(', repr(data), ')')) | ||
| print(("getc(", repr(data), ")")) |
There was a problem hiding this comment.
| __author__ = 'Wijnand Modderman <maze@pyth0n.org>' | ||
| __copyright__ = ['Copyright (c) 2010 Wijnand Modderman', | ||
| 'Copyright (c) 1981 Chuck Forsberg'] | ||
| __license__ = 'MIT' | ||
| __version__ = '0.4.5' |
There was a problem hiding this comment.
Let's not remove the acknowledgement to the original author
|
|
||
| ''' | ||
|
|
||
| # crctab calculated by Mark G. Mendel, Network Systems Corporation |
There was a problem hiding this comment.
Let's not remove the acknowledgement to the original author
| def download(self, filename, local_md5, callback): | ||
| stream = open(filename, 'wb') | ||
| result = self.modem.recv(stream, md5 = local_md5, retry = 10, callback = callback) | ||
| result = self.modem.recv(stream, md5=local_md5, retry=50, callback=callback) |
There was a problem hiding this comment.
... 50 retries seems excessive. Users will think the app is broken if it spends this much time retrying. Let's continue using the original value of 10, or maybe even reduce it to 3.
| # do upload | ||
| stream = open(filename, 'rb') | ||
| result = self.modem.send(stream, md5 = local_md5, retry = 10, callback = callback) | ||
| result = self.modem.send(stream, md5=local_md5, retry=50, callback=callback) |
There was a problem hiding this comment.
| self.t = None | ||
| self.tr = None | ||
|
|
||
| return |
There was a problem hiding this comment.
init methods does not explicitly return a value. Its purpose is to initialize the attributes of a newly created object, not to produce a return value for assignment.
| UDP_PORT = 3333 | ||
| BUFFER_SIZE = 1024 | ||
| SOCKET_TIMEOUT = 0.3 # s | ||
| SOCKET_TIMEOUT = 5 |
There was a problem hiding this comment.
The comment that this is in seconds is useful. Often high speed actions like this are measured in milliseconds
| try: | ||
| self.socket = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM) | ||
| ip_port = address.split(':') | ||
| self.socket.settimeout(3) |
There was a problem hiding this comment.
Eh? Whats the point of defining SOCKET_TIMEOUT as 5 if it's not even used.
| ip_port = address.split(':') | ||
| self.socket.settimeout(3) | ||
| self.socket.connect((address.split(':')[0], int(address.split(':')[1]) if len(ip_port) > 1 else TCP_PORT)) | ||
| self.socket.settimeout(SOCKET_TIMEOUT) |
There was a problem hiding this comment.
I'm confused. Why set a socket timeout after the connection?
There was a problem hiding this comment.
It's a bit weird that one of the changes here is to convert values that were previously in hex to base-10. The convention for most low level protocol work is in hex. It does not harm, just makes the file changes look more than it really is.
SergeBakharev
left a comment
There was a problem hiding this comment.
There is a lot of iOS related changes here, that I'm not comfortable commenting on. I don't know if they conflict with the existing stuff written by @zittix or not. I don't like the idea of taking in code changes from Makera without verifying them, so I would prefer to drop all the iOS changes.
I see some re-occuring issues:
- Makera is using some inane way of testing the firmware version for some reason with
controller.echosendingWe shouldn't propagate that when we already do better with our ownMakeraApp.is_community_firmwareandMakeraApp.fw_version_digitized - We use a temp_directory for temporary files but Makera is saving the files directly next to the controller executable. We should continue to use
MakerApp.temp_dir
A point of discussion: This change is breaking, are we okay with that? Previous versions of firmware will not be supported. Which is not ideal but I'm okay with. We should however make it clear in our messaging the order that the updates should be applied: First new firmware uploaded with previous controller version before using the new controller.
Sorry I wrote my previous comments while looking at a specific commit so I wasn't able to directly suggest code changes.
|
We should put this PR on ice. Makera have pulled 0.9.12 because it's got some critical bugs. I worry that those bugs are protocol design related. |
|
IMHO we should keep backward compatibility at least during one controller version to allow people to upgrade/downgrade to avoid things like Makera is doing "please first use that version to upgrade then upgrade to that one". |
No description provided.