How to start program from android using direct command

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

How to start program from android using direct command

Postby NNext » Tue Feb 11, 2014 12:05 am

Hi everyone !
I have a question, how to start program in my NXT by sending direct commands from android phone?
I already found that I need to use this direct command:

Code: Select all
Byte 0: 0x80 (or 0x00 if you want a reply)
Byte 1: 0x00
Byte 2-21 file name padded with 0x00.


I tried something like this but it didn't work, please correct me (I put pieces of code).
Code: Select all
public class serviceForBluetooth extends Service
{

   private static final String CHARSET = "US-ASCII";
   public String text = "SonicTest.nxj";
   public byte[] asciiBytes;

 public int startProgram ()
    {
             try
             {
               asciiBytes = encode(text);
                
                byte[] buffer = new byte[16];
               buffer[0] = 0x00; //with response
               buffer[1] = 0x00; // length msb
               buffer[2] = asciiBytes[0];       // PROGRAM NAME 2-21 byte
               buffer[3] = asciiBytes[1];
               buffer[4] = asciiBytes[2];
               buffer[5] = asciiBytes[3];
               buffer[6] = asciiBytes[4];
               buffer[7] = asciiBytes[5];
               buffer[8] = asciiBytes[6];
               buffer[9] = asciiBytes[7];
               buffer[10] = asciiBytes[8]; 
               buffer[11] = asciiBytes[9];
               buffer[12] = asciiBytes[10];
               buffer[13] = asciiBytes[11];
               buffer[14] = asciiBytes[12];
               buffer[15] = asciiBytes[13];
              
               write(buffer);
                return asciiBytes.length;
              }
              catch (Exception e)
             {
                 return 0;
             }
            
         
    }
   
    public static byte[] encode(String str) throws UnsupportedEncodingException {
        // Encode string with ASCII charset
            byte[] ascii;
         ascii = str.getBytes(CHARSET);
         
         byte[] asciiz = new byte[ascii.length + 1];
           System.arraycopy(ascii, 0, asciiz, 0, ascii.length);
           System.arraycopy(new byte[] { 0x00 }, 0, asciiz, asciiz.length - 1, 1);

           return asciiz;
      }

public void write(byte[] buffer) {
            try {
                mmOutStream.write(buffer);
                mmOutStream.flush();
            } catch (IOException e) {
                Log.e(TAG, "Exception during write", e);
            }
        }
}


Thanks for your attention. :)
NNext
New User
 
Posts: 4
Joined: Mon Feb 10, 2014 11:45 pm

Re: How to start program from android using direct command

Postby NNext » Tue Feb 18, 2014 1:13 pm

Seriously, no one knows? I need it really :(
NNext
New User
 
Posts: 4
Joined: Mon Feb 10, 2014 11:45 pm


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 3 guests

cron
more stuff