Compare commits
13 Commits
lift_axis_
...
master
Author | SHA1 | Date | |
---|---|---|---|
354e9d90fb | |||
deea821e3f | |||
7a46788fd5 | |||
9e77eb585c | |||
7e1fc78f76 | |||
9e0d8a4322 | |||
3cccfe930c | |||
8860d0c59f | |||
b6c38be113 | |||
b14b50c25a | |||
477ffdbc0b | |||
0a23ec8f22 | |||
39098fd0d1 |
236
.clang-format
Normal file
236
.clang-format
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: None
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
PadOperators: true
|
||||||
|
AlignConsecutiveBitFields:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveMacros:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveShortCaseStatements:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCaseColons: false
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments:
|
||||||
|
Kind: Always
|
||||||
|
OverEmptyLines: 0
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
|
AttributeMacros:
|
||||||
|
- __capability
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakAfterAttributes: Never
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakArrays: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeConceptDeclarations: Always
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInlineASMColon: OnlyMultiline
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 80
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IfMacros:
|
||||||
|
- KJ_IF_MAYBE
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||||
|
Priority: 3
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 1
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentRequiresClause: true
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
InsertBraces: false
|
||||||
|
InsertNewlineAtEOF: false
|
||||||
|
InsertTrailingCommas: None
|
||||||
|
IntegerLiteralSeparator:
|
||||||
|
Binary: 0
|
||||||
|
BinaryMinDigits: 0
|
||||||
|
Decimal: 0
|
||||||
|
DecimalMinDigits: 0
|
||||||
|
Hex: 0
|
||||||
|
HexMinDigits: 0
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
KeepEmptyLinesAtEOF: false
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
LineEnding: DeriveLF
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PackConstructorInitializers: BinPack
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakOpenParenthesis: 0
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
PointerAlignment: Right
|
||||||
|
PPIndentWidth: -1
|
||||||
|
QualifierAlignment: Leave
|
||||||
|
ReferenceAlignment: Pointer
|
||||||
|
ReflowComments: true
|
||||||
|
RemoveBracesLLVM: false
|
||||||
|
RemoveParentheses: Leave
|
||||||
|
RemoveSemicolon: false
|
||||||
|
RequiresClausePosition: OwnLine
|
||||||
|
RequiresExpressionIndentation: OuterScope
|
||||||
|
SeparateDefinitionBlocks: Leave
|
||||||
|
ShortNamespaceLines: 1
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
SortJavaStaticImport: Before
|
||||||
|
SortUsingDeclarations: LexicographicNumeric
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeJsonColon: false
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: true
|
||||||
|
AfterForeachMacros: true
|
||||||
|
AfterFunctionDefinitionName: false
|
||||||
|
AfterFunctionDeclarationName: false
|
||||||
|
AfterIfMacros: true
|
||||||
|
AfterOverloadedOperator: false
|
||||||
|
AfterRequiresInClause: false
|
||||||
|
AfterRequiresInExpression: false
|
||||||
|
BeforeNonEmptyParentheses: false
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: Never
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: -1
|
||||||
|
SpacesInParens: Never
|
||||||
|
SpacesInParensOptions:
|
||||||
|
InCStyleCasts: false
|
||||||
|
InConditionalStatements: false
|
||||||
|
InEmptyParentheses: false
|
||||||
|
Other: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Latest
|
||||||
|
StatementAttributeLikeMacros:
|
||||||
|
- Q_EMIT
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
||||||
|
VerilogBreakBetweenInstancePorts: true
|
||||||
|
WhitespaceSensitiveMacros:
|
||||||
|
- BOOST_PP_STRINGIZE
|
||||||
|
- CF_SWIFT_NAME
|
||||||
|
- NS_SWIFT_NAME
|
||||||
|
- PP_STRINGIZE
|
||||||
|
- STRINGIZE
|
||||||
|
...
|
||||||
|
|
51
.gitlab-ci.yml
Normal file
51
.gitlab-ci.yml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
default:
|
||||||
|
image: docker.psi.ch:5000/wall_e/sinqepics:latest
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- test
|
||||||
|
- build
|
||||||
|
|
||||||
|
cppcheck:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- cppcheck --std=c++17 --addon=cert --addon=misc --error-exitcode=1 sinqEPICSApp/
|
||||||
|
allow_failure: true # Long term this needs to be removed
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
formatting:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- clang-format --style=file --Werror --dry-run sinqEPICSApp/src/*.cpp sinqEPICSApp/src/*.c sinqEPICSApp/src/*.h
|
||||||
|
allow_failure: true # Long term this needs to be removed
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
# clangtidy:
|
||||||
|
# stage: test
|
||||||
|
# script:
|
||||||
|
# - curl https://docker.psi.ch:5000/v2/_catalog
|
||||||
|
# # - dnf update -y
|
||||||
|
# # - dnf install -y clang-tools-extra
|
||||||
|
# # - clang-tidy sinqEPICSApp/src/*.cpp sinqEPICSApp/src/*.c sinqEPICSApp/src/*.h -checks=cppcoreguidelines-*,cert-*
|
||||||
|
# # tags:
|
||||||
|
# # - docker
|
||||||
|
|
||||||
|
build_module:
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- sed -i 's/ARCH_FILTER=.*/ARCH_FILTER=linux%/' Makefile.RHEL8
|
||||||
|
- make -f Makefile.RHEL8 install
|
||||||
|
- cp -rT "/ioc/modules/sinq/$(ls -U /ioc/modules/sinq/ | head -1)" "./sinq-${CI_COMMIT_SHORT_SHA}"
|
||||||
|
artifacts:
|
||||||
|
name: "sinq-${CI_COMMIT_SHORT_SHA}"
|
||||||
|
paths:
|
||||||
|
- "sinq-${CI_COMMIT_SHORT_SHA}/*"
|
||||||
|
expire_in: 1 week
|
||||||
|
when: always
|
||||||
|
tags:
|
||||||
|
- docker
|
@ -4,7 +4,7 @@ include /ioc/tools/driver.makefile
|
|||||||
MODULE=sinq
|
MODULE=sinq
|
||||||
BUILDCLASSES=Linux
|
BUILDCLASSES=Linux
|
||||||
EPICS_VERSIONS=7.0.7
|
EPICS_VERSIONS=7.0.7
|
||||||
ARCH_FILTER=RHEL%
|
ARCH_FILTER=RHEL8%
|
||||||
|
|
||||||
# additional module dependencies
|
# additional module dependencies
|
||||||
REQUIRED+=SynApps
|
REQUIRED+=SynApps
|
||||||
@ -12,13 +12,11 @@ REQUIRED+=stream
|
|||||||
REQUIRED+=scaler
|
REQUIRED+=scaler
|
||||||
REQUIRED+=motorBase
|
REQUIRED+=motorBase
|
||||||
|
|
||||||
# Release version
|
|
||||||
LIBVERSION=2025
|
|
||||||
|
|
||||||
# DB files to include in the release
|
# DB files to include in the release
|
||||||
TEMPLATES += sinqEPICSApp/Db/dimetix.db
|
TEMPLATES += sinqEPICSApp/Db/dimetix.db
|
||||||
TEMPLATES += sinqEPICSApp/Db/slsvme.db
|
TEMPLATES += sinqEPICSApp/Db/slsvme.db
|
||||||
TEMPLATES += sinqEPICSApp/Db/spsamor.db
|
TEMPLATES += sinqEPICSApp/Db/spsamor.db
|
||||||
|
TEMPLATES += sinqEPICSApp/Db/el734.db
|
||||||
|
|
||||||
# DBD files to include in the release
|
# DBD files to include in the release
|
||||||
DBDS += sinqEPICSApp/src/sinq.dbd
|
DBDS += sinqEPICSApp/src/sinq.dbd
|
||||||
|
@ -38,3 +38,12 @@ Those political problems require a special development model:
|
|||||||
Take care of the sinqEPICsApp/src/sinq.dbd file. This is the one which differs mostly between
|
Take care of the sinqEPICsApp/src/sinq.dbd file. This is the one which differs mostly between
|
||||||
amorsim and master branches.
|
amorsim and master branches.
|
||||||
|
|
||||||
|
# Formatting
|
||||||
|
|
||||||
|
Formatting is done via the [`.clang-format`](./.clang-format) file checked into
|
||||||
|
the repository. One option to apply the formatting to a given file is via the
|
||||||
|
command below.
|
||||||
|
|
||||||
|
```
|
||||||
|
clang-format -i -style=file <file>
|
||||||
|
```
|
||||||
|
34
sinqEPICSApp/Db/el734.db
Normal file
34
sinqEPICSApp/Db/el734.db
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
record(motor,"$(P)$(M)")
|
||||||
|
{
|
||||||
|
field(DESC,"$(DESC)")
|
||||||
|
field(DTYP,"$(DTYP)")
|
||||||
|
field(DIR,"$(DIR)")
|
||||||
|
field(VELO,"$(VELO)")
|
||||||
|
field(HVEL,"$(VELO)")
|
||||||
|
field(VBAS,"$(VELO)")
|
||||||
|
field(VMAX, "${VMAX}")
|
||||||
|
field(ACCL,"$(ACCL)")
|
||||||
|
field(BDST,"$(BDST)")
|
||||||
|
field(BVEL,"$(BVEL)")
|
||||||
|
field(BACC,"$(BACC)")
|
||||||
|
field(OUT,"@asyn($(PORT),$(ADDR))")
|
||||||
|
field(MRES,"$(MRES)")
|
||||||
|
field(PREC,"$(PREC)")
|
||||||
|
field(EGU,"$(EGU)")
|
||||||
|
field(DHLM,"$(DHLM)")
|
||||||
|
field(DLLM,"$(DLLM)")
|
||||||
|
field(INIT,"$(INIT)")
|
||||||
|
field(PINI, "NO")
|
||||||
|
field(TWV,"1")
|
||||||
|
field(RTRY,"0")
|
||||||
|
}
|
||||||
|
|
||||||
|
# The message text
|
||||||
|
record(waveform, "$(P)$(M)-MsgTxt") {
|
||||||
|
field(DTYP, "asynOctetRead")
|
||||||
|
field(INP, "@asyn($(PORT),$(N),1) MOTOR_MESSAGE_TEXT")
|
||||||
|
field(FTVL, "CHAR")
|
||||||
|
field(NELM, "80")
|
||||||
|
field(SCAN, "I/O Intr")
|
||||||
|
}
|
||||||
|
|
@ -250,6 +250,8 @@ PhytronAxis::PhytronAxis(PhytronController *pC, int axisNo, int enc)
|
|||||||
haveBrake = 0;
|
haveBrake = 0;
|
||||||
brakeIO = -1;
|
brakeIO = -1;
|
||||||
next_poll = -1;
|
next_poll = -1;
|
||||||
|
homing = 0;
|
||||||
|
homing_direction = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PhytronAxis::setBrake(int brakeNO)
|
int PhytronAxis::setBrake(int brakeNO)
|
||||||
|
@ -114,7 +114,7 @@ typedef struct {
|
|||||||
unsigned int dbInit;
|
unsigned int dbInit;
|
||||||
}EL737priv;
|
}EL737priv;
|
||||||
|
|
||||||
static void dummyAsynCallback([[maybe_unused]] asynUser *pasynUser)
|
static void dummyAsynCallback(asynUser *pasynUser)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
213
utils/decodeMasterMACStatusR10.py
Executable file
213
utils/decodeMasterMACStatusR10.py
Executable file
@ -0,0 +1,213 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# List of tuples which encodes the states given in the file description.
|
||||||
|
# Index first with the bit index, then with the bit value
|
||||||
|
interpretation = [
|
||||||
|
("Not ready to be switched on", "Ready to be switched on"), # Bit 0
|
||||||
|
("Not switched on", "Switched on"), # Bit 1
|
||||||
|
("Disabled", "Enabled"), # Bit 2
|
||||||
|
("Ok", "Fault condition set"), # Bit 3
|
||||||
|
("Motor supply voltage absent ", "Motor supply voltage present"), # Bit 4
|
||||||
|
("Motor performs quick stop", "Ok"), # Bit 5
|
||||||
|
("Switch on enabled", "Switch on disabled"), # Bit 6
|
||||||
|
("Ok", "RWarning: Movement function was called while motor is still moving. The function call is ignored"), # Bit 7
|
||||||
|
("Motor is idle", "Motor is currently moving"), # Bit 8
|
||||||
|
("Motor does not execute command messages (local mode)", "Motor does execute command messages (remote mode)"), # Bit 9
|
||||||
|
("Target not reached", "Target reached"), # Bit 10
|
||||||
|
("Ok", "Internal limit active"), # Bit 11
|
||||||
|
("Not specified", "Not specified"), # Bit 12
|
||||||
|
("Not specified", "Not specified"), # Bit 13
|
||||||
|
("No event set or event has not occurred yet", "Set event has occurred"), # Bit 14
|
||||||
|
("Axis off (power disabled)", "Axis on (power enabled)"), # Bit 15
|
||||||
|
]
|
||||||
|
|
||||||
|
def decode(value, big_endian: bool = False):
|
||||||
|
|
||||||
|
interpreted = []
|
||||||
|
|
||||||
|
bit_list = [(value >> shift_ind) & 1
|
||||||
|
for shift_ind in range(value.bit_length())] # little endian
|
||||||
|
|
||||||
|
if big_endian:
|
||||||
|
bit_list.reverse() # big endian
|
||||||
|
|
||||||
|
for (bit, interpretations) in zip(bit_list, interpretation):
|
||||||
|
interpreted.append(interpretations[bit])
|
||||||
|
return (bit_list, interpreted)
|
||||||
|
|
||||||
|
def print_decoded(bit_list, interpreted):
|
||||||
|
for (idx, (bit_value, msg)) in enumerate(zip(bit_list, interpreted)):
|
||||||
|
print(f"Bit {idx} = {bit_value}: {msg}")
|
||||||
|
|
||||||
|
def interactive():
|
||||||
|
|
||||||
|
# Imported here, because curses is not available in Windows. Using the
|
||||||
|
# interactive mode therefore fails on Windows, but at least the single
|
||||||
|
# command mode can be used (which would not be possible if we would import
|
||||||
|
# curses at the top level)
|
||||||
|
import curses
|
||||||
|
|
||||||
|
stdscr = curses.initscr()
|
||||||
|
curses.noecho()
|
||||||
|
curses.cbreak()
|
||||||
|
stdscr.keypad(True)
|
||||||
|
stdscr.scrollok(True)
|
||||||
|
|
||||||
|
stdscr.addstr(">> ")
|
||||||
|
stdscr.refresh()
|
||||||
|
|
||||||
|
history = [""]
|
||||||
|
ptr = len(history) - 1
|
||||||
|
|
||||||
|
while True:
|
||||||
|
c = stdscr.getch()
|
||||||
|
if c == curses.KEY_RIGHT:
|
||||||
|
(y, x) = stdscr.getyx()
|
||||||
|
if x < len(history[ptr]) + 3:
|
||||||
|
stdscr.move(y, x+1)
|
||||||
|
stdscr.refresh()
|
||||||
|
elif c == curses.KEY_LEFT:
|
||||||
|
(y, x) = stdscr.getyx()
|
||||||
|
if x > 3:
|
||||||
|
stdscr.move(y, x-1)
|
||||||
|
stdscr.refresh()
|
||||||
|
elif c == curses.KEY_UP:
|
||||||
|
if ptr > 0:
|
||||||
|
ptr -= 1
|
||||||
|
stdscr.addch("\r")
|
||||||
|
stdscr.clrtoeol()
|
||||||
|
stdscr.addstr(">> " + history[ptr])
|
||||||
|
elif c == curses.KEY_DOWN:
|
||||||
|
if ptr < len(history) - 1:
|
||||||
|
ptr += 1
|
||||||
|
stdscr.addch("\r")
|
||||||
|
stdscr.clrtoeol()
|
||||||
|
stdscr.addstr(">> " + history[ptr])
|
||||||
|
elif c == curses.KEY_ENTER or c == ord('\n') or c == ord('\r'):
|
||||||
|
if history[ptr] == 'quit':
|
||||||
|
break
|
||||||
|
|
||||||
|
# because of arrow keys move back to the end of the line
|
||||||
|
(y, x) = stdscr.getyx()
|
||||||
|
stdscr.move(y, 3+len(history[ptr]))
|
||||||
|
|
||||||
|
if history[ptr]:
|
||||||
|
result = interpret_inputs(history[ptr].split())
|
||||||
|
if result is None:
|
||||||
|
stdscr.addstr(f"\nBAD INPUT: Expected input of 'value [big_endian]', where 'value' is an int or a float and 'big_endian' is an optional boolean argument.")
|
||||||
|
else:
|
||||||
|
(arg, big_endian) = result
|
||||||
|
(bit_list, interpreted) = decode(arg, big_endian)
|
||||||
|
for (idx, (bit_value, msg)) in enumerate(zip(bit_list, interpreted)):
|
||||||
|
stdscr.addstr(f"\nBit {idx} = {bit_value}: {msg}")
|
||||||
|
stdscr.refresh()
|
||||||
|
|
||||||
|
if ptr == len(history) - 1 and history[ptr] != "":
|
||||||
|
history += [""]
|
||||||
|
else:
|
||||||
|
history[-1] = ""
|
||||||
|
ptr = len(history) - 1
|
||||||
|
|
||||||
|
stdscr.addstr("\n>> ")
|
||||||
|
stdscr.refresh()
|
||||||
|
|
||||||
|
else:
|
||||||
|
if ptr < len(history) - 1: # Modifying previous input
|
||||||
|
if len(history[-1]) == 0:
|
||||||
|
history[-1] = history[ptr]
|
||||||
|
ptr = len(history) - 1
|
||||||
|
|
||||||
|
else:
|
||||||
|
history += [history[ptr]]
|
||||||
|
ptr = len(history) - 1
|
||||||
|
|
||||||
|
if c == curses.KEY_BACKSPACE:
|
||||||
|
if len(history[ptr]) == 0:
|
||||||
|
continue
|
||||||
|
(y, x) = stdscr.getyx()
|
||||||
|
history[ptr] = history[ptr][0:x-4] + history[ptr][x-3:]
|
||||||
|
stdscr.addch("\r")
|
||||||
|
stdscr.clrtoeol()
|
||||||
|
stdscr.addstr(">> " + history[ptr])
|
||||||
|
stdscr.move(y, x-1)
|
||||||
|
stdscr.refresh()
|
||||||
|
|
||||||
|
else:
|
||||||
|
(y, x) = stdscr.getyx()
|
||||||
|
history[ptr] = history[ptr][0:x-3] + chr(c) + history[ptr][x-3:]
|
||||||
|
stdscr.addch("\r")
|
||||||
|
stdscr.clrtoeol()
|
||||||
|
stdscr.addstr(">> " + history[ptr])
|
||||||
|
stdscr.move(y, x+1)
|
||||||
|
stdscr.refresh()
|
||||||
|
|
||||||
|
# to quit
|
||||||
|
curses.nocbreak()
|
||||||
|
stdscr.keypad(False)
|
||||||
|
curses.echo()
|
||||||
|
curses.endwin()
|
||||||
|
|
||||||
|
def interpret_inputs(inputs):
|
||||||
|
|
||||||
|
number = None
|
||||||
|
big_endian = False
|
||||||
|
try:
|
||||||
|
number = int(float(inputs[0]))
|
||||||
|
if len(inputs) > 1:
|
||||||
|
second_arg = inputs[1]
|
||||||
|
if second_arg == "True" or second_arg == "true":
|
||||||
|
big_endian = True
|
||||||
|
elif second_arg == "False" or second_arg == "false":
|
||||||
|
big_endian = False
|
||||||
|
else:
|
||||||
|
big_endian = bool(int(second_arg))
|
||||||
|
return (number, big_endian)
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
|
if len(argv) == 1:
|
||||||
|
# Start interactive mode
|
||||||
|
interactive()
|
||||||
|
else:
|
||||||
|
|
||||||
|
result = interpret_inputs(argv[1:])
|
||||||
|
|
||||||
|
if result is None:
|
||||||
|
print("""
|
||||||
|
Decode R10 message of MasterMACs
|
||||||
|
------------------
|
||||||
|
|
||||||
|
MasterMACs returns its status message (R10) as a floating-point number.
|
||||||
|
The bits of this float encode different states. These states are stored
|
||||||
|
in the interpretation variable.
|
||||||
|
|
||||||
|
This script can be used in two different ways:
|
||||||
|
|
||||||
|
Option 1: Single Command
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
Usage: decodeMasterMACStatusR10.py value [big_endian]
|
||||||
|
|
||||||
|
'value' is the return value of a R10 command. This value is interpreted
|
||||||
|
bit-wise and the result is printed out. The optional second argument can
|
||||||
|
be used to specify whether the input value needs to be interpreted as
|
||||||
|
little or big endian. Default is False.
|
||||||
|
|
||||||
|
Option 2: CLI Mode
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Usage: decodeMasterMACStatusR10.py
|
||||||
|
|
||||||
|
A prompt will be opened. Type in the return value of a R10 command, hit
|
||||||
|
enter and the interpretation will be printed in the prompt. After that,
|
||||||
|
the next value can be typed in. Type 'quit' to close the prompt.
|
||||||
|
""")
|
||||||
|
else:
|
||||||
|
print("Motor status")
|
||||||
|
print("============")
|
||||||
|
(arg, big_endian) = result
|
||||||
|
(bit_list, interpreted) = decode(arg, big_endian)
|
||||||
|
print_decoded(bit_list, interpreted)
|
@ -64,6 +64,7 @@ if __name__ == "__main__":
|
|||||||
curses.noecho()
|
curses.noecho()
|
||||||
curses.cbreak()
|
curses.cbreak()
|
||||||
stdscr.keypad(True)
|
stdscr.keypad(True)
|
||||||
|
stdscr.scrollok(True)
|
||||||
|
|
||||||
stdscr.addstr(">> ")
|
stdscr.addstr(">> ")
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
|
Reference in New Issue
Block a user