OSDN Git Service

とりあえず、軽くシャッターを切るところまで。
authorMRSa <mrsa@myad.jp>
Wed, 1 May 2019 12:05:49 +0000 (21:05 +0900)
committerMRSa <mrsa@myad.jp>
Wed, 1 May 2019 12:05:49 +0000 (21:05 +0900)
app/src/main/java/net/osdn/gokigen/cameratest/camtest/CamTest.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/Communication.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/Connection.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/FujiAsyncResponseReceiver.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/cameratest/fuji/FujiStreamReceiver.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/MessageSequence.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/ReceivedData.java
app/src/main/res/values/strings.xml

index e1878d7..18f2797 100644 (file)
@@ -84,7 +84,7 @@ public class CamTest implements View.OnClickListener
         switch (id)
         {
             case R.id.button1:
-                showMessageText("Button1");
+                doShutter();
                 break;
             case R.id.button2:
                 showMessageText("Button2");
@@ -97,4 +97,31 @@ public class CamTest implements View.OnClickListener
                 break;
         }
     }
+
+
+    private void doShutter()
+    {
+        Log.v(TAG, "execute shutter");
+        try
+        {
+            Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.shutter, Snackbar.LENGTH_SHORT).show();
+            showMessageText("SHUTTER");
+            Thread thread = new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    boolean ret = connection.execute_shutter();
+                    if (!ret)
+                    {
+                        showMessageText("SHUTTER FAILURE...");
+                    }
+                }
+            });
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
 }
index 5567e03..1fce41a 100644 (file)
@@ -2,11 +2,8 @@ package net.osdn.gokigen.cameratest.fuji;
 
 import android.util.Log;
 
-import java.io.BufferedInputStream;
 import java.io.BufferedReader;
-import java.io.DataInputStream;
 import java.io.DataOutputStream;
-import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.Socket;
 import java.util.Arrays;
@@ -27,12 +24,14 @@ class Communication
     private DataOutputStream dos = null;
     //private DataInputStream dis = null;
     BufferedReader bufferedReader = null;
+    private final FujiStreamReceiver stream;
+    private final FujiAsyncResponseReceiver response;
 
 
     Communication()
     {
-
-
+        this.stream = new FujiStreamReceiver(camera_ip, STREAM_PORT);
+        this.response = new FujiAsyncResponseReceiver(camera_ip, ASYNC_RESPONSE_PORT);
     }
 
     void connect_socket()
@@ -137,29 +136,44 @@ class Communication
         int receive_bytes = 0;
         InputStreamReader isr = null;
         byte[] byte_array = new byte[BUFFER_SIZE];
+        char[] char_array = new char[BUFFER_SIZE];
         try
         {
             Log.v(TAG, "receive_from_camera() : start.");
-             isr  = new InputStreamReader(socket.getInputStream());
+            isr  = new InputStreamReader(socket.getInputStream());
 
+/////////////////////////
+            int read_bytes = isr.read(char_array, 0, BUFFER_SIZE);
+            Log.v(TAG, "receive_from_camera() : " + read_bytes + " bytes.");
+            return (new ReceivedData(char_array, read_bytes));
+/////////////////////////
+/*
             int data = isr.read();
-            Log.v(TAG, "receive_from_camera() : #1 ");
+            byte_array[0] = (byte) data;
 
-            int read_bytes = 0;
+            Log.v(TAG, "receive_from_camera() : #1  : " + byte_array[0]);
+
+            int length = data - 1;
+            int read_bytes = 1;
             //while (data != -1)
-            while ((data >= 0)&&(data <= 255))
+            //while ((data >= 0)&&(data <= 255))
+            for (int index = 0; index < length; index++)
             {
+                data = isr.read();
+                //if ((data < 0)||(data > 255))
+                {
+                //    break;
+                }
                 Log.v(TAG, "receive_from_camera() : #2 (" + read_bytes + ") " + data);
-
                 byte_array[read_bytes] = (byte) data;
                 read_bytes++;
-                data = isr.read();
             }
             receive_bytes = read_bytes;
 
             //isr.close();
-
-            /*
+*/
+/////////////////////////
+/*
             dis = new DataInputStream(socket.getInputStream());
             //BufferedInputStream stream = new BufferedInputStream(is);
             while (receive_bytes < BUFFER_SIZE)
@@ -329,4 +343,23 @@ bool is_success_response(uint32_t const id, void const* buffer,
  */
 
 
+
+    void start_stream()
+    {
+        stream.start();
+    }
+    void stop_stream()
+    {
+        stream.stop();
+    }
+
+    void start_response()
+    {
+        response.start();
+    }
+    void stop_response()
+    {
+        response.stop();
+    }
+
 }
