Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
What is the feasibility of writing and deploying a java application onto a Trimble unit running Windows Mobile 6. I am writing another GIS system that will have that target platform. I plan on writing it in C#, but I want to investigate further into the possibility of using Java so the code could be multiplatform and possibly incorporate the rest of all our other code (the vast majority of which is in Java).

Basically, I have to justify not using Java.

Adbot
ADBOT LOVES YOU

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?

Kaltag posted:

What is the feasibility of writing and deploying a java application onto a Trimble unit running Windows Mobile 6. I am writing another GIS system that will have that target platform. I plan on writing it in C#, but I want to investigate further into the possibility of using Java so the code could be multiplatform and possibly incorporate the rest of all our other code (the vast majority of which is in Java).

Basically, I have to justify not using Java.


So I've looked into it and the main issue is getting a good JVM for WM6. The free ones are open source and the others cost money. Does anyone have experience with the wm6 open source jvm? It looks like poo poo on the website.

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
Is there a way to add an actionlister to a tab in a JTabbedPane that fires every time that pane is selected? Google is being stupid.

I'm using swing btw, bosses' orders.

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
I am writing an FTP client. I am testing downloading a jpg. When I download it, it looks all hosed up and when I examine it in a hex editor it seems only every 100th byte or so is messed up. Other than that the file is the correct size, the bytes seem to be in the correct order etc, its just that every 100th bit or so is messed up.

my download routine, it looks hosed up because I'm still working on it and has some other things I tried commented out

code:
public BufferedReader defaultIn = null; //binded to socket elsewhere
public BufferedReader passiveIn = null; //binded to socket elsewhere

public boolean download(String file)
{
        ArrayList<FTPFile> files = list();
        if(files.size() != 0)
	{
	        int i;
		for(i = 0; i < files.size(); i++)
		{
			if(files.get(i).getName().trim().compareToIgnoreCase(file.trim()) == 0)
			{
				System.out.println("File Size: " + files.get(i).getSize());
				break;
			}
		}
		send("TYPE I");
		System.out.println(getResponse(defaultIn));
		send("PASV");
		String portCommand = getResponse(defaultIn);
		System.out.println(portCommand);
		if(getPassiveSock(portCommand))
		{
			send("RETR " + file);
			System.out.println(getResponse(defaultIn));
	
			File f = new File(path + sensorName + "_" + file);
				
			byte[] fileBytes = new byte[Integer.parseInt(files.get(i).getSize())];
			System.out.println("filesize: " + files.get(i).getSize());
			try
			{
				FileOutputStream out = new FileOutputStream(f);
				//IMPORTANT PART GOONS!
				//while(passiveIn.ready())
				for(int j = 0; j < Integer.parseInt(files.get(i).getSize()); j ++ )
				{
					out.write(passiveIn.read());
					//fileBytes[j] = (byte) passiveIn.read();
				} 
				//out.write(fileBytes, 0, fileBytes.length - 1);
				out.close();
				System.out.println("Done Transferring File");		
			}
			catch (Exception e)
			{
				System.out.println("Problem Writing File");
			}
			closePassiveSock();
			return true;
		} 
		else 
		{
			closePassiveSock();
			return false;
		}
	}
	System.out.println("List command failed");
	return false;
}
This is the important part. Things commented out are other things I've been trying but end with the same problem.

code:
//byte[] fileBytes = new byte[Integer.parseInt(files.get(i).getSize())];
//while(passiveIn.ready())
for(int j = 0; j < Integer.parseInt(files.get(i).getSize()); j ++ )
{
	out.write(passiveIn.read());
	//fileBytes[j] = (byte) passiveIn.read();
} 
//out.write(fileBytes, 0, fileBytes.length - 1);
out.close
I think the issue lies in the read/write routine and somehow my data is being corrupted. BufferedReader.read() is the closest thing to reading a single byte I have and I haven't found any good alternatives.

I will add that this seems to work for text files and small files.

EDIT: I think the problem lies in that bufferedreader can not read a single byte, it reads ints instead. Even though I have not implemented the solution I will leave this up as I work so you can mock my code.

EDIT2: I am an idiot and need to use DataInputStream instead of bufferedreader

EDIT3: It worked

Kaltag fucked around with this message at 14:57 on Jun 19, 2009

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
thanks for the side read/write tip

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
What the hell is going on?

I can't get a JPopupMenu to only show up when you right click. I understand this is refered to the 'windows look and feel' but I can't get it to take. I know that the BasicPopupMenuUI refers to the windows look and feel for popup menus, but like I said, won't do it.

code:
popUp = new JPopupMenu();

popUp.setUI(new BasicPopupMenuUI()); //this doesn't work

BasicPopupMenuUI wlf = new BasicPopupMenuUI(); 
wlf.installUI(popUp); //neither does this

popUp.setUI(wlf); //what the gently caress!?!?

menuItem = new JMenuItem("Create Spectrograms...");
menuItem.addActionListener(new MenuItemListener());
popUp.add(menuItem);
Maybe I have to implement this in my actionlistener?

code:
public class MenuItemListener implements ActionListener
{
	MenuItemListener(){}

	public void actionPerformed(ActionEvent actevent) 
        {
	    String cmd = actevent.getActionCommand();
	    if (cmd.equalsIgnoreCase("Create Spectrograms...")) 
	    {
	    	System.out.println("GOING TO CREATE SPECGRAMMIES");
	    }
	}
}
Java gui work is not my thing, I usually do C and data processing poo poo so feel free to berate me.

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?

yeah I've read over that like a million times already

I already have the popupmenu showing up its just that I don't want it to show up when i left click, maybe i wasnt clear

Kaltag fucked around with this message at 21:42 on Sep 3, 2009

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?

rhag posted:

The "e.isPopupTrigger()" line is essential in this case.

That's all I needed to hear.

popUp.setUI(new BasicPopupMenuUI()); sets the windows look and feel, causing isPopUpTrigger to be true only when there is a right click. I only had to modify my actionlistener that added to my menuItem to include the line

code:
if(e.isPopupTrigger())
    popUp.show(e.getComponent(), e.getX(), e.getY());
and it works just great.

I'm guessing unless you set the UI to be new BasicPopupMenuUI() then e.isPopupTrigger will always be true, by default.

Thanks rhag!

VV right again

Kaltag fucked around with this message at 14:33 on Sep 4, 2009

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
I'm having a stupid problem writing strings over sockets in Java when I am using linux. What I'm trying to do works fine in Windows.

When I use PrintWriter to send a string command over a socket in Linux using println(message), it chops the last character off, so if the message was "/data" the other end only gets "/dat". I know linux only uses a line feed instead of a line feed and carriage return like windows as the separator, but the println command uses the separator for the platform, so that shouldn't matter.

I tried lots of different mixing up of line feeds, carriage returns, and null terminators, but it didn't work. I even converted the string to a char array, appended a null terminator, then a line feed, and used .print(charArray) and it still doesn't work. Every permutation doesn't work. I also noticed if I added another null terminator to the end of the string, it would chop off 2 characters instead of just one.

So far I've been able to jury rig it by checking the platform, and if its linux, to add an extra space so that space just gets chopped off instead of the end of my message, but I'm not satisfied.

Kaltag fucked around with this message at 12:56 on Sep 29, 2009

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
The other side is an embedded system that runs a very unrobust FTP server. I only know that the last character is getting chopped because when I send "CWD /data" it returns with "Can't open directory /dat". My boss wrote the embedded FTP and perhaps he didn't anticipate the different line separators for linux and windows. I'm going to work on it some more before I walk up to him and tell him that his code is wrong.

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
excellent, thanks

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
*resolved

Kaltag fucked around with this message at 14:25 on Mar 8, 2010

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
Could anyone recommend to me a way to send SMS messages using java? So far I see that I can get a GMS modem or use a web service that java can access, or a java library that uses a web service or hell I don't know. These are things I learned from google, and there are many .jars out there that claim to be the best at sending sms.

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
I don't want to have to know what carriers my targets are using. I also don't want to use anything "free" lest my customers get loving ads or end up on a mailing list. Also, security is an issue.

I actually found http://www.message-media.com/ and they had a fairly simple api I was able to import to eclipse and I talked to their sales people and got 50 free texts to test with. I guess later you end up buying bulk once your poo poo hits mainstream.

As the program I am working on gets more serious we'll probably just start integrating a gsm modem and proper provider.

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
Whats the best way to make java do something every 3 hours then do nothing in between?

code:
while(true)
{
   Thread.sleep(3*60*60*1000);
   doSomething();
}
Seems too easy to be true. Of course I would add some code to make sure that the time that doSomething() took to run is counted, but this gets the basic idea across.

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
Is this what you mean?

http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
I am only researching the feasibility of this idea.

I know that this is ridiculously low level stuff for Java and I'll probably get laughed out of here but has anyone here ever heard of using Java to bit-bang a SPI interface or interfaced with a USB to SPI adapter? Would it be possible to control single I/O pins in a serial port or other general I/O pin? Could Java supply an appropriate clock of ~48kHz?

From my research the best bet would be to use a C or assembly library wrapped in JNI to do the dirty stuff.

Adbot
ADBOT LOVES YOU

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
I'm having trouble getting integer values from a byte buffer filled with signed 16 bit little endian audio samples. I am getting it mostly right, as strange as it sounds, but I'm getting little spikes in my data that look like this...



The spikes have a difference with the rest of the curve of 256, 2^8 so I know that a I'm loving up my bits somewhere.

This problem has been found and explained in this thread, however their solutions do not work for me.
http://forums.sun.com/thread.jspa?threadID=5420508

These are methods I have tried, they all result in the same type of noise being introduced into my output.
code:
byte[] rawInBuffer = new byte[(int)numBytes];
int read = audioInputStream.read(rawInBuffer, 0, rawInBuffer.length);
System.out.println("num bytes read: " + read);
			
int[] returning = new int[(int)numSamples]; 
for (int i = 0, k = 0; i < numSamples - 1; i++)
{			
    byte firstByte = rawInBuffer[++k];
    byte secondByte = rawInBuffer[++k];

    int low = secondByte & 0xff;
    int high = firstByte;
    int returning[i] = (high << 8 | low);
}
code:
byte[] rawInBuffer = new byte[(int)numBytes];
int read = audioInputStream.read(rawInBuffer, 0, rawInBuffer.length);
System.out.println("num bytes read: " + read);
			
int[] returning = new int[(int)numSamples]; 
for (int i = 0, k = 0; i < numSamples - 1; i++)
{			
    ByteBuffer byteBuff = ByteBuffer.allocate(2);
    byteBuff.order(ByteOrder.LITTLE_ENDIAN);
				
    byte firstByte = rawInBuffer[++k];
    byte secondByte = rawInBuffer[++k];
    byteBuff.put(secondByte);
    byteBuff.put(firstByte);
				
    returning[i] = (int) byteBuff.getShort(0);
}
code:
byte[] rawInBuffer = new byte[(int)numBytes];
int read = audioInputStream.read(rawInBuffer, 0, rawInBuffer.length);
System.out.println("num bytes read: " + read);
			
int[] returning = new int[(int)numSamples]; 
for (int i = 0, k = 0; i < numSamples - 1; i++)
{			
   byte firstByte = rawInBuffer[++k];
   byte secondByte = rawInBuffer[++k];


   int d = 0;
   for (int j = 0; j < 8; j++) 
   {
       if (((secondByte >>> j) & 1) == 1) 
       {
           d += (int) Math.pow(2, j);
       }
   }
   for (int j = 0; j < 7; j++) 
   {
       if (((firstByte >>> j) & 1) == 1) 
       {
           d += (int) Math.pow(2, j+8);
       }
   }
   if (((firstByte >>> 7) & 1) == 1) 
   {
       d -= Math.pow(2, 15);
   }
				
    returning[i] = (int) d;
}
Excuse the formatting and if any of that doesn't compile I had to make a few minor changes to cleanly separate that from my code. I know the problem has to do with the samples being signed, the sign bit is loving me up. What is the best way to take the value of the same, sign bit included, without being a douche about it?

Edit: Ended up writing my own wav file processor and reading the samples straight out of the file instead of relying on audioInputStream.read(). Oh well, at least it works.

Kaltag fucked around with this message at 16:28 on Sep 14, 2010

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply