I have a program that I want to run on track-mate
Track-mate system identifies the object through the webcam which is connected to the PC. We place the webcam under the Plexiglas sheet (a transparent surface which is save for children) to track the bar-code and returns a digital feedback to the Track-mate...
the bar-code is saved in a database in a String format but our problem is that the bar-code readings are different each time we move the object on the surface, which makes it not unique for the exact object.
what can we do to solve this problem?
The program sources:
//LusidOSC a layer that reads tags from a webcam and send the result to any application
public LusidOSCJavaApp(){
// create the client, on port 3333.
lusidClient = new LusidClient(this, 3333);
System.out.println("lusid osc java app ");
System.out.println(View.getisRunning());
while(View.getisRunning()){//SOME CODE TO DO}
// ---------------------------------------------------------------
// these methods are called whenever a LusidOSC event occurs.
// called when an object is added to the scene
public void addLusidObject(LusidObject lObj) {
System.out.println("add lusid object");
//when object is added we add an instance of the object to lusidObj arraylist
lusidArr.add(lObj);
//The problem is here because the ID isn't unique (but it should be unique...)
if(lObj.getUniqueID().equals("0x111111AA1111")) {
System.out.println("you put the right shape");}
else{
System.out.println("error");}
System.out.println("add object: "+lObj.getUniqueID());
System.out.println(" location =
("+lObj.getX()+","+lObj.getY()+","+lObj.getZ()+")");
System.out.println(" rotation =
("+lObj.getRotX()+","+lObj.getRotY()+","+lObj.getRotZ()+")");
System.out.println("data =
("+lObj.getEncoding()+","+lObj.getData()+")");
System.out.println("#######################################");
System.out.println(lusidArr.size());
}
// called when an object is removed from the scene
public void removeLusidObject(LusidObject lObj) {
lusidArr.remove(lObj);
System.out.println("remove object: "+lObj.getUniqueID());
}
// called when an object is moved
public void updateLusidObject (LusidObject lObj) {
//System.out.println("update object: "+lObj.getUniqueID());
ArrayList<LusidObject> currentLusidList = new ArrayList<LusidObject>
(Arrays.asList(lusidClient.getLusidObjects()));
Download Link + source: Trackmate
Related
I am working on an application where I am connecting with the BLE device and sending commands.
One of that commands we have a command for changing the Bluetooth device name.
Communication is working fine, but the problem is when we send the command for changing the name it was working, BLE confirms the input and sends us the output, but when we disconnect and run LE Scan it was showing the same name as the previous, it should show the new name of the device.
If I want to get the latest name of the device I need to open the Bluetooth page manually in the device and scan over there in the scan result it was showing the latest name, when I open the app again which is in the background and its scanning under LE scan function with 10-sec delay, it was showing the new name in the list.
How can I ask Bluetooth manager or system to refresh the cache or refresh data for that Bluetooth device ?.
I don't know it was right to create ticket, but i have created ticket in google issue tracker : https://issuetracker.google.com/issues/233924346
Thanks.
I had the same problem and solved it by reading the new name from the raw scan data. In this way you never have to use device.getName() which returns the old name from the cache. This is Android Java code for the scan callback function.
private ScanCallback newscancallback()
{
ScanCallback scb;
// Device scan callback.
scb = new ScanCallback()
{
#Override
public void onScanResult(int callbackType, ScanResult result)
{
super.onScanResult(callbackType, result);
int n,k,len,getout;
BluetoothDevice dev;
byte[] rec;
StringBuilder nameb;
String name;
dev = result.getDevice();
// do not use dev.getName() which returns cached name
// read current name from raw scan record instead
name = null;
rec = result.getScanRecord().getBytes();
len = rec.length;
nameb = new StringBuilder();
n = 0;
getout = 0;
// search scan record for name
while(n < len-2 && rec[n] != 0 && getout == 0)
{
// rec[n] is length of next item
// rec[n+1] is item type - look for 8 or 9=name
// rec[n+2].. is the name, length rec[n]-1
if(rec[n] > 1 && (rec[n+1] == 8 || rec[n+1] == 9)
{ // found name
for(k = 0 ; k < rec[n]-1 ; ++k)
nameb.append((char)rec[n+2+k]);
name = nameb.toString();
getout = 1;
}
else // go to next item
n += rec[n] + 1;
}
// name is now null or the new name from the scan record
}
#Override
public void onScanFailed(int errcode)
{
}
#Override
public void onBatchScanResults(List<ScanResult> result)
{
}
};
return (scb);
}
As you can see the latest name in the Bluetooth settings of the mobile device, I believe there is no issue with the Bluetooth manager of the system. The issue will be in the scanning function of the code as it is not actually refreshing the scan list yet and it might saved the last known BLE list somewhere in the cache. If you are using third-party library, you might need to check their documentation or codes about how the scan function actually works. There may be like force-refresh option or something in the library. As far as I know, to save the device's battery, there is a delay to actually refresh the scan list.
I have been trying to put permission on my pdf.
I have a method which will set the Access Permission on an instance variable called access
private AccessPermission access = new AccessPermission();
public void setPdfPermissions(boolean allowPrint, boolean degradePrint,
boolean editPage, boolean allowAssembly, boolean allowCopy,
boolean allowReaders, boolean editAnnotation, boolean allowFillIn) {
if (allowPrint) { // allow printing
access.setCanPrint(allowPrint);
}
if (degradePrint) { // degrade printing
access.setCanPrintDegraded(allowAssembly);
}
if (editPage) { // edit page contents
access.setCanModify(editPage);
}
if (allowAssembly) { // insert, remote or rotate page
access.setCanAssembleDocument(allowAssembly);
}
if (allowCopy) { // copy page contents or graphics
access.setCanExtractForAccessibility(allowCopy);
}
if (allowReaders) { // screen readers can copy contents or graphics
access.setReadOnly();
}
if (editAnnotation) { // edit annotations
access.setCanModifyAnnotations(editAnnotation);
}
if (allowFillIn) { // fill form fields
access.setCanFillInForm(allowFillIn);
}
}
and then I m saving the access in security handler
StandardSecurityHandler secHandler = new StandardSecurityHandler();
if((userPass != null) || (ownerPass != null)) {
System.out.println("userPass:"+userPass+"owner pass:"+userPass);
// TODO
StandardProtectionPolicy policy = new StandardProtectionPolicy(ownerPass.toString(), userPass.toString(),
access);
secHandler = new StandardSecurityHandler(policy);
document.setSecHandler(secHandler);
When Im passing false for values like setPrint as false, Its allowing me to print. Any help is highly appreciated.
In addition to #Tilman's answer, the first code block also is wrong:
For each boolean parameter, setPdfPermissions only does something if the value is true, e.g.:
if (allowPrint) { // allow printing
access.setCanPrint(allowPrint);
}
This would work if the permission by default was not granted. Looking at the definition of the AccessPermission default constructor, though, one sees that the contrary is the case, e.g. in the code from 1.8.10:
/**
* Create a new access permission object.
* By default, all permissions are granted.
*/
public AccessPermission()
{
bytes = DEFAULT_PERMISSIONS;
}
Thus, setPdfPermissions essentialis is a big NOP (no-operation) block of code.
Your second code block is wrong. The correct way (at least for the 1.8 versions) to encrypt a file is described here. So for you, the correct code would be:
// owner password to open the file with all permissions
// user password to open the file but with restricted permissions, can be empty
StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPass, userPass, access);
spp.setEncryptionKeyLength(128);
doc.protect(spp);
edit: see also the answer by mkl why your 1st code segment is wrong too :-)
I am writing a Java program that will listen for PDUs that are being sent across a network, and present information about those PDUs (such as entity state & position within the simulation) to the user.
I currently have one class which is being used to listen for the PDUs being sent over the network (EspduReceiver.java), and another class that I am using to create the GUI that the user will use to interact with the program (Gui.java).
The EspduReceiver.java class currently works as intended- when I run it, it listens for any PDUs that are being sent over the network, and displays information about each individual PDU it receives in the console. The information that it displays includes the entity ID, and its position within the simulation.
However, this method literally just listens for a PDU message, and prints the relevant information about it to the console when it 'hears' one- so the information about the Entity State PDU that is being printed in the console, is not actually stored anywhere in the program at present.
Now, what I would like to do with my Gui.java class, is to create a user interface that will display what I am seeing being printed in the console to the user. I have written the foundation of a class that will do this, but I am having trouble retrieving the data that is being read into my program from the EspduReceiver.java class...
The method that I am using to retrieve the PDU information, and display it in the console currently looks like this:
public static void receivePdu(){
try{
/*Specify the socket to receive the data */
socket = new MulticastSocket(EspduSender.PORT);
address = InetAddress.getByName(EspduSender.DEFAULT_MULTICAST_GROUP);
socket.joinGroup(address);
/*Loop infinitely, receiving datagrams */
while(true){
byte buffer[] = new byte[MAX_PDU_SIZE];
packet = new DatagramPacket(buffer, buffer.length);
socket.receive(packet);
Pdu pdu = pduFactory.createPdu(packet.getData()); /* Commented on 15/04/2014 # 09:15 */
if(pdu != null){
System.out.print("Got PDU of type: " + pdu.getClass().getName());
if(pdu instanceof EntityStatePdu){
EntityID eid = ((EntityStatePdu)pdu).getEntityID();
Vector3Double position = ((EntityStatePdu)pdu).getEntityLocation();
System.out.print(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] ");
System.out.print(" Location in DIS coordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]");
} else if(!(pdu instanceof EntityStatePdu)){
System.out.println("There are no PDUs currently being received.");
}
System.out.println();
}
} /*end while */
} /*end try */
catch(Exception e){
System.out.println(e);
e.printStackTrace();
System.out.println("This is where the error is being generated");
/*09/04/2014 # 17:100
* If this exception gets called, presumably it either means that pdu is not an instance of EntityStatePdu, or
* that pdu does not actually hold a packet. */
}
}
Then, in my Gui.java class, I have a public void initGui(){...} method, which I am trying to use to call the receivePdu() method from EspduReceiver.java. I have done this by declaring a new instance of my EspduReceiver class, and creating a new String variable to hold the data generated by the receivePdu() method:
EspduReceiver receiver = new EspduReceiver();
String data = receiver.receivePdu();
However, I get an error on the String data = receiver.receivePdu(); line that says: "Type mismatch: cannot convert from void to String", and suggests that I change return type of receivePdu() to String...
I understand the reason that I get the error- because my receivePdu() method has a return type of "void", and here I am trying to state that it is String- I had originally tried to write the receivePdu method with a return type of String, but kept getting errors with that, and couldn't fix it other than by changing it to void.
Is there a way that I can access the data retrieved by the receivePdu() method, so that I can display it to the user? How would I do this? Could I possibly save the data that it retrieves to another variable, and use that to display it to the user?
You can't usefully call the receivePdu() method from your GUI, because receivePdu() never returns - it loops forever - and doesn't return anything.
Creating a new instance of EspduReceiver won't help, since the receivePdu method is static i.e. shared by all instances.
You could get receivePdu() to store data in a variable at the top level of EspduReceiver, visible to the GUI, then notify the GUI that it should collect the data and display it. Or you could push the data to the GUI from within receivePdu, though that tangles all your code up somewhat.
Either way, you will need to notify the GUI from the "Event Dispatching Thread" - see the tutorial here.
I am currently using Apache Commons Net to develop my own NNTP reader. Using the tutorial available I was able to use some of their code to allow me to get articles back.
The Code I am using from NNTP Section -
System.out.println("Retrieving articles between [" + lowArticleNumber + "] and [" + highArticleNumber + "]");
Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);
System.out.println("Building message thread tree...");
Threader threader = new Threader();
Article root = (Article)threader.thread(articles);
Article.printThread(root, 0);
I need to take the articles and turn them into a List type so I can send them to AWT using something like this -
List x = (List) b.GetGroupList(dog);
f.add(CreateList(x));
My Entire code Base for this section is -
public void GetThreadList(String Search) throws SocketException, IOException {
String hostname = USE_NET_HOST;
String newsgroup = Search;
NNTPClient client = new NNTPClient();
client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
client.connect(hostname);
client.authenticate(USER_NAME, PASS_WORD);
if(!client.authenticate(USER_NAME, PASS_WORD)) {
System.out.println("Authentication failed for user " + USER_NAME + "!");
System.exit(1);
}
String fmt[] = client.listOverviewFmt();
if (fmt != null) {
System.out.println("LIST OVERVIEW.FMT:");
for(String s : fmt) {
System.out.println(s);
}
} else {
System.out.println("Failed to get OVERVIEW.FMT");
}
NewsgroupInfo group = new NewsgroupInfo();
client.selectNewsgroup(newsgroup, group);
long lowArticleNumber = group.getFirstArticleLong();
long highArticleNumber = lowArticleNumber + 5000;
System.out.println("Retrieving articles between [" + lowArticleNumber + "] and [" + highArticleNumber + "]");
Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);
System.out.println("Building message thread tree...");
Threader threader = new Threader();
Article root = (Article)threader.thread(articles);
Article.printThread(root, 0);
try {
if (client.isConnected()) {
client.disconnect();
}
}
catch (IOException e) {
System.err.println("Error disconnecting from server.");
e.printStackTrace();
}
}
and -
public void CreateFrame() throws SocketException, IOException {
// Make a new program view
Frame f = new Frame("NNTP Reader");
// Pick my layout
f.setLayout(new GridLayout());
// Set the size
f.setSize(H_SIZE, V_SIZE);
// Make it resizable
f.setResizable(true);
//Create the menubar
f.setMenuBar(CreateMenu());
// Create the lists
UseNetController b = new UseNetController(NEWS_SERVER_CREDS);
String dog = "*";
List x = (List) b.GetGroupList(dog);
f.add(CreateList(x));
//f.add(CreateList(y));
// Add Listeners
f = CreateListeners(f);
// Show the program
f.setVisible(true);
}
I just want to take my list of returned news articles and send them to the display in AWT. Can any one explain to me how to turn those Articles into a list?
Welcome to the DIY newsreader club. I'm not sure if you are trying to get a list of newsgroups on the server, or articles.You have already have your Articles in an Iterable Collection. Iterate through it appending what you want in the list from each article. You probably aren't going to want to display the whole article body in a list view. More likely the message id, subject, author or date (or combination as a string). For example for a List of just subjects:
...
Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);
Iterator<Article> it = articles.iterator();
while(it.hasNext()) {
Article thisone = it.next();
MyList.add(thisone.getSubject());
//MyList should have been declared up there somewhere ^^^ and
//your GetThreadList method must include List in the declaration
}
return MyList;
...
My strategy has been to retrieve the articles via an iterator in to an SQLite database with the body, subject, references etc. stored in fields. Then you can create a list sorted just how you want, with a link by primary key to retrieve what you need for individual articles as you display them. Another strategy would be an array of message_ids or article numbers and fetch each one individually from the news server as required. Have fun - particularly when you are coding for Android and want to display a list of threaded messages in the correct sequence with suitable indents and markers ;). In fact, you can learn a lot by looking at the open source Groundhog newsreader project (to which I am eternally grateful).
http://bazaar.launchpad.net/~juanjux/groundhog/trunk/files/head:/GroundhogReader/src/com/almarsoft/GroundhogReader
Busy trying to Call RPG function from Java and got this example from JamesA. But now I am having trouble, here is my code:
AS400 system = new AS400("MachineName");
ProgramCall program = new ProgramCall(system);
try
{
// Initialise the name of the program to run.
String programName = "/QSYS.LIB/LIBNAME.LIB/FUNNAME.PGM";
// Set up the 3 parameters.
ProgramParameter[] parameterList = new ProgramParameter[2];
// First parameter is to input a name.
AS400Text OperationsItemId = new AS400Text(20);
parameterList[0] = new ProgramParameter(OperationsItemId.toBytes("TestID"));
AS400Text CaseMarkingValue = new AS400Text(20);
parameterList[1] = new ProgramParameter(CaseMarkingValue.toBytes("TestData"));
// Set the program name and parameter list.
program.setProgram(programName, parameterList);
// Run the program.
if (program.run() != true)
{
// Report failure.
System.out.println("Program failed!");
// Show the messages.
AS400Message[] messagelist = program.getMessageList();
for (int i = 0; i < messagelist.length; ++i)
{
// Show each message.
System.out.println(messagelist[i]);
}
}
// Else no error, get output data.
else
{
AS400Text text = new AS400Text(50);
System.out.println(text.toObject(parameterList[1].getOutputData()));
System.out.println(text.toObject(parameterList[2].getOutputData()));
}
}
catch (Exception e)
{
//System.out.println("Program " + program.getProgram() + " issued an exception!");
e.printStackTrace();
}
// Done with the system.
system.disconnectAllServices();
The application Hangs at this lineif (program.run() != true), and I wait for about 10 minutes and then I terminate the application.
Any idea what I am doing wrong?
Edit
Here is the message on the job log:
Client request - run program QSYS/QWCRTVCA.
Client request - run program LIBNAME/FUNNAME.
File P6CASEL2 in library *LIBL not found or inline data file missing.
Error message CPF4101 appeared during OPEN.
Cannot resolve to object YOBPSSR. Type and Subtype X'0201' Authority
FUNNAME insert a row into table P6CASEPF through a view called P6CASEL2. P6CASEL2 is in a different library lets say LIBNAME2. Is there away to maybe set the JobDescription?
Are you sure FUNNAME.PGM is terminating and not hung with a MSGW? Check QSYSOPR for any messages.
Class ProgramCall:
NOTE: When the program runs within the host server job, the library list will be the initial library list specified in the job description in the user profile.
So I saw that my problem is that my library list is not setup, and for some reason, the user we are using, does not have a Job Description. So to over come this I added the following code before calling the program.run()
CommandCall command = new CommandCall(system);
command.run("ADDLIBLE LIB(LIBNAME)");
command.run("ADDLIBLE LIB(LIBNAME2)");
This simply add this LIBNAME, and LIBNAME2 to the user's library list.
Oh yes, the problem is Library list not set ... take a look at this discussion on Midrange.com, there are different work-around ...
http://archive.midrange.com/java400-l/200909/msg00032.html
...
Depe