index c603367..7edc801 100644 (file)
@@ -18,8 +18,10 @@ public class Connection
     {
         boolean ret = false;
 
-        ret = connect_to_camera();
-
+        if (connect_to_camera())
+        {
+            ret = get_current_settings();
+        }
         return (ret);
     }
 
@@ -40,18 +42,98 @@ public class Connection
 /*
             応答エラーの場合は この値が返ってくるはず  = {0x05, 0x00, 0x00, 0x00, 0x19, 0x20, 0x00, 0x00};
 */
+
+            // start_messageを送信
             comm.send_to_camera(sequence.start_message());
 
             rx_bytes = comm.receive_from_camera();
             dump_bytes(indexNumber, rx_bytes);
             indexNumber++;
 
+/**/
+            //  なんだろう?? (必要なようだが)
+            comm.send_to_camera(sequence.start_message2());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+/**/
+
+            // two_part messageを発行 (その1)
+            comm.send_to_camera(sequence.start_message3_1());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+
+            // two_part messageを発行 (その2)
+            comm.send_to_camera(sequence.start_message3_2());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+
+            // remote mode
+            comm.send_to_camera(sequence.start_message4());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+
+
+            // two_part messageを発行 (その1)
+            comm.send_to_camera(sequence.start_message5_1());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+
+            // two_part messageを発行 (その2)
+            comm.send_to_camera(sequence.start_message5_2());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+
+
+            // ????
+            comm.send_to_camera(sequence.start_message6());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+
+
+            // ????
+            comm.send_to_camera(sequence.start_message7());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+
+            // ????
+            comm.send_to_camera(sequence.start_message8());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+
+            // ????
+            comm.send_to_camera(sequence.start_message9());
+
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(indexNumber, rx_bytes);
+            indexNumber++;
+
+
+/*
             comm.send_to_camera(sequence.start_message2());
 
             //byte[] rx_bytes = comm.receive_from_camera();
             rx_bytes = comm.receive_from_camera();
             dump_bytes(indexNumber, rx_bytes);
             indexNumber++;
+*/
 /*
             応答OKの場合は、8バイト ({0x03, 0x00, 0x01, 0x20} + {0x10, 0x02, 0x00, 0x00} )が応答されるはず
 
@@ -65,6 +147,11 @@ public class Connection
             fuji_twopart_message(sockfd, msg4_1, msg4_2);
 */
 
+            // 別のポートもオープンしておく
+            comm.start_stream();
+            comm.start_response();
+
+            Log.v(TAG, "connect_to_camera DONE.");
 
             return (true);
         }
@@ -75,6 +162,28 @@ public class Connection
         return (false);
     }
 
