OSDN Git Service

ステータス受信準備。その2。
authorMRSa <mrsa@myad.jp>
Fri, 10 May 2019 16:02:41 +0000 (01:02 +0900)
committerMRSa <mrsa@myad.jp>
Fri, 10 May 2019 16:02:41 +0000 (01:02 +0900)
app/src/main/java/net/osdn/gokigen/cameratest/camtest/CamTest.java
app/src/main/java/net/osdn/gokigen/cameratest/camtest/InformationView.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/cameratest/fuji/Connection.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/ILiveViewImage.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/FujiStatusChecker.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/FujiStatusHolder.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/IFujiStatus.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/IFujiStatusNotify.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/IFujiStatusReceive.java
app/src/main/res/layout/fragment_main.xml

index 9a466a0..37a4ad2 100644 (file)
@@ -4,7 +4,6 @@ import android.app.Activity;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.PointF;
-import android.os.Environment;
 import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
@@ -17,26 +16,24 @@ import net.osdn.gokigen.cameratest.R;
 import net.osdn.gokigen.cameratest.fuji.Connection;
 import net.osdn.gokigen.cameratest.fuji.ILiveViewImage;
 import net.osdn.gokigen.cameratest.fuji.ReceivedDataHolder;
+import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatus;
+import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusNotify;
 
 import androidx.annotation.NonNull;
 
-import java.io.File;
-import java.io.FileInputStream;
-
-
-public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiveViewImage
+public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiveViewImage, IFujiStatusNotify
 {
     private String TAG = toString();
     private final Activity activity;
     private TextView textview;
     private Connection connection;
     //private FileOutputStream outputStream = null;
-    private int offsetSize = 18;  // 4byte: データサイズ、14byte: (謎の)ヘッダ
+    private static final int offsetSize = 18;  // 4byte: データサイズ、14byte: (謎の)ヘッダ
 
     public CamTest(@NonNull Activity activity)
     {
         this.activity = activity;
-        this.connection = new Connection(this);
+        this.connection = new Connection(this, this);
     }
 
     public void connect()
@@ -284,130 +281,6 @@ public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiv
         }
     }
 
-    @Override
-    public void updateImage(final Bitmap bitmap)
-    {
-        try
-        {
-            Log.v(TAG, "bitmap : " + bitmap.getByteCount() + " bytes.");
-
-            //////  画像を更新する
-            activity.runOnUiThread(new Runnable() {
-                @Override
-                public void run() {
-                    try
-                    {
-                        // ビットマップイメージを表示する。
-                        ImageView view = activity.findViewById(R.id.imageView);
-                        view.setImageBitmap(bitmap);
-                        view.invalidate();
-                    }
-                    catch (Throwable e)
-                    {
-                        e.printStackTrace();
-                    }
-                }
-            });
-        }
-        catch (Throwable e)
-        {
-            e.printStackTrace();
-        }
-    }
-/*
-    private void outputFile(ReceivedDataHolder receivedData)
-    {
-        try
-        {
-            if (outputStream != null)
-            {
-                final byte[] byteData = receivedData.getData();
-                outputStream.write(byteData, 0, byteData.length);
-            }
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-    }
-
-    private void prepareFile()
-    {
-        try
-        {
-            final String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/AirA01a/";
-            final String outputFileName = "camtest.bin";
-            File filepath = new File(directoryPath.toLowerCase(), outputFileName.toLowerCase());
-            outputStream = new FileOutputStream(filepath);
-          }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-            outputStream = null;
-        }
-    }
-
-    private void readImageFile(final String readFileName)
-    {
-        Thread thread = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                    readImageFileImpl(readFileName);
-            }
-        });
-        try
-        {
-            thread.start();
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-    }
-
-    private void readImageFileImpl(final String readFileName)
-    {
-        try
-        {
-            Log.v(TAG, "readImageFileImpl() : " + readFileName);
-            final String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/AirA01a/";
-            File filepath = new File(directoryPath.toLowerCase(), readFileName.toLowerCase());
-            FileInputStream istr = new FileInputStream(filepath);
-            final Bitmap imageData = BitmapFactory.decodeStream(istr);
-            istr.close();
-            if (imageData == null)
-            {
-                Log.v(TAG, "readImageFileImpl() : bitmap is NULL.");
-            }
-            else
-            {
-                Log.v(TAG, "readImageFileImpl() : bitmap is " + imageData.getByteCount() + " bytes.");
-            }
-            //////  画像表示を更新する //////
-            activity.runOnUiThread(new Runnable() {
-                @Override
-                public void run() {
-                    try
-                    {
-                        // ビットマップイメージを表示する。
-                        ImageView view = activity.findViewById(R.id.information_view);
-                        view.setImageBitmap(imageData);
-                        view.invalidate();
-                    }
-                    catch (Throwable e)
-                    {
-                        e.printStackTrace();
-                    }
-                }
-            });
-        }
-        catch (Throwable e)
-        {
-            e.printStackTrace();
-        }
-    }
-*/
-
     private Bitmap getBitmap(ReceivedDataHolder receivedData)
     {
         try
@@ -419,12 +292,6 @@ public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiv
                 Log.v(TAG, "getBitmap() : NULL. (offset : " + offsetSize + ")");
                 return (null);
             }
