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

Davkim add el6001 #71

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open

Davkim add el6001 #71

wants to merge 41 commits into from

Conversation

davidinkyu-kim
Copy link
Contributor

Added jsd_el6001 driver

Copy link
Contributor

@alex-brinkman alex-brinkman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution David!

  • Consider simplifying the Rx/TxPDOs to use a uint8_t[22] for ease of use.
  • Consider modifying the write functions to accept an array up to 22 bytes rather than specifying a specific index in the array - this feels error prone and awkward to me.
    • Multiple writes would append data up to the cap of 22 bytes

Comment on lines 46 to 50
int jsd_el6001_set_transmit_data_8bits(jsd_t* self, uint16_t slave_id, int byte, uint8_t value);

int jsd_el6001_request_transmit_data(jsd_t* self, uint16_t slave_id, int num_bytes_to_transmit);

int jsd_el6001_set_persistent_transmit_data(jsd_t* self, uint16_t slave_id, int num_bytes_to_transmit, bool state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document these interfaces.

I'd expect you to have API write function of the form:

write(..., const char* data, size_t data_length)
// or possibly
write(..., const uint8_t* data, size_t data_length)

In the same flavor has memcpy, memset, or strncpy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this functionality as fastcat level command, wonder that would be sufficient.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that function calls this function up to 22 times? Why?

src/jsd_el6001_types.h Show resolved Hide resolved
src/jsd_el6001_types.h Show resolved Hide resolved
@alex-brinkman
Copy link
Contributor

@davidinkyu-kim What is the status of this driver - is it ready to do a final round of testing and merge or should we take it back to draft status?

@davidinkyu-kim
Copy link
Contributor Author

I think we are pending on loopback test: to test Tx/Rx latency, which would be not critical at the moment.
Would it be okay to be merge the current, and add/test loopback later to be minor revision?

@alex-brinkman
Copy link
Contributor

Let's wait until the loopback test can be completed to merge, else it may get forgotten. Do you need help with it? If you can help me find a spare EL6001 module, I'll offer to test it.

@davidinkyu-kim davidinkyu-kim requested a review from a team as a code owner June 28, 2023 18:37
@davidinkyu-kim
Copy link
Contributor Author

@alex-brinkman loopback test has been done. Confirmed that we can transmit/receive at one loop cycle persistently.

// Set for user to know number of bytes received
state->num_bytes_received = num_bytes_received;

return ok ? 0 : -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable, "ok," is never false. Is that okay?

JSD_EL6001_DATA_OUT_BYTE_21,
JSD_EL6001_NUM_PDO_ENTRIES_OUTPUT,

} jsd_el6001_rxpdo_entries_t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is used anywhere in the final version, omit

Comment on lines 46 to 50
int jsd_el6001_set_transmit_data_8bits(jsd_t* self, uint16_t slave_id, int byte, uint8_t value);

int jsd_el6001_request_transmit_data(jsd_t* self, uint16_t slave_id, int num_bytes_to_transmit);

int jsd_el6001_set_persistent_transmit_data(jsd_t* self, uint16_t slave_id, bool is_persistent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document these.

Why is there no function akin to memcpy with an array of uint8_t and n_bytes? for example,

bool jsd_el6001_write(jsd_t* self, uint8_t* data_in, size_t data_len);

jsd_el6001_sms_t sms;
jsd_el6001_transmit_sms_t transmit_state;

} jsd_el6001_state_t;
Copy link
Contributor

@alex-brinkman alex-brinkman Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is in the public API, it needs to be explained better. As a causal user, I don't know how to read this and get my data out of the returned state struct without digging into the implementation.

in the EGD class, I introduced a notion of public and private state (to help shield the public interface from unnecessary cruft) Could that pattern be employed here perhaps?

consider adding an fread-like function to return validated user data.

* @param slave_id Slave ID of EL6001 device
* @return Pointer to EL6001 device state
*/
const jsd_el6001_state_t* jsd_el6001_get_state(jsd_t* self, uint16_t slave_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider offering an fread like interface where the user passes a buffer to copy the recv data into.

@alex-brinkman
Copy link
Contributor

I don't understand what is meant by persistence in the transmit cycle, can you explain that? This is probably related to the jsd_el6001_set_persistence_data API call.

@davidinkyu-kim
Copy link
Contributor Author

Persistent transmit can be set on public function call, making terminal to persistently send out current outgoing buffer every cycle.
If not set, jsd_el6001 internal state machine will cycle between TRANSMIT_REQUEST_FROM_USER and TRANSMIT_CONFIRMATION, which will take 2 cycles per 1 packet transmission.
If set, jsd_el6001 state machine will hang in TRANSMIT_REQUEST_FROM_USER and skip the confirmation of transmission, enabling the device to send out the packet every control loop cycle.

@davidinkyu-kim
Copy link
Contributor Author

@alex-brinkman Thank you for the feedback. I've pushed few commits, would appreciate if you can review them.

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.

4 participants