initializeClass();
prepareClass();
onReadyClass();
-
}
/**
exitApplication();
return (true);
}
+ if (id == R.id.action_reset)
+ {
+ testTarget.resetConnection();
+ return (true);
+ }
if (id == R.id.action_up_value)
{
testTarget.valueUp();
{
try
{
+ testTarget.disconnect();
finish();
}
catch (Exception e)
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
public class CamTest implements View.OnClickListener, ILiveViewImage
private final Activity activity;
private TextView textview;
private Connection connection;
- private FileOutputStream outputStream = null;
+ //private FileOutputStream outputStream = null;
private int offsetSize = 18; // 4byte: データサイズ、14byte: (謎の)ヘッダ
public CamTest(@NonNull Activity activity)
Log.v(TAG, "connect request");
try
{
- prepareFile();
-
+ //prepareFile();
Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.connect, Snackbar.LENGTH_SHORT).show();
showMessageText("START CONNECT");
}
}
+ public void disconnect()
+ {
+ try
+ {
+ connection.disconnect();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void resetConnection()
+ {
+ Log.v(TAG, "Reset Connection");
+
+ showMessageText("RESET CONNECTION");
+ try
+ {
+ Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.action_reset, Snackbar.LENGTH_SHORT).show();
+ Thread thread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ connection.reset_to_camera();
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+
public void settings()
{
Log.v(TAG, "settings menu");
Log.v(TAG, "Image : "+ dataValue.length + " bytes.");
// ダミーの記録ファイルが開いていたらファイルに書いておく。
- outputFile(receivedData);
+ //outputFile(receivedData);
/////// Bitmap画像を作る... //////
final Bitmap imageData = getBitmap(receivedData);
e.printStackTrace();
}
}
-
+/*
private void outputFile(ReceivedDataHolder receivedData)
{
try
outputStream = null;
}
}
-
+*/
private void readImageFile(final String readFileName)
{
Thread thread = new Thread(new Runnable() {
{
Log.v(TAG, "readImageFileImpl() : bitmap is NULL.");
}
+/*
else
{
Log.v(TAG, "readImageFileImpl() : bitmap is " + imageData.getByteCount() + " bytes.");
}
-
+*/
////// 画像表示を更新する //////
activity.runOnUiThread(new Runnable() {
@Override
final Bitmap imageData = BitmapFactory.decodeByteArray(data, offsetSize, (data.length - offsetSize));
if (imageData == null)
{
- Log.v(TAG, "readImageFileImpl() : bitmap is NULL. (offset : " + offsetSize + ")");
+ Log.v(TAG, "getBitmap() : NULL. (offset : " + offsetSize + ")");
+ return (null);
}
+/*
else
{
- Log.v(TAG, "readImageFileImpl() : bitmap is " + imageData.getByteCount() + " bytes.");
+ Log.v(TAG, "getBitmap() : " + imageData.getByteCount() + "bytes. (offset : " + offsetSize + ")");
}
+*/
return (imageData);
}
catch (Exception e)
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.Socket;
class Communication
ReceivedDataHolder receive_from_camera()
{
-/*
- InputStreamReader isr;
- char[] char_array = new char[BUFFER_SIZE];
- try
- {
- //Log.v(TAG, "receive_from_camera() : start.");
- 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 ReceivedDataHolder(char_array, read_bytes));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return (new ReceivedDataHolder(char_array, 0));
-*/
try
{
byte[] byte_array = new byte[BUFFER_SIZE];
{
stream.start();
}
+
void stop_stream()
{
stream.stop();
{
response.start();
}
+
void stop_response()
{
response.stop();
// 応答OKの場合は、8バイト ({0x03, 0x00, 0x01, 0x20} + {0x10, 0x02, 0x00, 0x00} )が応答されるはず
rx_bytes = comm.receive_from_camera();
dump_bytes(11, rx_bytes);
- Thread.sleep(50);
+ Thread.sleep(150);
// 別のポートもオープンして動作を行う。 (1500ms程度待つといけるみたいだ...)
- Thread.sleep(1500);
+ Thread.sleep(2000);
comm.start_stream();
comm.start_response();
return (false);
}
+ public void reset_to_camera()
+ {
+ try
+ {
+ comm.send_to_camera(sequence.reset_message());
+ ReceivedDataHolder rx_bytes = comm.receive_from_camera();
+ dump_bytes(0, rx_bytes);
+ Thread.sleep(150);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void disconnect()
+ {
+ try
+ {
+ comm.stop_stream();
+ comm.stop_response();
+ comm.disconnect_socket();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
private boolean get_current_settings()
{
try
// なんで2回受信... でもやってみる
rx_bytes = comm.receive_from_camera();
dump_bytes(15, rx_bytes);
-
}
catch (Exception e)
{
private final String ipAddress;
private final int portNumber;
private final ILiveViewImage imageViewer;
+ private static final int WAIT_MS = 75;
private static final int BUFFER_SIZE = 1280 * 1024 + 8;
- private static final int WAIT_MS = 50;
private boolean isStart = false;
FujiStreamReceiver(String ip, int portNumber, @NonNull ILiveViewImage imageViewer)
private void startReceive(Socket socket)
{
-/**/
InputStream isr;
byte[] byteArray;
try
Log.v(TAG, "===== startReceive() aborted.");
return;
}
-/**/
- Log.v(TAG, "startReceive() start.");
while (isStart)
{
try
{
-/*
- Bitmap imageData = BitmapFactory.decodeStream(socket.getInputStream());
- if (imageData != null)
- {
- // received image
- Log.v(TAG, "RECEIVED IMAGE.");
- }
- else
- {
- Log.v(TAG, "IMAGE IS NULL...");
- }
-*/
-/**/
int read_bytes = isr.read(byteArray, 0, BUFFER_SIZE);
imageViewer.updateImage(new ReceivedDataHolder(byteArray, read_bytes));
-/**/
Thread.sleep(WAIT_MS);
}
catch (Exception e)
e.printStackTrace();
}
}
-/**/
try
{
isr.close();
{
e.printStackTrace();
}
-/**/
- Log.v(TAG, "startReceive() end.");
}
}
(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)0x34, (byte)0x00,
- (byte)0x35, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x35, (byte)0x00, (byte)0x36, (byte)0x00, (byte)0x37, (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[] reset_message()
+ {
+ return (new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, });
+ }
+
+
byte[] hello_message()
{
return (new byte[] {
android:title="@string/action_wifi_settings"
app:showAsAction="never" />
<item
+ android:id="@+id/action_reset"
+ android:orderInCategory="100"
+ android:title="@string/action_reset"
+ app:showAsAction="never" />
+ <item
android:id="@+id/action_up_value"
android:orderInCategory="100"
android:title="@string/action_up"
<string name="label_button5">5</string>
<string name="action_up">Up</string>
<string name="action_down">Down</string>
+ <string name="action_reset">Reset Connection</string>
</resources>