Skip to content
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

Merged
merged 7 commits into from
Jul 9, 2019
Merged

Conversation

tschanzt
Copy link

@tschanzt tschanzt commented Jul 4, 2019

No description provided.

@jcoux jcoux changed the title Inital developments for cubiscan Initial developments for cubiscan Jul 8, 2019
Copy link
Member

@jcoux jcoux left a 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.

Copy link

@Tonow-c2c Tonow-c2c left a 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':

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

Suggested change
if value_str == 'C':
if upper(value_str) == 'C':

?

Copy link
Author

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.

Copy link

@Tonow-c2c Tonow-c2c Jul 8, 2019

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 ?

Copy link
Member

@simahawk simahawk left a 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.
Copy link
Member

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.
Copy link
Member

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):
Copy link
Member

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?

Copy link
Author

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 Show resolved Hide resolved
command_string = get_command_registry().build_command_string(
command, param
)
conn = socket.create_connection((self.ip_address, self.port))
Copy link
Member

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'))
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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:
Copy link
Member

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:
Copy link
Member

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 Show resolved Hide resolved


def test_parse_positive_measure_response():
scanner_obj = CubiScan('127.0.0.1', '1234')
Copy link
Member

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

@tschanzt
Copy link
Author

tschanzt commented Jul 9, 2019

@simahawk updated the pr.

Copy link
Member

@simahawk simahawk left a 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/).
Copy link
Member

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>
Copy link
Member

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'))
Copy link
Member

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
Copy link
Member

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 :)

@tschanzt tschanzt merged commit b6099ae into camptocamp:master Jul 9, 2019
@tschanzt
Copy link
Author

@jcoux @Tonow-c2c @simahawk this pr got closed accidentally when i pushed the wrong remote so i opened #2 if there is more discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants