public class InspcMng extends java.lang.Object implements java.io.Closeable, InspcAccess_ifc
VariableContainer_ifc
and the VariableAccess_ifc
: The InspcMng is a variable container.
A variable can be gotten using VariableContainer_ifc#getVariable(String)
. This variable is created in the InspcMng then
unless it is existing in the target. It is a mirror of a variable in the target with a specified access path.
The last current value is contained in the mirror. VariableAccess_ifc#requestValue()
, VariableAccess_ifc#isRefreshed()
,
VariableAccess_ifc#getFloat()
etc. The InspcMng and its subordinated classes organnizes the communication with the target
in an own time cycle.
InspcAccess_ifc
. With them requests can be done immediately to a target.
The callback is done with implementing the InspcAccessExecRxOrder_ifc
in the users area.
InspcVariable
to see how the variable request, send request to the target, receive from target works.
InspcStruct
to see how data struct in the target are re-built in the InspcMng.
InspcTargetAccessor
to see how the access to the target works
InspcCommPort
The commmunication port.
startupThreads()
for the send requests to the target device.
That thread opens the
inspector communication via InspcTargetAccessor#open(String)
which may use an
InterProcessComm
instance.
idxAllVars
sorted by name.
The variable reference of type VariableAccess_ifc
stores the access path to the target if necessary and the
actual value. The actual value may be read from a target device or not in the last time. A variable can be registered
to the manager calling getVariable(String)
. That routine build the correct instance for the variable access,
that is either InspcVariable
or an FieldJcVariableAccess
for java-internal variables.
The variable will be wrapped in an org.vishia.byteData.VariableAccessWithIdx
. The variable knows the
InspcTargetAccessor
and can get values from the target.
threadProcComm
calls method procComm()
cyclically,
if the communication was opened till close()
is called. In this loop all requested variables
were handled with a request-value telegram and all #addUserOrder(Runnable)
are processed.
procComm()
all known variables from idxAllVars
are processed, see getVariable(String)
.
But only if a value from a variable was requested in the last time, a new value is requested from a target device.
With that requests one send telegram is built. If the telegram is filled, it will be send.
Then the answer of the target device is awaiting, see InspcTargetAccessor#sendAndAwaitAnswer()
.
In this time the loop is blocked till a timeout is occurred while waiting of the embedded device's answer.
Normally the embedded device or other target should answer in a few milliseconds.
InspcTargetAccessor#receiveThread
.
The receive thread handles receiving from the one port of communication, which is opened with the
InterProcessComm
instance which usual is a InterProcessComm_SocketImpl
.
It is possible to send from more as this thread, or it is possible to receive some special telegrams which
are not requested. That does the receive thread.
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
bAllReceived
Set from
#variableIsReceived(InspcVariable) if all variables are received. |
(package private) boolean |
bUseGetValueByHandle |
(package private) boolean |
bUserCalled |
(package private) boolean |
bWriteDebugSystemOut |
(package private) java.lang.Runnable |
callbackOnRxData
This method is called if variable are received.
|
(package private) int |
clearRequestedVariable |
private java.util.concurrent.ConcurrentLinkedQueue<InspcCmdStore> |
cmdQueue |
protected InspcCommPort |
commPort |
(package private) int |
identLogTelg |
(package private) java.util.Map<java.lang.String,InspcStruct> |
idxAllStruct
This container holds all structures which are created.
|
(package private) java.util.Map<java.lang.String,InspcVariable> |
idxAllVars
This container holds all variables which are created.
|
private java.util.Map<java.lang.String,java.lang.String> |
indexFaultDevice |
private java.util.Map<java.lang.String,InspcTargetAccessor> |
indexTargetAccessor |
private java.util.Map<java.lang.String,java.lang.String> |
indexTargetIpcAddr
The target ipc-address for Interprocess-Communication with the target.
|
private java.util.List<InspcTargetAccessor> |
listTargetAccessor |
(package private) long |
millisecTimeoutOrders |
(package private) ReplaceAlias_ifc |
replacerAlias |
(package private) boolean |
retryDisabledVariable |
java.lang.String |
sFileLog |
(package private) java.lang.String |
sIpTarget |
private java.lang.String |
sOwnIpcAddr
Own address string for the communication.
|
private ThreadRun.Step |
step |
private InspcTargetAccessor |
targetAccDbg
listTargetAccessor also as array, because Reflection access does not work for ArrayList yet. |
(package private) EventTimerThread |
threadEvent
Thread which manages the queue of all events of state machines.
|
private ThreadRun |
threadProcComm
The request of values from the target is organized in a cyclic thread.
|
(package private) long |
timeLastRemoveOrders |
private InspcPlugUser_ifc |
user |
(package private) InspcVariable |
varDummyForUnknownTarget |
(package private) static java.lang.String |
version
Version, history and license.
|
(package private) java.lang.Runnable |
XXXcallbackShowingTargetCommState |
idLogFailedSeq, idLogGetAddress, idLogGetFields, idLogGetOther, idLogGetValueByIdent, idLogGetValueByPath, idLogRcvGetAddress, idLogRcvGetFields, idLogRcvGetOther, idLogRcvGetValueByIdent, idLogRcvGetValueByPath, idLogRcvRegisterByPath, idLogRcvSetValueByPath, idLogRegisterByPath, idLogRx, idLogRxError, idLogRxItem, idLogRxLast, idLogRxNotlast, idLogRxRepeat, idLogSetValueByPath, idLogTx, sVersion
Constructor and Description |
---|
InspcMng(java.lang.String sOwnIpcAddr,
java.util.Map<java.lang.String,java.lang.String> indexTargetIpcAddr,
int cycletime,
boolean bUseGetValueByIndex,
InspcPlugUser_ifc user) |
Modifier and Type | Method and Description |
---|---|
VariableAccess_ifc |
accVariable(java.lang.String sDataPath,
int maxtimeMilliseconds)
Returns a variable which's access to the target is established.
|
void |
addUserTxOrder(java.lang.Runnable order)
Adds any program snippet which is executed while preparing the telegram for data request from target.
|
(package private) void |
callbackOnRxData(java.util.EventObject ev)
This routine will be invoked if all data are received from the target.
|
void |
clearRequestedVariables() |
void |
close() |
boolean |
cmdGetAddressByPath(java.lang.String sDataPath,
InspcAccessExecRxOrder_ifc actionOnRx)
Adds the info block to send 'get value by path'
|
int |
cmdGetFields(java.lang.String sPathInTarget,
InspcAccessExecRxOrder_ifc actionOnRx) |
boolean |
cmdGetValueByHandle(int ident,
InspcAccessExecRxOrder_ifc actionOnRx)
Adds the info block to send 'register by path'
|
int |
cmdGetValueByPath(java.lang.String sPathInTarget,
InspcAccessExecRxOrder_ifc actionOnRx)
Adds the info block to send 'get value by path'
|
int |
cmdRegisterHandle(java.lang.String sPathInTarget,
InspcAccessExecRxOrder_ifc actionOnRx)
Adds the info block to send 'register by path'
|
void |
cmdSetDoubleByPath(java.lang.String sDataPath,
double value,
InspcAccessExecRxOrder_ifc actionOnRx)
Adds the info block to send 'get value by path'
|
void |
cmdSetFloatByPath(java.lang.String sDataPath,
float value,
InspcAccessExecRxOrder_ifc actionOnRx)
Adds the info block to send 'get value by path'
|
void |
cmdSetInt32ByPath(java.lang.String sDataPath,
int value,
InspcAccessExecRxOrder_ifc actionOnRx)
Adds the info block to send 'get value by path'
|
void |
cmdSetStringByPath(VariableAccessArray_ifc var,
java.lang.String value)
Adds the info block to send 'set value by path'
|
void |
cmdSetValueByPath(java.lang.String sDataPath,
long value,
int typeofValue,
InspcAccessExecRxOrder_ifc actionOnRx)
Adds the info block to send 'get value by path'
|
void |
complete_ReplaceAlias_ifc(ReplaceAlias_ifc replacerAliasArg) |
void |
completeConstruction() |
InspcRxOk |
create_InspcRxOk() |
(package private) void |
errorDevice(java.lang.String sDevice) |
int |
getStateOfTargetComm(int ixTarget) |
InspcTargetAccessData |
getTargetAccessFromPath(java.lang.String sDataPath,
boolean strict)
Splits a given full data path with device:datapath maybe with alias:datapath in the device, path, name and returns a struct.
|
VariableAccess_ifc |
getVariable(java.lang.String sDataPath) |
private InspcVariable |
getVariable(java.lang.String sDataPath,
int recurs) |
boolean |
isOrSetReady(long timeCurrent)
Checks readiness of communication cycle.
|
(package private) void |
openComm() |
protected void |
procComm()
This routine requests all values from its target devices,
for the variables which were requested itself after last call of refresh.
|
void |
requestFields(InspcTargetAccessData data,
InspcAccessExecRxOrder_ifc rxActionGetFields,
java.lang.Runnable runOnReceive)
Set the request for all fields of the given variable.
|
void |
setCallbackOnReceivedData(java.lang.Runnable callback) |
void |
setmodeGetValueByIndex(boolean byIndex) |
void |
setmodeRetryDisabledVariables(boolean retry) |
void |
startupThreads() |
(package private) void |
stop() |
java.lang.String |
translateDeviceToAddrIp(java.lang.String sDevice) |
void |
XXXsetCallbackShowingState(java.lang.Runnable callback) |
static final java.lang.String version
targetAccDbg
, openComm()
invokes now user.registerTarget(name, val, accessor); for the GUI
InspcTargetAccessor.isOrSetReady(long)
, need for step debug.
InspcTargetAccessor.setStateToUser(InspcPlugUser_ifc)
.
InspcTargetAccessor.addUserTxOrder(Runnable)
. Any target has its own timing. Only the target
access can determine when to send to a target. Some gardening furthermore.
InspcTargetAccessor
#requestValueByPath(String, InspcAccessExecRxOrder_ifc)
because
the telegram is full, the same variable should be requested repeatedly in the next telegram. It was forgotten.
getVariable(String)
should start with "java:" then the variable is searched internally. TODO now it isn't tested well, the start instance
should be given by constructor, because it should be either the start instance of the whole application or a special
data area.
bUseGetValueByHandle
: Access via getValuePerPath for downward compatibility with target device.
to test telegram trafic
VariableAccess_ifc
concept which has experience in the org.vishia.guiViewCfg package.
Both concepts to access variable are merged yet. The GUI to show values from a target system
now has only one interface concept to access values, independent of their communication concept.
This class supports the communication via the inspector reflex access.
WidgetCommAction#execInspcRxOrder(Info)
for formatted output
private final ThreadRun threadProcComm
procComm()
.final EventTimerThread threadEvent
private final InspcPlugUser_ifc user
ReplaceAlias_ifc replacerAlias
java.lang.Runnable callbackOnRxData
java.lang.Runnable XXXcallbackShowingTargetCommState
public java.lang.String sFileLog
boolean bWriteDebugSystemOut
int identLogTelg
java.util.Map<java.lang.String,InspcVariable> idxAllVars
java.util.Map<java.lang.String,InspcStruct> idxAllStruct
private final java.lang.String sOwnIpcAddr
private final java.util.Map<java.lang.String,java.lang.String> indexTargetIpcAddr
private final java.util.Map<java.lang.String,InspcTargetAccessor> indexTargetAccessor
private final java.util.List<InspcTargetAccessor> listTargetAccessor
private InspcTargetAccessor targetAccDbg
listTargetAccessor
also as array, because Reflection access does not work for ArrayList yet.private java.util.Map<java.lang.String,java.lang.String> indexFaultDevice
private java.util.concurrent.ConcurrentLinkedQueue<InspcCmdStore> cmdQueue
boolean retryDisabledVariable
int clearRequestedVariable
long millisecTimeoutOrders
long timeLastRemoveOrders
java.lang.String sIpTarget
boolean bUseGetValueByHandle
boolean bUserCalled
protected final InspcCommPort commPort
boolean bAllReceived
#variableIsReceived(InspcVariable)
if all variables are received.
Tested from #inspcThread
whether all are received.InspcVariable varDummyForUnknownTarget
private final ThreadRun.Step step
public InspcMng(java.lang.String sOwnIpcAddr, java.util.Map<java.lang.String,java.lang.String> indexTargetIpcAddr, int cycletime, boolean bUseGetValueByIndex, InspcPlugUser_ifc user)
public void completeConstruction()
public void complete_ReplaceAlias_ifc(ReplaceAlias_ifc replacerAliasArg)
public void startupThreads()
public void setmodeRetryDisabledVariables(boolean retry)
public void clearRequestedVariables()
public void setmodeGetValueByIndex(boolean byIndex)
public void setCallbackOnReceivedData(java.lang.Runnable callback)
public void XXXsetCallbackShowingState(java.lang.Runnable callback)
public VariableAccess_ifc getVariable(java.lang.String sDataPath)
private InspcVariable getVariable(java.lang.String sDataPath, int recurs)
public VariableAccess_ifc accVariable(java.lang.String sDataPath, int maxtimeMilliseconds)
VariableAccess_ifc#getFloat()
etc. If a new value is need, invoke VariableAccess_ifc#requestValue()
.sDataPath
- Path to the target:data.path.maxtimeSeconds
- waiting time for establishing the target communication.public InspcRxOk create_InspcRxOk()
protected void procComm()
InspcVariable.VariableRxAction.execInspcRxOrder(org.vishia.communication.InspcDataExchangeAccess.Inspcitem, long, LogMessage, int)
with the info block of the telegram for each variable.
If all variables are received, the callback routineorg.vishia.byteData.VariableContainer_ifc#refreshValues()
public InspcTargetAccessData getTargetAccessFromPath(java.lang.String sDataPath, boolean strict)
indexTargetAccessor
to get the target accessor instance.
It uses idxAllStruct
to get the existing InspcStruct
for the variablegetTargetAccessFromPath
in interface InspcAccess_ifc
sDataPath
- The user given data path maybe with alias, necessary with target.
An alias is written in form "alias:rest.of.path". A device is written "device:rest.of.path".
The distinction between alias and device is done with checking whether the charsequence before :
is detected as alias.strict
- true then throws an error on faulty device, if false then returns null if faulty.public int getStateOfTargetComm(int ixTarget)
public java.lang.String translateDeviceToAddrIp(java.lang.String sDevice)
void errorDevice(java.lang.String sDevice)
void callbackOnRxData(java.util.EventObject ev)
ev
- void openComm()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
void stop()
public int cmdGetFields(java.lang.String sPathInTarget, InspcAccessExecRxOrder_ifc actionOnRx)
cmdGetFields
in interface InspcAccess_ifc
public boolean cmdGetValueByHandle(int ident, InspcAccessExecRxOrder_ifc actionOnRx)
InspcAccess_ifc
cmdGetValueByHandle
in interface InspcAccess_ifc
public int cmdGetValueByPath(java.lang.String sPathInTarget, InspcAccessExecRxOrder_ifc actionOnRx)
InspcAccess_ifc
cmdGetValueByPath
in interface InspcAccess_ifc
public int cmdRegisterHandle(java.lang.String sPathInTarget, InspcAccessExecRxOrder_ifc actionOnRx)
InspcAccess_ifc
cmdRegisterHandle
in interface InspcAccess_ifc
public boolean cmdGetAddressByPath(java.lang.String sDataPath, InspcAccessExecRxOrder_ifc actionOnRx)
InspcAccess_ifc
cmdGetAddressByPath
in interface InspcAccess_ifc
sDataPath
- Either the path inside the target or the path with target identification,
depends on implementation. Maybe possible with alias.actionOnRx
- it will be added to a list with its order. Executed in the receive thread.public void cmdSetValueByPath(java.lang.String sDataPath, long value, int typeofValue, InspcAccessExecRxOrder_ifc actionOnRx)
InspcAccess_ifc
cmdSetValueByPath
in interface InspcAccess_ifc
value
- The value as long-image, it may be a double, float, int etc.typeofValue
- The type of the value, use InspcDataExchangeAccess#kScalarTypes
+ ClassJc#REFLECTION_double
etc.public void cmdSetStringByPath(VariableAccessArray_ifc var, java.lang.String value)
InspcAccess_ifc
cmdSetStringByPath
in interface InspcAccess_ifc
value
- The value as long-image, it may be a double, float, int etc.public void cmdSetInt32ByPath(java.lang.String sDataPath, int value, InspcAccessExecRxOrder_ifc actionOnRx)
InspcAccess_ifc
cmdSetInt32ByPath
in interface InspcAccess_ifc
value
- The value as long-image, it may be a double, float, int etc.public void cmdSetFloatByPath(java.lang.String sDataPath, float value, InspcAccessExecRxOrder_ifc actionOnRx)
InspcAccess_ifc
cmdSetFloatByPath
in interface InspcAccess_ifc
value
- The value as long-image, it may be a double, float, int etc.public void cmdSetDoubleByPath(java.lang.String sDataPath, double value, InspcAccessExecRxOrder_ifc actionOnRx)
InspcAccess_ifc
cmdSetDoubleByPath
in interface InspcAccess_ifc
value
- The value as long-image, it may be a double, float, int etc.public boolean isOrSetReady(long timeCurrent)
InspcAccess_ifc
States.StateIdle
or States.StateFilling
Returns false if not all answer telegrams were received from the last request.
It is in all other states of States
.
If the time of the last send request was before timeLastTxWaitFor
then it is assumed that the communication was faulty. Therefore all older pending requests are removed.
Note: On InspcMng it return false;isOrSetReady
in interface InspcAccess_ifc
timeCurrent
- The current time. It is compared with the time of the last transmit telegram which's answer is expected,
and the timeout. If the timeout is expired, older requests are removed and this routine returns true.public void addUserTxOrder(java.lang.Runnable order)
InspcAccess_ifc
addUserTxOrder
in interface InspcAccess_ifc
order
- the program snippet.public void requestFields(InspcTargetAccessData data, InspcAccessExecRxOrder_ifc rxActionGetFields, java.lang.Runnable runOnReceive)
InspcAccess_ifc
InspcAccess_ifc.cmdGetFields(String, InspcAccessExecRxOrder_ifc)
in the inspector thread.requestFields
in interface InspcAccess_ifc
data
- The variablerxActionGetFields
- Action on gotten fieldsrunOnReceive
- Action should be run if all fields are received, if all datagrams are received for that communication cycle.