Skip to content

Commit

Permalink
Fixes bug on serial_message_container
Browse files Browse the repository at this point in the history
Enhances documentation
  • Loading branch information
cajomferro committed Jan 19, 2017
1 parent 5488016 commit a494147
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 28 deletions.
9 changes: 5 additions & 4 deletions docs/source/api_reference/com/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**********************
Communication Protocol
**********************
*************
Communication
*************

Contents:

Expand All @@ -10,4 +10,5 @@ Contents:
protocol
message_headers
arcom
hw_info_container
hw_info_container
serial_message_container
6 changes: 3 additions & 3 deletions docs/source/api_reference/com/protocol.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=================
Protocol Commands
=================
===========================
Requesting Commands to Bpod
===========================

.. contents:: Contents
:local:
Expand Down
24 changes: 24 additions & 0 deletions docs/source/api_reference/com/serial_message_container.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
========================
Serial Message Container
========================

.. contents:: Contents
:local:

--------
Overview
--------

This container is used to store serial message information.

.. seealso::
:meth:`pybpodapi.com.protocol.Protocol.load_serial_message`

--------------
Implementation
--------------


.. autoclass:: pybpodapi.com.serial_message_container.SerialMessageContainer
:members:
:private-members:
5 changes: 3 additions & 2 deletions docs/source/api_reference/hardware/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Hardware description
====================
********
Hardware
********

Contents:

Expand Down
10 changes: 5 additions & 5 deletions docs/source/api_reference/model/bpod.rst
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
.. _bpod-class-label:

****
====
Bpod
****
====

.. contents:: Contents
:local:

Overview
========
--------

TODO

Implementation
==============
--------------


.. automodule:: pybpodapi.model.bpod
.. autoclass:: pybpodapi.model.bpod.Bpod
:members:
:private-members:
7 changes: 4 additions & 3 deletions docs/source/api_reference/model/index.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Entities Model
==============
********
Entities
********

Contents:

.. toctree::
:maxdepth: 2
:maxdepth: 4

bpod
state_machine
Expand Down
11 changes: 5 additions & 6 deletions docs/source/api_reference/model/session.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
*******
=======
Session
*******
=======

.. contents:: Contents
:local:

Overview
========
--------

TODO

Implementation
==============
--------------


.. automodule:: pybpodapi.model.session
.. autoclass:: pybpodapi.model.session.Session
:members:
:private-members:
5 changes: 4 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@
'sphinx.ext.todo',
'sphinx.ext.viewcode']

# Do not sort autodoc alphabetically, use source code appearance order
# Do not sort autodoc alphabetically, use source code appearance order.
autodoc_member_order= 'bysource'

# Both the class’ and the __init__ method’s docstring are concatenated and inserted.
autoclass_content = 'both'

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Welcome to pybpod-api's documentation!
All examples and Bpod's state machine and communication logic were based on the original version made available by `Josh Sanders (Sanworks) <https://github.com/sanworks>`_.

.. toctree::
:maxdepth: 2
:maxdepth: 4

getting_started
writing_protocols
Expand Down
14 changes: 11 additions & 3 deletions pybpodapi/com/serial_message_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ class SerialMessageContainer(object):
"""

def __init__(self, serial_channel, message_ID, serial_message, n_messages=1):
"""
:param int serial_channel: UART port to trigger
:param int message_ID: byte parameter that triggers UART port
:param list(int) serial_message: 3-byte message to send to UART port
:param n_messages: TODO
"""

if len(serial_message) > 3:
raise SerialMessageContainerError('Error: Serial messages cannot be more than 3 bytes in length.')

if message_ID > 255 or message_ID < 1:
raise SerialMessageContainerError('Error: Bpod can only store 255 serial messages (indexed 1-255).')

self.serial_channel = serial_channel - 1 # type: int
self.message_ID = message_ID # type: int
self.serial_channel = serial_channel - 1 # type: int
self.message_ID = message_ID # type: int
self.serial_message = serial_message
self.n_messages = n_messages

Expand All @@ -30,7 +37,8 @@ def format_for_sending(self):
:rtype: list(int)
"""
return [self.serial_message - 1, self.n_messages, self.message_ID, len(self.serial_message)] + self.serial_message
return [self.serial_channel, self.n_messages, self.message_ID, len(self.serial_message)] + self.serial_message


class SerialMessageContainerError(Exception):
pass

0 comments on commit a494147

Please sign in to comment.