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

ENH: check PLC OS to set new default dir for BSD PLCs #215

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

ZLLentz
Copy link
Member

@ZLLentz ZLLentz commented Mar 22, 2024

Description

Use the IPCDiag FBs to check the PLC's OS, then use that OS to decide the default directory for pmpsdb reading.
These function blocks are somewhat strange, but I followed the docs closely and arrived at this implementation.

Here, I've set the new default directory for TwinCAT BSD PLCs to match the associated PRs:
pcdshub/twincat-bsd-ansible#19
pcdshub/pmpsdb_client#25

And I've left the default directory for other PLC types unchanged.

Motivation and Context

We can explicitly set a directory for the PMPS database loading in each project, but this leaves open the possibility for typos and copy/paste errors. The directory should be the same every time (dependent on OS), so we can directly check the OS to set a reasonable default. The code is skipped entirely if the user provides a directory.

How Has This Been Tested?

Interactively on a BSD PLC: the correct directory was checked and the file was opened. (plc-tst-bsd2)
Also checked on a Windows CE PLC, test suite passed and default directory was ftp (plc-tst-proto8, plc-tst-pmps-subsytem-b)

Tested again after adding some error handling, seemed to do the right thing

Where Has This Been Documented?

https://confluence.slac.stanford.edu/display/PCDS/TcBSD+Configuration+Reference#TcBSDConfigurationReference-PMPSDatabase

Pre-merge checklist

  • Code works interactively
  • Test suite passes locally
  • Code contains descriptive comments
  • Libraries are set to Always Newest version (Library, *)
  • Committed with pre-commit or ran pre-commit run --all-files

@ZLLentz
Copy link
Member Author

ZLLentz commented Mar 22, 2024

I will run the unit tests right now, but I won't test the Windows CE PLC until Monday. When I'm in the office it will be more straightforward to avoid conflicts.

If it works on Windows CE then I'll be confident to mark as ready for review and ask for reviewers next week.

@ZLLentz
Copy link
Member Author

ZLLentz commented Mar 22, 2024

This doesn't brick the test suite, but also I didn't expand the test suite here because I wasn't sure if there was anything meaningful to do. The only test I can think of is a sort of "reflexive" test where I duplicate the logic in the test suite and make sure its being followed but this doesn't have very much value in my opinion.

@ZLLentz
Copy link
Member Author

ZLLentz commented Mar 25, 2024

I think this is done, looking for opinions on the direction + code review + suggestions on some sort of useful unit test I can add

@ZLLentz ZLLentz marked this pull request as ready for review March 25, 2024 18:11
eParameterKey:=E_IPCDiag_ParameterKey.OS_Name,
fbRegister:=fbIPCReg,
);
IF fbCheckOS.bValid THEN
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this includes a check for error, but if there is an error, we won't be flagged.

Copy link
Member Author

@ZLLentz ZLLentz Mar 25, 2024

Choose a reason for hiding this comment

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

Good catch. You're right, as-written if we have an error the JSON file will silently never try to load and we might not notice an issue until we check the PMPS diagnostic.

This warrants some revision.

Copy link
Member Author

Choose a reason for hiding this comment

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

Some options that I'm tossing around right now:

  • If there's an error, try again? (a few times?)
  • Go back to the old default?
  • Give an error log message?
  • Fast fault?

Needs some thought

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'm going to opt for 3 tries followed by going back to the old default
This gives us some wiggle room for first-cycle-bs and will give us some normal error messages if the old default was wrong and if the old default was correct then the PLC will load values as normal.

Copy link
Contributor

@nrwslac nrwslac Apr 15, 2024

Choose a reason for hiding this comment

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

I think this means, if the OS isn't solved and a twincat BSD PLC gets the default directory, fbPmpsFileReader will throw a directory not found error.

@ZLLentz
Copy link
Member Author

ZLLentz commented Apr 12, 2024

I'm going to click update branch and re-request reviews here, I forgot about this PR until I checked my jira tickets.

@ZLLentz ZLLentz requested review from nrwslac, ghalym and NSLentz and removed request for ghalym and NSLentz April 12, 2024 21:26
Copy link
Contributor

@nrwslac nrwslac left a comment

Choose a reason for hiding this comment

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

lgtm.

@ZLLentz
Copy link
Member Author

ZLLentz commented Apr 22, 2024

I'm going to merge and release this if there are no objections from @ghalym and @NSLentz prior to midday tomorrow

Copy link
Contributor

@NSLentz NSLentz left a comment

Choose a reason for hiding this comment

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

lgtm

@ZLLentz ZLLentz merged commit db6ce93 into pcdshub:master Apr 24, 2024
9 checks passed
@ZLLentz ZLLentz deleted the enh_bsd_pmpsdb branch April 24, 2024 21:39
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.

3 participants