+    private boolean get_current_settings()
+    {
+        try
+        {
+            comm.send_to_camera(sequence.status_request_message());
+
+            ReceivedData rx_bytes = comm.receive_from_camera();
+            dump_bytes(12, rx_bytes);
+
+            // なんで2回... でもやってみる
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(13, rx_bytes);
+
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
+
+
 
     private void dump_bytes(int indexNumber,ReceivedData data)
     {
@@ -98,4 +207,25 @@ public class Connection
         }
         System.gc();
     }
+
+    public boolean execute_shutter()
+    {
+        try
+        {
+            comm.send_to_camera(sequence.execute_shutter_message());
+
+            ReceivedData rx_bytes = comm.receive_from_camera();
+            dump_bytes(14, rx_bytes);
+
+            // なんで2回... でもやってみる
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(15, rx_bytes);
+
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
 }
diff --git a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/FujiAsyncResponseReceiver.java b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/FujiAsyncResponseReceiver.java
new file mode 100644 (file)
index 0000000..e9360c9
--- /dev/null
@@ -0,0 +1,93 @@
+package net.osdn.gokigen.cameratest.fuji;
+
+import android.util.Log;
+
+import java.io.InputStream;
+import java.net.Socket;
+
+public class FujiAsyncResponseReceiver
+{
+    private final String TAG = toString();
+    private final String ipAddress;
+    private final int portNumber;
+    private static final int WAIT_MS = 750;
+    private boolean isStart = false;
+
+    FujiAsyncResponseReceiver(String ip, int portNumber)
+    {
+        this.ipAddress = ip;
+        this.portNumber = portNumber;
+    }
+
+    void start()
+    {
+        isStart = true;
+        Thread thread = new Thread(new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                try
+                {
+                    Socket socket = new Socket(ipAddress, portNumber);
+                    startReceive(socket);
+                }
+                catch (Exception e)
+                {
+                    Log.v(TAG, " IP : " + ipAddress + " port : " + portNumber);
+                    e.printStackTrace();
+                }
+            }
+        });
+        try
+        {
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    void stop()
+    {
+        isStart = false;
+    }
+
+    private void startReceive(Socket socket)
+    {
+        InputStream from = null;
+        Log.v(TAG, "startReceive() start.");
+        while (isStart)
+        {
+            try
+            {
+                from = socket.getInputStream();
+                int value = 0;
+                int count = 0;
+                while ((value = from.read()) != -1)
+                {
+                    Log.v(TAG, " READ [" + count + "] " + value);
+                    count++;
+                }
+                Thread.sleep(WAIT_MS);
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+        if (from != null)
+        {
+            try
+            {
+                from.close();
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+        Log.v(TAG, "startReceive() end.");
+    }
+}
index e6f3785..cb4b91a 100644 (file)
@@ -1,21 +1,24 @@
 package net.osdn.gokigen.cameratest.fuji;
 
+import android.util.Log;
+
 import java.io.InputStream;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 
-public class FujiStreamReceiver
+class FujiStreamReceiver
 {
+    private final String TAG = toString();
+    private final String ipAddress;
     private final int portNumber;
     private static final int WAIT_MS = 750;
     private boolean isStart = false;
 
-    FujiStreamReceiver(int portNumber)
+    FujiStreamReceiver(String ip, int portNumber)
     {
+        this.ipAddress = ip;
         this.portNumber = portNumber;
-
-
     }
 
     void start()
@@ -28,13 +31,19 @@ public class FujiStreamReceiver
             {
                 try
                 {
+                    Socket socket = new Socket(ipAddress, portNumber);
+                    startReceive(socket);
+
+                    /*
                     ServerSocket listener = new ServerSocket();
                     listener.setReuseAddress(true);
                     listener.bind(new InetSocketAddress(portNumber));
                     watchMain(listener);
+                    */
                 }
                 catch (Exception e)
                 {
+                    Log.v(TAG, " IP : " + ipAddress + " port : " + portNumber);
                     e.printStackTrace();
                 }
             }
@@ -49,21 +58,65 @@ public class FujiStreamReceiver
         }
     }
 
-
     void stop()
     {
         isStart = false;
     }
 
+    private void startReceive(Socket socket)
+    {
+        InputStream from = null;
+        Log.v(TAG, "startReceive() start.");
+        while (isStart)
+        {
+            try
+            {
+                from = socket.getInputStream();
+                int value = 0;
+                int count = 0;
+                while ((value = from.read()) != -1)
+                {
+                    Log.v(TAG, " READ [" + count + "] " + value);
+                    count++;
+                }
+                Thread.sleep(WAIT_MS);
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+        if (from != null)
+        {
+            try
+            {
+                from.close();
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+        Log.v(TAG, "startReceive() end.");
+    }
+
     private void watchMain(ServerSocket listener)
     {
+        InputStream from = null;
+        Log.v(TAG, "watchMain() start.");
         while (isStart)
         {
             try
             {
                 Socket socket = listener.accept();
-                InputStream from = socket.getInputStream();
-
+                from = socket.getInputStream();
+                int value = 0;
+                int count = 0;
+                while ((value = from.read()) != -1)
+                {
+                    Log.v(TAG, " READ [" + count + "] " + value);
+                    count++;
+                }
                 Thread.sleep(WAIT_MS);
             }
             catch (Exception e)
@@ -71,9 +124,18 @@ public class FujiStreamReceiver
                 e.printStackTrace();
             }
         }
+        if (from != null)
+        {
+            try
+            {
+                from.close();
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+        Log.v(TAG, "watchMain() end.");
     }
 
-
-
-
 }
index e8c5536..c70e6e3 100644 (file)
@@ -38,28 +38,22 @@ class MessageSequence
                 (byte)0xad, (byte)0xa5, (byte)0x48, (byte)0x5d, (byte)0x87, (byte)0xb2, (byte)0x7f, (byte)0x0b,
                 (byte)0xd3, (byte)0xd5, (byte)0xde, (byte)0xd0, // (byte)0x02, (byte)0x78, (byte)0xa8, (byte)0xc0,
                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+/**/
                 // device_name 'ASUS_Z01BDA-2348'
                 (byte)0x41, (byte)0x00, (byte)0x53, (byte)0x00, (byte)0x55, (byte)0x00, (byte)0x53, (byte)0x00,
                 (byte)0x5f, (byte)0x00, (byte)0x5a, (byte)0x00, (byte)0x30, (byte)0x00, (byte)0x31, (byte)0x00,
                 (byte)0x42, (byte)0x00, (byte)0x44, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x2d, (byte)0x00,
                 (byte)0x32, (byte)0x00, (byte)0x33, (byte)0x00, (byte)0x34, (byte)0x00, (byte)0x38, (byte)0x00,
-
                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
-
-/*
-                (byte)0xb0, (byte)0x00, (byte)0xf5, (byte)0x00, (byte)0x5d, (byte)0x00, (byte)0xa1, (byte)0x00,
-                (byte)0x7f, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
-*/
-/**/
                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
 /**/
 /*
-                // device_name 'GOKIGEN device 0'
+                // device_name 'GOKIGEN____0123'
                 (byte)0x47, (byte)0x00, (byte)0x4f, (byte)0x00, (byte)0x4b, (byte)0x00, (byte)0x49, (byte)0x00,
-                (byte)0x47, (byte)0x00, (byte)0x45, (byte)0x00, (byte)0x4e, (byte)0x00, (byte)0x00, (byte)0x00,
-                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
-                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+                (byte)0x47, (byte)0x00, (byte)0x45, (byte)0x00, (byte)0x4e, (byte)0x00, (byte)0x5f, (byte)0x00,
+                (byte)0x5f, (byte)0x00, (byte)0x5f, (byte)0x00, (byte)0x5f, (byte)0x00, (byte)0x30, (byte)0x00,
+                (byte)0x31, (byte)0x00, (byte)0x32, (byte)0x00, (byte)0x33, (byte)0x00, (byte)0x00, (byte)0x00,
                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
@@ -83,35 +77,292 @@ class MessageSequence
                 (byte) 0x01, (byte) 0x00, (byte) 0x02, (byte) 0x10, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                 (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
 */
-                // START (0x1002)
-                (byte)0x10, (byte)0x02,
-                // index
-                (byte)0x00, (byte)0x01,
-                // data
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : START (0x1002)
+                (byte)0x02, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる)
+                (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
                 (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00,
         });
     }
 
-
     byte[] start_message2()
     {
         return (new byte[] {
-                //
+/*
+                //  現物...
                 (byte) 0x01, (byte) 0x00, (byte) 0x15, (byte) 0x10, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                 (byte) 0x12, (byte) 0xd2, (byte) 0x00, (byte) 0x00,
+*/
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : single_part (0x1015)
+                (byte)0x15, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる)
+                (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x12, (byte)0xd2, (byte)0x00, (byte)0x00,
+
+        });
+    }
+
+    byte[] start_message3_1()
+    {
+        return (new byte[] {
 /*
-                // START (0x1002)
-                (byte)0x10, (byte)0x02,
-                // index
-                (byte)0x00, (byte)0x01,
-                // data
-                (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00,
+                //  現物...
+                (byte) 0x01, (byte) 0x00, (byte) 0x16, (byte) 0x10, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x01, (byte) 0xdf, (byte) 0x00, (byte) 0x00,
+*/
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : two_part (0x1016)
+                (byte)0x16, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる)
+                (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x01, (byte)0xdf, (byte)0x00, (byte)0x00,
+
+        });
+    }
+
+    byte[] start_message3_2()
+    {
+        return (new byte[] {
+/*
+                //  現物...
+                (byte) 0x02, (byte) 0x00, (byte) 0x16, (byte) 0x10, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x05, (byte) 0x00,
+*/
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x02, (byte)0x00,
+
+                // message_header.type : two_part (0x1016)
+                (byte)0x16, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる...けど two-part messageなので同じ)
+                (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x05, (byte)0x00,
+
+        });
+    }
+
+
+    byte[] start_message4()
+    {
+        return (new byte[] {
+/*
+                //  現物...
+                (byte) 0x01, (byte) 0x00, (byte) 0x15, (byte) 0x10, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x24, (byte) 0xdf, (byte) 0x00, (byte) 0x00,
+*/
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : single_part (0x1015)
+                (byte)0x15, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる)
+                (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x24, (byte)0xdf, (byte)0x00, (byte)0x00,
+
+        });
+    }
+
+    byte[] start_message5_1()
+    {
+        return (new byte[] {
+/*
+                //  現物...
+                (byte) 0x01, (byte) 0x00, (byte) 0x16, (byte) 0x10, (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x24, (byte) 0xdf, (byte) 0x00, (byte) 0x00,
+*/
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : two_part (0x1016)
+                (byte)0x16, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる)
+                (byte)0x05, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x24, (byte)0xdf, (byte)0x00, (byte)0x00,
+
+        });
+    }
+
+    byte[] start_message5_2()
+    {
+        return (new byte[] {
+/*
+                //  現物...
+                (byte) 0x02, (byte) 0x00, (byte) 0x16, (byte) 0x10, (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00,
+*/
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x02, (byte)0x00,
+
+                // message_header.type : two_part (0x1016)
+                (byte)0x16, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる...けど two-part messageなので同じ)
+                (byte)0x05, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x07, (byte)0x00, (byte)0x02, (byte)0x00,
+
+        });
+    }
+
+    byte[] start_message6()
+    {
+        return (new byte[] {
+/*
+                //  現物...
+                (byte) 0x01, (byte) 0x00, (byte) 0x15, (byte) 0x10, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x12, (byte) 0xd2, (byte) 0x00, (byte) 0x00,
+*/
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : single_part (0x1015)
+                (byte)0x15, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる...)
+                (byte)0x06, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x12, (byte)0xd2, (byte)0x00, (byte)0x00,
+
+        });
+    }
+
+
+    byte[] start_message7()
+    {
+        return (new byte[] {
+/*
+                //  現物...
+                (byte) 0x01, (byte) 0x00, (byte) 0x2b, (byte) 0x90, (byte) 0x07, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+*/
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : camera_capabilities (0x902b)
+                (byte)0x2b, (byte)0x90,
+
+                // message_id (0~1づつ繰り上がる...)
+                (byte)0x07, (byte)0x00, (byte)0x00, (byte)0x00,
+
+        });
+    }
+
+
+    byte[] start_message8()
+    {
+        return (new byte[] {
+/*
+                //  現物...
+                (byte) 0x01, (byte) 0x00, (byte) 0x15, (byte) 0x10, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x12, (byte) 0xd2, (byte) 0x00, (byte) 0x00
 */
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : single_part (0x1015)
+                (byte)0x15, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる...)
+                (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x12, (byte)0xd2, (byte)0x00, (byte)0x00,
+
         });
     }
 
 
 
+    byte[] start_message9()
+    {
+        return (new byte[] {
+/*
+                //  現物...
+                (byte) 0x01, (byte) 0x00, (byte) 0x1c, (byte) 0x10, (byte) 0x09, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
+*/
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : camera_remote (0x101c)
+                (byte)0x1c, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる...)
+                (byte)0x09, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+
+        });
+    }
+
+
+    byte[] status_request_message()
+    {
+        return (new byte[] {
+
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : single_part (0x1015)
+                (byte)0x15, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる...)
+                (byte)0x0A, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x12, (byte)0xd2, (byte)0x00, (byte)0x00,
+        });
+    }
+
+
+    byte[] execute_shutter_message()
+    {
+        return (new byte[] {
+
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : shutter (0x100e)
+                (byte)0x0e, (byte)0x10,
+
+                // message_id (0~1づつ繰り上がる...
+                (byte)0x0B, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+        });
+    }
+
+
     byte[] two_part_message_One()
     {
         return (new byte[] {
index 48eeaa4..a548b17 100644 (file)
@@ -1,5 +1,8 @@
 package net.osdn.gokigen.cameratest.fuji;
 
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
 import java.util.Arrays;
 
 class ReceivedData
@@ -12,8 +15,23 @@ class ReceivedData
         this.data = Arrays.copyOfRange(data, 0, length);
     }
 
+    ReceivedData(char[] data, int length)
+    {
+        byte[] convertedData = toBytes(data);
+        this.data = Arrays.copyOfRange(convertedData, 0, length);
+    }
+
     byte[] getData()
     {
         return (data);
     }
+
+    private byte[] toBytes(char[] chars)
+    {
+        CharBuffer charBuffer = CharBuffer.wrap(chars);
+        ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(charBuffer);
+        byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit());
+        Arrays.fill(byteBuffer.array(), (byte) 0);
+        return (bytes);
+    }
 }
index b551028..100e525 100644 (file)
@@ -5,6 +5,7 @@
     <string name="action_wifi_settings">WiFi Settings</string>
     <string name="section_format">Hello World from section: %1$d</string>
     <string name="connect">Try connect</string>
+    <string name="shutter">Execute Shutter</string>
     <string name="label_button1">1</string>
     <string name="label_button2">2</string>
     <string name="label_button3">3</string>