-/*
-            else
-            {
-                Log.v(TAG, "getBitmap() : " + imageData.getByteCount() + "bytes. (offset : " + offsetSize + ")");
-            }
-*/
             return (imageData);
         }
         catch (Exception e)
@@ -471,4 +338,41 @@ public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiv
         }
         return (null);
     }
+
+    @Override
+    public void statusUpdated(final IFujiStatus cameraStatus)
+    {
+        try
+        {
+            Log.v(TAG, "statusUpdated()");
+
+            // 情報エリアの内容を更新する
+            final InformationView view = activity.findViewById(R.id.information_view);
+            if (view == null)
+            {
+                return;
+            }
+            view.drawInformation(cameraStatus);
+
+            //////  画像を更新する
+            activity.runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    try
+                    {
+                        view.invalidate();
+                    }
+                    catch (Throwable e)
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+        catch (Throwable e)
+        {
+            e.printStackTrace();
+        }
+
+    }
 }
diff --git a/app/src/main/java/net/osdn/gokigen/cameratest/camtest/InformationView.java b/app/src/main/java/net/osdn/gokigen/cameratest/camtest/InformationView.java
new file mode 100644 (file)
index 0000000..249aadc
--- /dev/null
@@ -0,0 +1,70 @@
+package net.osdn.gokigen.cameratest.camtest;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+
+import androidx.appcompat.widget.AppCompatImageView;
+
+import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatus;
+
+public class InformationView extends AppCompatImageView
+{
+    String message = "AAAAA";
+
+    public InformationView(Context context) {
+        super(context);
+        initComponent(context);
+    }
+
+    public InformationView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        initComponent(context);
+    }
+
+    public InformationView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        initComponent(context);
+    }
+
+    private void initComponent(Context context) {
+
+    }
+
+    @Override
+    protected void onDraw(Canvas canvas)
+    {
+        super.onDraw(canvas);
+        drawCanvas(canvas);
+    }
+
+    private void drawCanvas(Canvas canvas)
+    {
+        // Clears the canvas.
+        canvas.drawARGB(255, 0, 0, 0);
+
+        // Rotates the image.
+        int centerX = canvas.getWidth() / 2;
+        int centerY = canvas.getHeight() / 2;
+
+        Paint framePaint = new Paint();
+        framePaint.setStyle(Paint.Style.STROKE);
+        framePaint.setColor(Color.WHITE);
+
+        canvas.drawText(message, centerX, centerY, framePaint);
+    }
+
+    /**
+     *   表示エリアの情報を更新する
+     *
+     *
+     */
+    public void drawInformation(IFujiStatus cameraStatus)
+    {
+
+
+    }
+
+}
index f78cb8c..6a3df0c 100644 (file)
@@ -6,6 +6,7 @@ import android.util.Log;
 import androidx.annotation.NonNull;
 
 import net.osdn.gokigen.cameratest.fuji.statuses.FujiStatusChecker;
+import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusNotify;
 import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusRequest;
 
 public class Connection implements IFujiStatusRequest
@@ -15,11 +16,11 @@ public class Connection implements IFujiStatusRequest
     private final Communication comm;
     private final FujiStatusChecker statusChecker;
 
-    public Connection(@NonNull ILiveViewImage imageViewer)
+    public Connection(@NonNull ILiveViewImage imageViewer, @NonNull IFujiStatusNotify notify)
     {
         this.comm = new Communication(imageViewer);
         this.sequence = new MessageSequence();
-        this.statusChecker = new FujiStatusChecker(this);
+        this.statusChecker = new FujiStatusChecker(this, notify);
     }
 
     public boolean start_connect()
