-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat: TO_<NUM>
library functions
#1334
Changes from 4 commits
7fd83b6
3a68ecd
140297b
51da74a
4082459
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
f = open("to_x.txt", "w") | ||
|
||
types = [ | ||
"SINT", | ||
"USINT", | ||
"INT", | ||
"UINT", | ||
"DINT", | ||
"UDINT", | ||
"LINT", | ||
"ULINT", | ||
"LREAL", | ||
"REAL", | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we are missing quite a few types here, i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have to check what CodeSys supports here, but |
||
|
||
template = """(******************** | ||
* | ||
* Converts any other numerical value to {0} | ||
* | ||
*********************) | ||
FUNCTION TO_{0}<T: ANY_NUM> : {0} | ||
VAR_INPUT | ||
in : T; | ||
END_VAR | ||
END_FUNCTION | ||
|
||
""" | ||
|
||
src = """(******************** | ||
* | ||
* Converts {0} to {1} | ||
* | ||
*********************) | ||
FUNCTION TO_{1}__{0} : {1} | ||
VAR_INPUT | ||
in : {0}; | ||
END_VAR | ||
|
||
TO_{1}__{0} := {0}_TO_{1}(in); | ||
END_FUNCTION | ||
|
||
""" | ||
|
||
src_same = """(******************** | ||
* | ||
* Converts {0} to {1} | ||
* | ||
*********************) | ||
FUNCTION TO_{1}__{0} : {1} | ||
VAR_INPUT | ||
in : {0}; | ||
END_VAR | ||
|
||
TO_{1}__{0} := in; | ||
END_FUNCTION | ||
|
||
""" | ||
|
||
for type_a in types: | ||
f.write(template.format(type_a)) | ||
for type_b in types: | ||
if type_a == type_b: | ||
f.write(src_same.format(type_b, type_a)) | ||
else: | ||
f.write(src.format(type_b, type_a)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to keep these generative scripts around? I think they've served their purpose and there is no need to track them via git/keep them in our sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo it doesn't hurt to track them in case anything changes in the future where we have to regenerate the ST files but I'm also fine with deleting them. Which one do you prefer?