Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nomad-3d-commons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Instrument Control
Protos
Nomad 3D
nomad-3d-commons
Commits
9de55d50
Commit
9de55d50
authored
8 years ago
by
Ivan Dages
Browse files
Options
Downloads
Patches
Plain Diff
link with nomad command system
parent
b5a41379
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fr/ill/ics/n3d/link/NomadLinker.java
+126
-0
126 additions, 0 deletions
src/main/java/fr/ill/ics/n3d/link/NomadLinker.java
with
126 additions
and
0 deletions
src/main/java/fr/ill/ics/n3d/link/NomadLinker.java
0 → 100644
+
126
−
0
View file @
9de55d50
/**
*
*/
package
fr.ill.ics.n3d.link
;
import
java.util.HashMap
;
import
java.util.Set
;
import
java.util.logging.Logger
;
import
org.omg.PortableInterceptor.ServerIdHelper
;
import
fr.ill.ics.bridge.Controller
;
import
fr.ill.ics.bridge.ControllerManager
;
import
fr.ill.ics.bridge.LoginManager
;
import
fr.ill.ics.bridge.LoginManager.ClientAlreadyLaunchedException
;
import
fr.ill.ics.bridge.LoginManager.ConnectionFailure
;
import
fr.ill.ics.bridge.LoginManager.LoginIncorrectException
;
import
fr.ill.ics.bridge.command.CommandZoneWrapper
;
import
fr.ill.ics.cameo.Application
;
import
fr.ill.ics.core.property.Property
;
import
fr.ill.ics.core.property.PropertyManager
;
import
fr.ill.ics.nscclient.servant.ControllerServant
;
import
fr.ill.ics.nscclient.serverconnection.ServerInstance
;
import
fr.ill.ics.util.ConfigManager
;
/**
* @author dages
*/
public
class
NomadLinker
{
public
final
static
int
LOGIN_OK
=
0
;
public
final
static
int
LOGIN_NOT_OK
=
1
;
public
final
static
int
LOGIN_REFUSED
=
2
;
private
final
static
NomadLinker
instance
=
new
NomadLinker
();
private
HashMap
<
String
,
ControllerServant
>
controllers
;
/**
* Default constructor.
*/
private
NomadLinker
()
{
controllers
=
new
HashMap
<>();
}
public
static
NomadLinker
getInstance
()
{
return
instance
;
}
public
void
init
(
String
[]
args
)
{
Application
.
This
.
init
(
args
);
// Initialize the ConfigManager at the very beginning because it is in this class where all .nomad/settings.properties are initialized!
ConfigManager
.
initInstance
();
ServerInstance
.
getInstance
().
init
();
Logger
.
getLogger
(
"nomad-3d"
).
info
(
"Nomad server endpoint : "
+
ConfigManager
.
getInstance
().
getNomadServerEndpoint
());
int
status
=
login
(
""
,
""
,
true
);
Logger
.
getLogger
(
"nomad-3d"
).
info
(
"Nomad server login status : "
+
status
);
PropertyManager
.
getInstance
().
init
();
Set
<
String
>
controllersNames
=
ControllerManager
.
getInstance
().
getControllersOfType
(
"axis"
,
true
);
// System.out.println("Controllers : \n " + controllers);
for
(
String
controllerName
:
controllersNames
)
{
ControllerServant
controller
=
ControllerManager
.
getInstance
().
getController
(
controllerName
);
controllers
.
put
(
controllerName
,
controller
);
// Property prop = PropertyManager.getInstance().getProperty(controller, "actual_position");
// System.out.println("server value : " + prop.getServerValue());
}
// System.out.println("Loaded controllers : \n" + controllers);
displayActualPositions
();
}
public
Set
<
String
>
getAxisControllersNames
()
{
return
controllers
.
keySet
();
}
public
String
getServerValue
(
String
controllerName
,
String
propertyName
)
{
ControllerServant
controller
=
controllers
.
get
(
controllerName
);
Property
prop
=
PropertyManager
.
getInstance
().
getProperty
(
controller
,
propertyName
);
return
prop
.
getServerValue
();
}
public
String
getValue
(
String
controllerName
,
String
propertyName
)
{
ControllerServant
controller
=
controllers
.
get
(
controllerName
);
Property
prop
=
PropertyManager
.
getInstance
().
getProperty
(
controller
,
propertyName
);
return
prop
.
getValue
();
}
// TODO TEST
private
void
displayActualPositions
()
{
System
.
out
.
println
(
"Controllers positions : "
);
for
(
String
controllerName
:
getAxisControllersNames
())
{
double
pos
=
Double
.
parseDouble
(
getServerValue
(
controllerName
,
"actual_position"
));
System
.
out
.
println
(
"\t"
+
controllerName
+
" : "
+
pos
);
}
}
public
void
terminate
()
{
// Close connection with Nomad Server
LoginManager
.
getInstance
().
logout
(
CommandZoneWrapper
.
SERVER_ID
);
Application
.
This
.
terminate
();
}
private
int
login
(
String
login
,
String
password
,
boolean
standalone
)
{
int
loginState
=
LOGIN_NOT_OK
;
// Check login and password
try
{
LoginManager
.
getInstance
().
login
(
login
,
password
,
standalone
,
CommandZoneWrapper
.
SERVER_ID
);
loginState
=
LOGIN_OK
;
}
catch
(
LoginIncorrectException
e
)
{
loginState
=
LOGIN_NOT_OK
;
}
catch
(
ClientAlreadyLaunchedException
e
)
{
loginState
=
LOGIN_REFUSED
;
}
catch
(
ConnectionFailure
e
)
{
System
.
exit
(
1
);
}
return
loginState
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment