Page 1 of 4 1234 LastLast
Results 1 to 10 of 32

Thread: Anyone understand Java ? I need help.

  1. #1
    I'm sorry, and you are....? frodobaggins's Avatar
    Join Date
    Jan 2003
    Location
    Ruston, LA
    Posts
    8,846

    Anyone understand Java ? I need help.

    I am trying to figure out some xm stuff, I have all my stuff working great, but I am trying to figure out some additional things. The only real good place to find this info is in the JXM source, but alas, I can't read this ****. I can't tell what info he is sending to the port, or what is returned. Can anyone help ?

    Anyone wanna convert this to English ?

    Frodo
    Attached Files Attached Files
    [H]4 Life
    My next generation Front End is right on schedule.
    It will be done sometime in the next generation.
    I'm a lesbian too.
    I am for hire!

  2. #2
    Maximum Bitrate mobileh1's Avatar
    Join Date
    Apr 2004
    Location
    San Francisco
    Posts
    454
    Have you done any object oriented programming?

    It would be better to convert it into another programming language, since English isnt the best in the world for binary protocols!

    What language do you code in?

    Why not compile it, run it with a COM port monitor and then reverse engineer it.

    There is also

    http://www.openxm.com/

    to check out, its written in perl, so if your not comfortable with OO programs this might be easier.


    If you're still stuck after these tips, then I can provide some examples of what the RadioCommander.java is doing.
    .//Daren
    (Epia M10000/C134) (C137/MII 10000) Liliput /Opus 150W/DVD/512MB/80GB/Hummer H1
    MediaCar/CoPilot7/Routis

  3. #3
    I'm sorry, and you are....? frodobaggins's Avatar
    Join Date
    Jan 2003
    Location
    Ruston, LA
    Posts
    8,846
    Quote Originally Posted by mobileh1
    Have you done any object oriented programming?
    It would be better to convert it into another programming language, since English isnt the best in the world for binary protocols!
    By English I mean pseudocode, with binary represented in Hex.


    What language do you code in?
    VB6


    Why not compile it, run it with a COM port monitor and then reverse engineer it.
    I could do that with the default software. And why re-invent the wheel when
    the info is already out there.


    There is also
    http://www.openxm.com/
    to check out, its written in perl, so if your not comfortable with OO programs this might be easier.
    I already have, and have all the functionality of OPENXM.
    I need some stuff out of here.
    Specifically, everything with "monitor" in the name.


    If you're still stuck after these tips, then I can provide some examples of what the RadioCommander.java is doing.
    Please.

    Frodo
    [H]4 Life
    My next generation Front End is right on schedule.
    It will be done sometime in the next generation.
    I'm a lesbian too.
    I am for hire!

  4. #4
    Banned eatyummypuppies's Avatar
    Join Date
    Feb 2004
    Location
    li, ny
    Posts
    439
    What specifically are you trying to understand in this?

  5. #5
    I'm sorry, and you are....? frodobaggins's Avatar
    Join Date
    Jan 2003
    Location
    Ruston, LA
    Posts
    8,846
    Quote Originally Posted by eatyummypuppies
    What specifically are you trying to understand in this?
    anything in there that has the word "monitor"

    I need to know what it is doing, what bytes it's setting, getting.

    If you could just show me how to read it it would be great.

    Frodo
    [H]4 Life
    My next generation Front End is right on schedule.
    It will be done sometime in the next generation.
    I'm a lesbian too.
    I am for hire!

  6. #6
    Raw Wave wizardPC's Avatar
    Join Date
    Jun 2000
    Location
    Nashville
    Posts
    2,635
    I've had 6 hours of Java, let's see what I can remember......
    Debt as of 1/1/05: $34,354.48
    Debt as of July 4, 2007: $0.00 explanation
    I'M DEBT FREE!!
    I'm now a reasonably successful gunblogger.

  7. #7
    Raw Wave wizardPC's Avatar
    Join Date
    Jun 2000
    Location
    Nashville
    Posts
    2,635
    looking at the code, I realize I need to know what your level of knowledge of object oriented programming is before I can start decoding this for you.

    Do you know about classes, constructors, and dot notation? I don't think VB6 has any of that, so this is why I ask.
    Debt as of 1/1/05: $34,354.48
    Debt as of July 4, 2007: $0.00 explanation
    I'M DEBT FREE!!
    I'm now a reasonably successful gunblogger.

  8. #8
    Variable Bitrate NoPistonPC's Avatar
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    360
    Here's my take on this code, let me know if you want me clarify anything...


    ***** The Command class

    The Command constructor allocates and initializes a byte buffer that holds the command and provides methods for filling in the command data. Subclasses of this class provide additional methods for filling in the command data that is specific to the action that that command represents.

    The format of the command buffer is:

    (n=commandLength)

    Code:
    byte pos   byte len    value     description
    --------   --------    ------    -----------
    0          2	       0x5aa5    xm cmd magic
    2          2           n+1       command length+1 (most significant byte first)
    4          1           type      command type (passed into the constructor)
    5          n+1         ...       command data
    n+5        2           0xeded    command footer (at end of every command)

    setByte() is used set the actual data in the command (starting from byte position 5 above)

    All the classes called cmdXXXXX that extend Command just define a method that fills in the command data in the buffer above.

    Specifically, cmdMonitorLabelChange creates a command buffer with 0x50 as the command type, and has 5 bytes that define the command. So the byte buffer for the MonitorLabelChange command looks like this:

    Code:
    byte pos   byte len    value     description
    --------   --------    ------    -----------
    0          2	       0x5aa5    xm cmd magic
    2          2           0x0006    command length (passed into constructor+1)
    4          1           0x50      command type (passed into the constructor)
    5          1           0x01      XM channel 1 
    6	   1	       0x00      service=false
    7	   1	       0x01      program=true
    8	   1	       0x01	 info=true
    9	   1	       0x00	 extended_info=false
    10         2           0xeded    command footer (at end of every command)
    total length of buffer: 12 bytes


    ***** The Response class

    The Response class holds the bytes that come in as a response to a command. A response is of the same format as a command (see above for a description of the bytes). It is constructed with the buffer holding the response bytes. It has a method for getting a specific byte (getByte()) in the response buffer and also a method (extractString()) for getting a String located at a specific position in the response buffer. Subclasses of the Response class provide methods that parse out data from the response buffer that is specific to that command.

    I think this is what they mean by some command being asynchronous: normally a response comes back in response to a command that is sent. So, I would send a command, wait for a response, then load the response into a buffer and then pull out data form that buffer. However, sometimes responses don't come back right away. In this case, I would send a command and then just not wait for the response since I don't know when it will come back. So, instead of explicitly waiting for this response to come back, what some of the Response subclasses do is define methods for handling themselves when the response comes in. That's what the handle() and isInternal() methods are for.

    respLabelChangeMonitored (SYNCHRONOUS) provides a getChannel() method that pulls out the channel from the response buffer (the channel is a byte long value located at byte 2).

    respMonitorChannelName (ASYNCHRONOUS) gets the channel name via the getChannelName() [string at byte 1] method. The channel number is determined via getChannel() @ byte 0.

    I think you can figure out what the rest of respXXXX Response classes do by looking at their getXXXXX() methods and handle() methods.
    1994 RX-7, EPIA P4-ITX w/ Celeron 2.4 Ghz, Arise PSU, Xenarc 700TSV (new model)

  9. #9
    Banned eatyummypuppies's Avatar
    Join Date
    Feb 2004
    Location
    li, ny
    Posts
    439
    Well that makes more sense than what I was going to say.

  10. #10
    Maximum Bitrate mobileh1's Avatar
    Join Date
    Apr 2004
    Location
    San Francisco
    Posts
    454
    A few java things for a VB programmer.

    the java datatype byte is a 1 byte 7 bit signed primitive with data values from -128 to 127. This is why you see code like getByte(0) & 0xff. This will be the same in any language, but the java specifics of it are to make the byte an unsigned int value, so you can write code like:

    byte b1=-1;
    if( (b1 & 0xff) == 255 )
    {
    // it does, -1 is 255...
    }

    The Response class has the meat of the methods, and they are pretty basic byte manipulations, except the bcd and date methods.

    BCD is binary coded decimal. Its been a while since I did any VB, so I cannot remember what VB makes of them, but in the program they are only used as an intermediate format in date representations. BCD is a simple, take a number, say 501, the BCD is the binary for each digit, so 101, 0, 1. Since the highest any DCB digit can be is 9, only the first 'half' of a byte is needed, the upper 4 bits (each of the 2 pairs of 4 bits are called nibbles) are wasted, so putting in the leading zeros, the example would be

    0000,0101 0000,0000 0000,0001

    The author is correct, since 9 in hex is the same as decimal, take the byte, convert it to hex and take the zeroth character from the result. If VB doesnt have a format as hex method there are many other ways to do the same conversion.


    Lets take the 0xD1 response (channel name change):

    private class respMonitorChannelName extends Response {
    public respMonitorChannelName(byte[] data) {
    super(data);
    }
    public boolean isInternal() {
    return true;
    }
    public void handle() {
    Log("Got channel name monitor response: ch=" + Integer.toString(this.getChannel()) +
    " -> " + this.getChannelName());
    RadioCommander.this.currentChannelInfo.setChannelN ame(this.getChannelName());
    RadioCommander.this.updateChannelInfo();
    }
    public int getChannel() {
    return this.getByte(0) & 0xff;
    }
    public String getChannelName() {
    if (this.getByte(1) == 0)
    return null;
    else
    return this.extractString(2, 16);
    }
    }

    The data array contains the response data.

    getChannel() simply takes byte[0] How long is it going to be before there are more than 255 channels I wonder...

    Anyway, the next part is the data between bytes 2 and 16 (inclusive). These are converted to a java string by iterating over the characters and adding them to a String Object unless the values is outside the ASCII range.

    Let me know if there are any other methods that dont make sense and I'll have a look.
    .//Daren
    (Epia M10000/C134) (C137/MII 10000) Liliput /Opus 150W/DVD/512MB/80GB/Hummer H1
    MediaCar/CoPilot7/Routis

Page 1 of 4 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •