-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial developments for cubiscan #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, nothig shocked me.
I'm not available to say if it's good or not.
Maybe if you can add comments and docstring to help to understand what you do in all places of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use i18n file to provide translation possibility ?
Please add the card number in the PR 😉
|
||
def get_error(value): | ||
value_str = decode(value) | ||
if value_str == 'C': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for all check no need to do
if value_str == 'C': | |
if upper(value_str) == 'C': |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The Documentation of this thing specified that we either get C, M, Z we really shouldn't get anything else. If we get small letters then something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for answer \o/
Can you put this information in the method description ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks good.
Thanks for the test cov :)
README.rst
Outdated
CUBISCAN | ||
======== | ||
|
||
Provides an interface to a cubiscan machine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a link to https://cubiscan.com/ and mention briefly what we are talking about
self.response_mappings[name] = (response, neg_response) | ||
|
||
def build_command_string(self, name, params=None): | ||
"""Wrap command and params with the base stuff arround it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth to mention here the schema of the command as reported on the docs.
<STX><COMMANDE><DONNÉES><ETX><CR><LF>
+ ACK/NACK variants, etc
self.add_command('weight_unit', bytes('#', 'ascii'), [], []) | ||
self.add_command('zero', bytes('Z', 'ascii'), [], []) | ||
|
||
def add_command(self, name, command_bit, response, neg_response): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just asking: do you really need this? The list of commands seems pretty static. You could simply have a mapping for commands and a mapping for response, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured that another version might have more commands. Also i excluded the ones to change ip, subnetmask and gateway since it can stop you from having access to the device. but someone might want it anyway but otherwise yes i could just have a mapping.
cubiscan/cubiscan.py
Outdated
command_string = get_command_registry().build_command_string( | ||
command, param | ||
) | ||
conn = socket.create_connection((self.ip_address, self.port)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to have a ctx manager
res_dict = {} | ||
# we split the response by commata because they arent interesting but | ||
# they split the response for dimensions etc | ||
sections = data.split(bytes(',', 'ascii')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems we can have numbers w/ commas. Am I wrong? If not, is this ok here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the command table floats are seperated by . not by , so yes it is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine
return self._make_request('set_factor', param) | ||
|
||
def set_location(self, location): | ||
if len(location) < 6: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any comment?
return self._make_request('measure') | ||
|
||
def calibrate_scale(self, weight): | ||
if not weight > 50 and weight < 100: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
tests/test_parse_response.py
Outdated
|
||
|
||
def test_parse_positive_measure_response(): | ||
scanner_obj = CubiScan('127.0.0.1', '1234') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scanner obj is always the same, you could define it globally or define a unit test case
@simahawk updated the pr. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor glitches but seems good. Also we'll need more time to adjust it by running it against the real device so it's pointless to be nitpicking for this 1st version :)
CUBISCAN | ||
======== | ||
|
||
Provides an interface to a cubiscan devices (https://cubiscan.com/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*to cubiscan devices
"""Wrap command and params with the base stuff arround it. | ||
""" | ||
# All commands always have the following format | ||
# <STX><COMMAND><DATA><ETX><CR><LF> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the meaning of each block? 👨🏫
res_dict = {} | ||
# we split the response by commata because they arent interesting but | ||
# they split the response for dimensions etc | ||
sections = data.split(bytes(',', 'ascii')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine
def _parse_response(self, command, data): | ||
"""Parse the response.""" | ||
mapping, neg_mapping = get_command_registry().get_response_for(command) | ||
used_map = mapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-reading: you only need a reference, fine :)
@jcoux @Tonow-c2c @simahawk this pr got closed accidentally when i pushed the wrong remote so i opened #2 if there is more discussion |
No description provided.