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

Use inp/out links for mapping terminals #44

Merged
merged 10 commits into from
Jun 28, 2023
Merged

Conversation

JJL772
Copy link
Member

@JJL772 JJL772 commented Jun 20, 2023

This ended up being a sizable refactor, but ultimately fixes the biggest issue with the module. Previously record -> terminal mapping was determined by ek9000ConfigureTerminal and a numeric suffix on the record name. Now it's done entirely using an inp/out link in the INST_IO format, similar to how asyn does it.

The legacy logic still exists in the module, not sure if I should keep it around or axe it entirely though.

Some other changes made here:

  • Changed lock/unlock calls to go through a safe RAII mutex wrapper. This ensures we don't forget to unlock a mutex in branchy code.
  • Changed devEK9000 to derive directly from drvModbusAsyn, as it should've in the first place
  • Fixed a couple memory leaks due to strdup calls I missed during an earlier refactor
  • Started refactoring logging so it's not a mess (and less spammy)

Still a draft for now until I decide what to do with the legacy paths. Also haven't regenerated the DB templates yet, just to make it easier to review :)

@JJL772 JJL772 requested review from klauer and mcb64 June 20, 2023 23:15
@JJL772
Copy link
Member Author

JJL772 commented Jun 22, 2023

Going to mark this as ready now. Once approved (or mostly approved) I'll regenerate the templates

@JJL772 JJL772 marked this pull request as ready for review June 22, 2023 23:05
Copy link
Collaborator

@klauer klauer left a comment

Choose a reason for hiding this comment

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

I like that this moves to more standard EPICS INP/OUT string handling - not requiring record names to conform and still retaining back-compatibility.

I didn't fully dig into the logic as much as I'd like to, but the methodology seems solid enough to me 👍

: drvModbusAsyn(portName, octetPortName, 0, 2, -1, 256, dataTypeUInt16, 150, "") {

/* Initialize members */
m_terms = static_cast<devEK9000Terminal*>(malloc(sizeof(devEK9000Terminal) * termCount));
Copy link
Collaborator

Choose a reason for hiding this comment

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

For my own information, why the mix of malloc/free and not just use new[] operator to allocate all terminals?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was confused at my own code here too, but I just remembered: new[] requires a default constructible type, which devEK9000Terminal is not because its constructor takes a parameter.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll probably make m_terms a std::vector<devEK9000Terminal*> instead- just realized that the destructor is not being called on any devEK9000Terminals because the array is simply being freed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I see. I like the std::vector approach much better 👍

ek9000App/src/devEK9000.cpp Show resolved Hide resolved
@JJL772 JJL772 requested a review from klauer June 28, 2023 18:07
Copy link
Collaborator

@klauer klauer left a comment

Choose a reason for hiding this comment

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

Looks good to me. Onto regenerating the database files in a follow-up PR?

Also clamp num terminals to <= 0xFF in ek9000Register
@JJL772
Copy link
Member Author

JJL772 commented Jun 28, 2023

I'll do that right now!

@klauer
Copy link
Collaborator

klauer commented Jun 28, 2023

Yep, seeing this in database form reinforces my opinion that it's a good change 👍

@JJL772 JJL772 merged commit 0e22e52 into slac-epics:master Jun 28, 2023
@JJL772 JJL772 deleted the enh_links branch June 28, 2023 18:56
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.

2 participants