@@ -172,16 +173,13 @@ public class Connection implements IFujiStatusRequest
         try
         {
             comm.send_to_camera(sequence.status_request_message(), true);
-            //Thread.sleep(30);// ちょっと待つ
             ReceivedDataHolder rx_bytes = comm.receive_from_camera();
-            if (rx_bytes.getData().length > 0) {
+            if (rx_bytes.getData().length > 0)
+            {
+                // 受信したステータス情報を渡す
                 statusChecker.statusReceived(rx_bytes);
             }
-            dump_bytes(12, rx_bytes);
-
-            // なんで2回... でもやってみる
-            rx_bytes = comm.receive_from_camera();
-            dump_bytes(13, rx_bytes);
+            //dump_bytes(12, rx_bytes);
 
             return (true);
         }
@@ -259,10 +257,6 @@ public class Connection implements IFujiStatusRequest
 
             ReceivedDataHolder 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)
         {
index e3166b2..f21b3cc 100644 (file)
@@ -1,10 +1,6 @@
 package net.osdn.gokigen.cameratest.fuji;
 
-import android.graphics.Bitmap;
-
 public interface ILiveViewImage
 {
     void updateImage(ReceivedDataHolder receivedData);
-    void updateImage(Bitmap bitmap);
-
 }
index 912a1b0..4b7fba8 100644 (file)
@@ -2,18 +2,24 @@ package net.osdn.gokigen.cameratest.fuji.statuses;
 
 import android.util.Log;
 
+import androidx.annotation.NonNull;
+
 import net.osdn.gokigen.cameratest.fuji.ReceivedDataHolder;
 
 public class FujiStatusChecker implements IFujiStatusReceive
 {
     private final String TAG = toString();
     private final IFujiStatusRequest comm;
+    private final IFujiStatusNotify notify;
+    private final FujiStatusHolder statusHolder;
     private boolean threadIsRunning = false;
     private final int WAIT_MS = 400;
 
-    public FujiStatusChecker(IFujiStatusRequest comm)
+    public FujiStatusChecker(@NonNull IFujiStatusRequest comm, @NonNull IFujiStatusNotify notify)
     {
         this.comm = comm;
+        this.notify = notify;
+        this.statusHolder = new FujiStatusHolder();
     }
 
     @Override
@@ -23,12 +29,6 @@ public class FujiStatusChecker implements IFujiStatusReceive
     }
 
     @Override
-    public void statusReceived2nd(ReceivedDataHolder data)
-    {
-        statusReceivedImpl(data.getData());
-    }
-
-    @Override
     public void start()
     {
         Thread thread = new Thread(new Runnable() {
@@ -75,10 +75,35 @@ public class FujiStatusChecker implements IFujiStatusReceive
 
     private void statusReceivedImpl(byte[] data)
     {
+        boolean isStatusUpdated = false;
         try
         {
             Log.v(TAG, "status Received. " + data.length + " bytes.");
 
+/*
+RX [00] 7a 00 00 00 02 00 15 10
+RX [01] b1 00 00 00 12 00 1b d2
+RX [02] 00 00 00 00 0c 50 02 00
+RX [03] 00 00 12 50 00 00 00 00
+RX [04] 29 d2 67 04 00 00 2a d2
+RX [05] a1 06 00 00 0e 50 03 00
+RX [06] 00 00 01 50 03 00 00 00
+RX [07] 7c d1 04 04 02 03 09 d2
+RX [08] 01 00 00 00 10 50 b3 fe
+RX [09] ff ff 05 50 02 00 00 00
+RX [10] 28 d0 00 00 00 00 0a 50
+RX [11] 01 80 00 00 41 d2 0a 00
+RX [12] 00 00 18 d0 04 00 00 00
+RX [13] 07 50 90 01 00 00 01 d0
+RX [14] 03 00 00 00 2a d0 40 06
+RX [15] 00 80 0c 00 00 00 03 00
+RX [16] 01 20 b1 00 00 00
+*/
+
+            if (isStatusUpdated)
+            {
+                notify.statusUpdated(statusHolder);
+            }
         }
         catch (Exception e)
         {
diff --git a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/FujiStatusHolder.java b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/FujiStatusHolder.java
new file mode 100644 (file)
index 0000000..6293c4a
--- /dev/null
@@ -0,0 +1,14 @@
+package net.osdn.gokigen.cameratest.fuji.statuses;
+
+class FujiStatusHolder implements IFujiStatus
+{
+    /**
+     *   コンストラクタ
+     */
+    FujiStatusHolder()
+    {
+
+    }
+
+
+}
diff --git a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/IFujiStatus.java b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/IFujiStatus.java
new file mode 100644 (file)
index 0000000..772c199
--- /dev/null
@@ -0,0 +1,7 @@
+package net.osdn.gokigen.cameratest.fuji.statuses;
+
+public interface IFujiStatus
+{
+
+
+}
diff --git a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/IFujiStatusNotify.java b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/IFujiStatusNotify.java
new file mode 100644 (file)
index 0000000..575a51a
--- /dev/null
@@ -0,0 +1,7 @@
+package net.osdn.gokigen.cameratest.fuji.statuses;
+
+public interface IFujiStatusNotify
+{
+    void statusUpdated(final IFujiStatus cameraStatus);
+
+}
index b3ded14..d73393c 100644 (file)
@@ -7,5 +7,4 @@ public interface IFujiStatusReceive
     void start();
     void stop();
     void statusReceived(ReceivedDataHolder data);
-    void statusReceived2nd(ReceivedDataHolder data);
 }
index 089483b..7e233de 100644 (file)
@@ -92,7 +92,7 @@
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toBottomOf="@id/show_information" />
 
-    <ImageView
+    <net.osdn.gokigen.cameratest.camtest.InformationView
         android:id="@+id/information_view"
         android:layout_width="300dp"
         android:layout_height="150dp"