Commit 28a942e4 authored by Martin Cífka's avatar Martin Cífka
Browse files

Updated Commander::getJSON, added timeout for recv

parent 7411783c
Loading
Loading
Loading
Loading
Loading
+257 −0
Original line number Diff line number Diff line
/***************************** INFO *****************************/
int AMBA_CAMERA_COMMAND_PORT = 7878;
int AMBA_CAMERA_DATA_PORT = 8787;
String AMBA_CAMERA_HTTPS_URL_ROOT = "https://192.168.42.1:443/";
String AMBA_CAMERA_HTTP_URL_ROOT = "http://192.168.42.1:50422/";
String AMBA_CAMERA_IP = "192.168.42.1";
String AMBA_CAMERA_RTSP_LIVE_URL = "rtsp://192.168.42.1/live";
String AMBA_CAMERA_RTSP_URL_ROOT = "rtsp://192.168.42.1";
String AMBA_SESSION_TYPE = "TCP";
String BACKSLASH_PATH_HEAD_TAG = "C:";
String SLASH_PATH_HEAD_TAG = "/tmp/SD0";

int AMBA_SESSION_TOKEN_INIT = 0;
int AMBA_CAMERA_TIMEOUT = 8000;
/****************************************************************/

int AMBA_MSGID_RESET_VF = 259;
int AMBA_MSGID_STOP_VF = 260;

int AMBA_MSGID_UPDATE_HARDWARE = 8;
int AMBA_MSGID_SET_CLNT_INFO = 261;
int AMBA_MSGID_GET_MEDIA_INFO = 1026;
int AMBA_MSGID_QUERY_SESSION_HOLDER = 1793;
int AMBA_MSGID_START_LOOP_FAIL = 4626;
int AMBA_MSGID_SET_GPS_INFO = 4917;
int AMBA_MSGID_RTC_SYNC = 6147;
int AMBA_MSGID_CAMERA_OVERHEATED = 6158;
int AMBA_MSGID_RECOVERY_MEDIA_FILE = 6161;
int AMBA_MSGID_ADJUST_CAMERA_GYRO = 6165;
int AMBA_MSGID_MP4_FILE_SPLIT_DONE = 8195;
int AMBA_MSGID_RESET_DEFAULT_PARAMS = 6153;
int AMBA_MSGID_RESET_DEFAULT_SETTINGS = 6152;

/* GET_CAMERA_ALL */
int AMBA_MSGID_GET_CAMERA_ALL_MODE_PARAM = 4365;
int AMBA_MSGID_GET_CAMERA_ALL_PARAM = 4363;
int AMBA_MSGID_GET_CAMERA_ALL_SETTING_PARAM = 4364;

s

/* RVAL */
int AMBA_COMMAND_OK = 0;
int AMBA_NOTIFICATION_OK = 128;
int AMBA_RVAL_ERROR_BUSY = -21;
int AMBA_RVAL_ERROR_INVALID_FILE_PATH = -26;
int AMBA_RVAL_ERROR_INVALID_OPERATION = -14;
int AMBA_RVAL_ERROR_INVALID_TOKEN = -4;
int AMBA_RVAL_ERROR_LOW_BATTERY = -58;
int AMBA_RVAL_ERROR_NO_FIRMWARE = -57;
int AMBA_RVAL_ERROR_NO_SDCARD = -50;
int AMBA_RVAL_ERROR_SDCARD = -59;
int AMBA_RVAL_ERROR_SDCARD_FULL = -17;
int AMBA_RVAL_ERROR_SDCARD_SLOWLY = -61;
int AMBA_RVAL_ERROR_WRONG_MODE = -56;
int AMBA_RVAL_START_SESSION_DENIED = -3;
 


/* POWER */
int AMBA_MSGID_SET_AUTO_SHUTDOWN_TIME = 6151;
int AMBA_MSGID_WAKEUP_CAMERA = 6154;
int AMBA_MSGID_CLOSE_CAMERA = 6155;



/* SHELL */
int AMBA_MSGID_LS = 1282;
int AMBA_MSGID_CD = 1283;



/* SESSION */
int AMBA_MSGID_START_SESSION = 257;
int AMBA_MSGID_STOP_SESSION = 258;



/* WHITEBALANCE */
int AMBA_MSGID_SET_WHITEBALANCE = 5121;
int AMBA_PARAM_WHITEBALANCE_AUTO = 0;
int AMBA_PARAM_WHITEBALANCE_OUTDOOR = 1;
int AMBA_PARAM_WHITEBALANCE_SHADOW = 2;
int AMBA_PARAM_WHITEBALANCE_CLOUDY = 3;
int AMBA_PARAM_WHITEBALANCE_NIGHT = 4;



/* PHOTO */
int AMBA_MSGID_SAVE_PHOTO_DONE = 8193;
int AMBA_MSGID_TAKE_PHOTO = 769;

int AMBA_MSGID_GET_PHOTO_CAPACITY = 4357;

int AMBA_MSGID_SHOOT_PHOTO_NORMAL = 4864;
int AMBA_MSGID_SHOOT_PHOTO_TIMING = 4868;
int AMBA_MSGID_SHOOT_PHOTO_INTERVAL = 5025;
int AMBA_MSGID_SHOOT_PHOTO_CONTINUOUS = 5027;

int AMBA_MSGID_SET_SHUTTER = 5127;
int AMBA_MSGID_SET_ISO = 5126;

int AMBA_MSGID_SET_PHOTO_CONTINUOUS_PARAM = 4915;
int AMBA_MSGID_SET_PHOTO_INTERVAL_PARAM = 4929;
int AMBA_MSGID_SET_PHOTO_SURROUNDEXP_PARAM = 4918;
int AMBA_MSGID_SET_PHOTO_TIMING_PARAM = 4866;

int AMBA_MSGID_START_PHOTO_SURROUNDEXP = 5029;



/* VIDEO */
int AMBA_MSGID_SAVE_VIDEO_DONE = 8192;

int AMBA_MSGID_START_VIDEO_MICRO = 4620;
int AMBA_MSGID_START_VIDEO_DELAY = 4623;
int AMBA_MSGID_START_VIDEO_SLOW = 5028;
int AMBA_MSGID_START_VIDEO_NORMAL = 513;

int AMBA_MSGID_STOP_VIDEO = 514;

int AMBA_MSGID_SET_VIDEO_FILTER = 4609;
int AMBA_MSGID_SET_VIDEO_MICRO_PARAM = 4618;
int AMBA_MSGID_SET_VIDEO_DELAY_PARAM = 4621;
int AMBA_MSGID_SET_VIDEO_SLOW_PARAM = 4916;

int AMBA_MSGID_GET_RECORD_TIME = 515;
int AMBA_MSGID_GET_VIDEO_CAPACITY = 4356;



/* WIFI */
int AMBA_MSGID_GET_WIFI_SETTING = 1539;
int AMBA_MSGID_GET_WIFI_STATUS = 1542;
int AMBA_MSGID_SET_WIFI_NEW = 5634;
int AMBA_MSGID_SET_WIFI_SETTING = 1538;
int AMBA_MSGID_WIFI_RESTART = 1537;
int AMBA_MSGID_WIFI_STOP = 1540;
int AMBA_MSGID_WIFI_START = 1541;


    
/* BATTERY */
int AMBA_MSGID_GET_BATTERY_VOLUME = 4361;
int AMBA_PARAM_BATTERY_PERCENT5 = 0;
int AMBA_PARAM_BATTERY_PERCENT25 = 1;
int AMBA_PARAM_BATTERY_PERCENT50 = 2;
int AMBA_PARAM_BATTERY_PERCENT75 = 3;
int AMBA_PARAM_BATTERY_PERCENT100 = 4;    
int AMBA_PARAM_BATTERY_CHARGE_FULL = 68;
    

 
/* MODE */
int AMBA_MSGID_SET_PHOTO_MODE = 2307;
int AMBA_MSGID_SET_VIDEO_MODE = 2308;

int AMBA_MSGID_SET_CAMERA_MODE = 4611;
int AMBA_PARAM_CAMERA_MODE_VIDEO = 0;
int AMBA_PARAM_CAMERA_MODE_PHOTO = 1;



/* CAMERA STATE */
int AMBA_MSGID_GET_CAMERA_STATE = 4362;
int AMBA_PARAM_CAMERA_STATE_IDLE = 0;
int AMBA_PARAM_CAMERA_STATE_STANDBY = 1;
int AMBA_PARAM_CAMERA_STATE_STORAGE = 2;
int AMBA_PARAM_CAMERA_STATE_CAPTURING = 3;
int AMBA_PARAM_CAMERA_STATE_CAPTURING_MICRO = 4;
int AMBA_PARAM_CAMERA_STATE_CAPTURING_DELAYED = 5;
int AMBA_PARAM_CAMERA_STATE_PHOTOING = 6;
int AMBA_PARAM_CAMERA_STATE_PHOTOING_DELAYED = 7;
int AMBA_PARAM_CAMERA_STATE_PHOTOING_INTERVAL = 12;
int AMBA_PARAM_CAMERA_STATE_CAPTURING_SLOW = 13;
int AMBA_PARAM_CAMERA_STATE_CAPTURING_CONTINUOUS = 14;
int AMBA_PARAM_CAMERA_STATE_CAPTURING_SURROUNDEXP = 15;

    
    
/* SDCARD */
int AMBA_MSGID_SDCARD_SLOWLY_WRITE = 4359;
int AMBA_MSGID_FORMAT_SD = 4;

int AMBA_MSGID_IS_SDCARD_FULL = 4354;
int AMBA_PARAM_SDCARD_FULL_NO = 0;
int AMBA_PARAM_SDCARD_FULL_ALMOST = 1;
int AMBA_PARAM_SDCARD_FULL_YES = 2;
int AMBA_PARAM_SDCARD_FULL_UNKNOWN = 3;

int AMBA_MSGID_IS_SDCARD_MOUNTED = 4353;
int AMBA_PARAM_SDCARD_MOUNTED_NO = 0;
int AMBA_PARAM_SDCARD_MOUNTED_YES = 1;

int AMBA_MSGID_IS_SDCARD_NEED_FORMAT = 4360;
int AMBA_PARAM_SDCARD_NEED_FORMAT_NO = 0;
int AMBA_PARAM_SDCARD_NEED_FORMAT_YES = 1;

    
    
/* BEEPER */
int AMBA_MSGID_BEEPER_VOLUME = 6145;
int AMBA_PARAM_BEEPER_OFF = 0;
int AMBA_PARAM_BEEPER_VOLUME_25P = 1;
int AMBA_PARAM_BEEPER_VOLUME_50P = 2;
int AMBA_PARAM_BEEPER_VOLUME_75P = 3;
int AMBA_PARAM_BEEPER_VOLUME_100P = 4;


 
/* DEVICE */
int AMBA_MSGID_GET_DEVICE_NAME = 4099;
int AMBA_MSGID_GET_DEVICE_VERSION = 4100;
int AMBA_MSGID_GET_SN = 4097;
int AMBA_MSGID_GET_VENDOR = 4098;



/* FILE */
int AMBA_MSGID_CANCEL_FILE_TRANSFER = 1287;
int AMBA_MSGID_DELETE_FILE = 1281;
int AMBA_MSGID_DELETE_FILES_DONE = 6162;
int AMBA_MSGID_FILE_TRANSFER_RESULT = 7;
int AMBA_MSGID_GET_FILE = 1285;
int AMBA_MSGID_PUT_FILE = 1286;
String GET_FILE_COMPLETE_TYPE = "get_file_complete";
String GET_FILE_FAILED_TYPE = "get_file_fail";
String PUT_FILE_COMPLETE_TYPE = "put_file_complete";
String PUT_FILE_FAIL_TYPE = "put_file_fail";



/* THUMB */
int AMBA_MSGID_GET_THUMB = 1025;
String GET_THUMB_TYPE_FULLVIEW = "fullview";
String GET_THUMB_TYPE_IDR = "idr";
String GET_THUMB_TYPE_THUMB = "thumb";



/* STORAGE */
int AMBA_MSGID_GET_STORAGE_ALL_STATE = 4358;
int AMBA_MSGID_GET_STORAGE_TOTAL_FREE = 5;
String GET_STORAGE_TYPE_FREE = "free";
String GET_STORAGE_TYPE_TOTAL = "total";



    
    
/*******************************************************/
/*******************************************************/
int AMBA_UPLOAD_FILE_TYPE_FW = 1;
int AMBA_UPLOAD_FILE_TYPE_RW = 2;
    
String APPUBLIC_TAG = "AP_PUBLIC=";
String PASSWORD_TAG = "AP_PASSWD=";
String SSID_TAG = "AP_SSID=";

apk_decompiled/AMBACommands.java

deleted100644 → 0
+0 −166
Original line number Diff line number Diff line
package com.madv360.madv.connection;

public class AMBACommands {
    public static final int AMBA_CAMERA_COMMAND_PORT = 7878;
    public static final int AMBA_CAMERA_DATA_PORT = 8787;
    public static final String AMBA_CAMERA_HTTPS_URL_ROOT = "https://192.168.42.1:443/";
    public static final String AMBA_CAMERA_HTTP_URL_ROOT = "http://192.168.42.1:50422/";
    public static final String AMBA_CAMERA_IP = "192.168.42.1";
    public static final String AMBA_CAMERA_RTSP_LIVE_URL = "rtsp://192.168.42.1/live";
    public static final String AMBA_CAMERA_RTSP_URL_ROOT = "rtsp://192.168.42.1";
    public static final int AMBA_CAMERA_TIMEOUT = 8000;
    public static final int AMBA_COMMAND_OK = 0;
    public static final int AMBA_MSGID_ADJUST_CAMERA_GYRO = 6165;
    public static final int AMBA_MSGID_BEEPER_VOLUME = 6145;
    public static final int AMBA_MSGID_CAMERA_OVERHEATED = 6158;
    public static final int AMBA_MSGID_CANCEL_FILE_TRANSFER = 1287;
    public static final int AMBA_MSGID_CD = 1283;
    public static final int AMBA_MSGID_CLOSE_CAMERA = 6155;
    public static final int AMBA_MSGID_DELETE_FILE = 1281;
    public static final int AMBA_MSGID_DELETE_FILES_DONE = 6162;
    public static final int AMBA_MSGID_FILE_TRANSFER_RESULT = 7;
    public static final int AMBA_MSGID_FORMAT_SD = 4;
    public static final int AMBA_MSGID_GET_BATTERY_VOLUME = 4361;
    public static final int AMBA_MSGID_GET_CAMERA_ALL_MODE_PARAM = 4365;
    public static final int AMBA_MSGID_GET_CAMERA_ALL_PARAM = 4363;
    public static final int AMBA_MSGID_GET_CAMERA_ALL_SETTING_PARAM = 4364;
    public static final int AMBA_MSGID_GET_CAMERA_STATE = 4362;
    public static final int AMBA_MSGID_GET_DEVICE_NAME = 4099;
    public static final int AMBA_MSGID_GET_DEVICE_VERSION = 4100;
    public static final int AMBA_MSGID_GET_FILE = 1285;
    public static final int AMBA_MSGID_GET_MEDIA_INFO = 1026;
    public static final int AMBA_MSGID_GET_PHOTO_CAPACITY = 4357;
    public static final int AMBA_MSGID_GET_RECORD_TIME = 515;
    public static final int AMBA_MSGID_GET_SN = 4097;
    public static final int AMBA_MSGID_GET_STORAGE_ALL_STATE = 4358;
    public static final int AMBA_MSGID_GET_STORAGE_TOTAL_FREE = 5;
    public static final int AMBA_MSGID_GET_THUMB = 1025;
    public static final int AMBA_MSGID_GET_VENDOR = 4098;
    public static final int AMBA_MSGID_GET_VIDEO_CAPACITY = 4356;
    public static final int AMBA_MSGID_GET_WIFI_SETTING = 1539;
    public static final int AMBA_MSGID_GET_WIFI_STATUS = 1542;
    public static final int AMBA_MSGID_IS_SDCARD_FULL = 4354;
    public static final int AMBA_MSGID_IS_SDCARD_MOUNTED = 4353;
    public static final int AMBA_MSGID_IS_SDCARD_NEED_FORMAT = 4360;
    public static final int AMBA_MSGID_LS = 1282;
    public static final int AMBA_MSGID_MP4_FILE_SPLIT_DONE = 8195;
    public static final int AMBA_MSGID_PUT_FILE = 1286;
    public static final int AMBA_MSGID_QUERY_SESSION_HOLDER = 1793;
    public static final int AMBA_MSGID_RECOVERY_MEDIA_FILE = 6161;
    public static final int AMBA_MSGID_RESET_DEFAULT_PARAMS = 6153;
    public static final int AMBA_MSGID_RESET_DEFAULT_SETTINGS = 6152;
    public static final int AMBA_MSGID_RESET_VF = 259;
    public static final int AMBA_MSGID_RTC_SYNC = 6147;
    public static final int AMBA_MSGID_SAVE_PHOTO_DONE = 8193;
    public static final int AMBA_MSGID_SAVE_VIDEO_DONE = 8192;
    public static final int AMBA_MSGID_SDCARD_SLOWLY_WRITE = 4359;
    public static final int AMBA_MSGID_SET_AUTO_SHUTDOWN_TIME = 6151;
    public static final int AMBA_MSGID_SET_CAMERA_MODE = 4611;
    public static final int AMBA_MSGID_SET_CLNT_INFO = 261;
    public static final int AMBA_MSGID_SET_GPS_INFO = 4917;
    public static final int AMBA_MSGID_SET_ISO = 5126;
    public static final int AMBA_MSGID_SET_PHOTO_CONTINUOUS_PARAM = 4915;
    public static final int AMBA_MSGID_SET_PHOTO_INTERVAL_PARAM = 4929;
    public static final int AMBA_MSGID_SET_PHOTO_MODE = 2307;
    public static final int AMBA_MSGID_SET_PHOTO_SURROUNDEXP_PARAM = 4918;
    public static final int AMBA_MSGID_SET_PHOTO_TIMING_PARAM = 4866;
    public static final int AMBA_MSGID_SET_SHUTTER = 5127;
    public static final int AMBA_MSGID_SET_VIDEO_DELAY_PARAM = 4621;
    public static final int AMBA_MSGID_SET_VIDEO_FILTER = 4609;
    public static final int AMBA_MSGID_SET_VIDEO_MICRO_PARAM = 4618;
    public static final int AMBA_MSGID_SET_VIDEO_MODE = 2308;
    public static final int AMBA_MSGID_SET_VIDEO_SLOW_PARAM = 4916;
    public static final int AMBA_MSGID_SET_WHITEBALANCE = 5121;
    public static final int AMBA_MSGID_SET_WIFI_NEW = 5634;
    public static final int AMBA_MSGID_SET_WIFI_SETTING = 1538;
    public static final int AMBA_MSGID_SHOOT_PHOTO_CONTINUOUS = 5027;
    public static final int AMBA_MSGID_SHOOT_PHOTO_INTERVAL = 5025;
    public static final int AMBA_MSGID_SHOOT_PHOTO_NORMAL = 4864;
    public static final int AMBA_MSGID_SHOOT_PHOTO_TIMING = 4868;
    public static final int AMBA_MSGID_START_LOOP_FAIL = 4626;
    public static final int AMBA_MSGID_START_PHOTO_SURROUNDEXP = 5029;
    public static final int AMBA_MSGID_START_SESSION = 257;
    public static final int AMBA_MSGID_START_VIDEO_DELAY = 4623;
    public static final int AMBA_MSGID_START_VIDEO_MICRO = 4620;
    public static final int AMBA_MSGID_START_VIDEO_NORMAL = 513;
    public static final int AMBA_MSGID_START_VIDEO_SLOW = 5028;
    public static final int AMBA_MSGID_STOP_SESSION = 258;
    public static final int AMBA_MSGID_STOP_VF = 260;
    public static final int AMBA_MSGID_STOP_VIDEO = 514;
    public static final int AMBA_MSGID_TAKE_PHOTO = 769;
    public static final int AMBA_MSGID_UPDATE_HARDWARE = 8;
    public static final int AMBA_MSGID_WAKEUP_CAMERA = 6154;
    public static final int AMBA_MSGID_WIFI_RESTART = 1537;
    public static final int AMBA_MSGID_WIFI_START = 1541;
    public static final int AMBA_MSGID_WIFI_STOP = 1540;
    public static final int AMBA_NOTIFICATION_OK = 128;
    public static final int AMBA_PARAM_BATTERY_CHARGE_FULL = 68;
    public static final int AMBA_PARAM_BATTERY_PERCENT100 = 4;
    public static final int AMBA_PARAM_BATTERY_PERCENT25 = 1;
    public static final int AMBA_PARAM_BATTERY_PERCENT5 = 0;
    public static final int AMBA_PARAM_BATTERY_PERCENT50 = 2;
    public static final int AMBA_PARAM_BATTERY_PERCENT75 = 3;
    public static final int AMBA_PARAM_BEEPER_OFF = 0;
    public static final int AMBA_PARAM_BEEPER_VOLUME_100P = 4;
    public static final int AMBA_PARAM_BEEPER_VOLUME_25P = 1;
    public static final int AMBA_PARAM_BEEPER_VOLUME_50P = 2;
    public static final int AMBA_PARAM_BEEPER_VOLUME_75P = 3;
    public static final int AMBA_PARAM_CAMERA_MODE_PHOTO = 1;
    public static final int AMBA_PARAM_CAMERA_MODE_VIDEO = 0;
    public static final int AMBA_PARAM_CAMERA_STATE_CAPTURING = 3;
    public static final int AMBA_PARAM_CAMERA_STATE_CAPTURING_CONTINUOUS = 14;
    public static final int AMBA_PARAM_CAMERA_STATE_CAPTURING_DELAYED = 5;
    public static final int AMBA_PARAM_CAMERA_STATE_CAPTURING_MICRO = 4;
    public static final int AMBA_PARAM_CAMERA_STATE_CAPTURING_SLOW = 13;
    public static final int AMBA_PARAM_CAMERA_STATE_CAPTURING_SURROUNDEXP = 15;
    public static final int AMBA_PARAM_CAMERA_STATE_IDLE = 0;
    public static final int AMBA_PARAM_CAMERA_STATE_PHOTOING = 6;
    public static final int AMBA_PARAM_CAMERA_STATE_PHOTOING_DELAYED = 7;
    public static final int AMBA_PARAM_CAMERA_STATE_PHOTOING_INTERVAL = 12;
    public static final int AMBA_PARAM_CAMERA_STATE_STANDBY = 1;
    public static final int AMBA_PARAM_CAMERA_STATE_STORAGE = 2;
    public static final int AMBA_PARAM_SDCARD_FULL_ALMOST = 1;
    public static final int AMBA_PARAM_SDCARD_FULL_NO = 0;
    public static final int AMBA_PARAM_SDCARD_FULL_UNKNOWN = 3;
    public static final int AMBA_PARAM_SDCARD_FULL_YES = 2;
    public static final int AMBA_PARAM_SDCARD_MOUNTED_NO = 0;
    public static final int AMBA_PARAM_SDCARD_MOUNTED_YES = 1;
    public static final int AMBA_PARAM_SDCARD_NEED_FORMAT_NO = 0;
    public static final int AMBA_PARAM_SDCARD_NEED_FORMAT_YES = 1;
    public static final int AMBA_PARAM_WHITEBALANCE_AUTO = 0;
    public static final int AMBA_PARAM_WHITEBALANCE_CLOUDY = 3;
    public static final int AMBA_PARAM_WHITEBALANCE_NIGHT = 4;
    public static final int AMBA_PARAM_WHITEBALANCE_OUTDOOR = 1;
    public static final int AMBA_PARAM_WHITEBALANCE_SHADOW = 2;
    public static final int AMBA_RVAL_ERROR_BUSY = -21;
    public static final int AMBA_RVAL_ERROR_INVALID_FILE_PATH = -26;
    public static final int AMBA_RVAL_ERROR_INVALID_OPERATION = -14;
    public static final int AMBA_RVAL_ERROR_INVALID_TOKEN = -4;
    public static final int AMBA_RVAL_ERROR_LOW_BATTERY = -58;
    public static final int AMBA_RVAL_ERROR_NO_FIRMWARE = -57;
    public static final int AMBA_RVAL_ERROR_NO_SDCARD = -50;
    public static final int AMBA_RVAL_ERROR_SDCARD = -59;
    public static final int AMBA_RVAL_ERROR_SDCARD_FULL = -17;
    public static final int AMBA_RVAL_ERROR_SDCARD_SLOWLY = -61;
    public static final int AMBA_RVAL_ERROR_WRONG_MODE = -56;
    public static final int AMBA_RVAL_START_SESSION_DENIED = -3;
    public static int AMBA_SESSION_TOKEN = 0;
    public static final int AMBA_SESSION_TOKEN_INIT = 0;
    public static final String AMBA_SESSION_TYPE = "TCP";
    public static final int AMBA_UPLOAD_FILE_TYPE_FW = 1;
    public static final int AMBA_UPLOAD_FILE_TYPE_RW = 2;
    public static final String APPUBLIC_TAG = "AP_PUBLIC=";
    public static final String BACKSLASH_PATH_HEAD_TAG = "C:";
    public static final String GET_FILE_COMPLETE_TYPE = "get_file_complete";
    public static final String GET_FILE_FAILED_TYPE = "get_file_fail";
    public static final String GET_STORAGE_TYPE_FREE = "free";
    public static final String GET_STORAGE_TYPE_TOTAL = "total";
    public static final String GET_THUMB_TYPE_FULLVIEW = "fullview";
    public static final String GET_THUMB_TYPE_IDR = "idr";
    public static final String GET_THUMB_TYPE_THUMB = "thumb";
    public static final String PASSWORD_TAG = "AP_PASSWD=";
    public static final String PUT_FILE_COMPLETE_TYPE = "put_file_complete";
    public static final String PUT_FILE_FAIL_TYPE = "put_file_fail";
    public static final String SLASH_PATH_HEAD_TAG = "/tmp/SD0";
    public static final String SSID_TAG = "AP_SSID=";
}
+3 −1
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@
set -euo pipefail

outfile="miphoto-exec"
buildopts="-std=c++17 -static-libstdc++ -pthread -I src/ArduinoJson"

usage=$(echo -e "Usage: run.sh [OPTIONS] \n\t-b\tbuild \n\t-r\tcopy to camera and run")

build=false
@@ -32,7 +34,7 @@ if [ "$build" = true ] ; then
	sources=$(ls src/*.cpp 2>/dev/null | tr '\r\n' ' ') || (echo "No .cpp files found" && exit 1)

    sudo docker build -t mi_camera_sdk .
    sudo docker run -it --rm -v "$PWD":/workdir mi_camera_sdk bash -c "arm-linux-gnueabihf-c++ -std=c++17 -static-libstdc++ -I src/ArduinoJson -o /workdir/$outfile $sources"
    sudo docker run -it --rm -v "$PWD":/workdir mi_camera_sdk bash -c "arm-linux-gnueabihf-c++ $buildopts -o /workdir/$outfile $sources"
    echo -e "\n"
fi

+65 −26
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
using namespace std;

Commander::Commander() :
    _token(0), _sock(TcpSocket()), _cr(CustomReader(&_sock)) {};
    _token(0), _sock(TcpSocket()), _reader(CustomReader(&_sock)) {};
    
string Commander::generateJSON(MSG msg)
{
@@ -35,28 +35,66 @@ string Commander::generateJSON(MSG msg, int param)
    return str;
}

bool Commander::getJSON(DynamicJsonDocument& json, int expected_rval)
bool Commander::getJSON(DynamicJsonDocument& json, MSG expected_msg_id, int expected_rval)
{
    // Get response
    string response;
    for (int i = 0; i < 3; ++i) // make 3 attempts to receive json
    {
        _reader.resetHistory();
        errno = 0;
        auto err = deserializeJson(json, _reader);
        
    DeserializationError err = deserializeJson(json, _cr);
        if (errno == EAGAIN || errno == EWOULDBLOCK)
        {
            cerr << "recv timed out\n";
            continue;
        }
        
    if (err)
        switch (err.code())
        {
            cerr << "Error: couldn't parse JSON (" << err.c_str() << "): " << response << endl;
            return false;
            case DeserializationError::Ok:
                break;
                
            case DeserializationError::NoMemory:
                //TODO
                cerr << "Error: couldn't parse JSON (" << err.c_str() << "): " << _reader.history << endl;
                break;
            
            //these shouldn't happen
            case DeserializationError::InvalidInput:
            case DeserializationError::TooDeep:          
            case DeserializationError::NotSupported:    
            case DeserializationError::IncompleteInput: // this won't happen, as recv (deserializeJson) would time out
                cerr << "Error: couldn't parse JSON (" << err.c_str() << "): " << _reader.history << endl;
                _sock.close();
                connect();
                //TODO: try again
                break;
        }
        
    string key = "rval";

        string key = "msg_id";
        if (!json.containsKey(key) || !json[key].is<int>() || json[key] != (int)expected_msg_id)
        {
            //TODO: Handle unexpected msg_id
            //handleMsgId(json);
            cerr << "Error: unexpected msg_id: " << _reader.history << endl;
            continue;
        }

        key = "rval";
        if (!json.containsKey(key) || !json[key].is<int>() || json[key] != expected_rval)
        {
            cerr << "Error: unexpected JSON response (\"" << key << "\" = " << json[key] << ")" << endl;
            return false;
            //TODO: Handle invalid rval
            //handleRval(json);
            cerr << "Error: unexpected rval (\"" << key << "\" = " << json[key] << ")" << endl;
            break;
        }
        
        return true;
    }
    return false;
}


bool Commander::str2int (const char* s, int& i, int base)
@@ -75,19 +113,20 @@ bool Commander::str2int (const char* s, int& i, int base)

bool Commander::connect()
{
    return _sock.connect("127.0.0.1", 7878);
   auto ret = _sock.connect("127.0.0.1", 7878);
   _sock.setTimeout(1);
   return ret;
}


bool Commander::getToken()
{
    
    if (!_sock.send(generateJSON(MSG::getToken))) 
        return false;
    
    // Get response
    DynamicJsonDocument json(JSON_OBJECT_SIZE(3) + 20);
    if (!getJSON(json))
    if (!getJSON(json, MSG::getToken))
        return false;
    
    string key = "param";
@@ -109,7 +148,7 @@ bool Commander::setISO(Commander::ISO iso)
    
    // Get response
    DynamicJsonDocument json(JSON_OBJECT_SIZE(3) + 20);
    if (!getJSON(json))
    if (!getJSON(json, MSG::setISO))
        return false;
    
    return true;
@@ -123,7 +162,7 @@ bool Commander::setSpeed(Commander::Speed speed)
    
    // Get response
    DynamicJsonDocument json(JSON_OBJECT_SIZE(3) + 20);
    if (!getJSON(json))
    if (!getJSON(json, MSG::setSpeed))
        return false;
    
    return true;
@@ -138,12 +177,12 @@ bool Commander::shoot()
    
    // await "capture was enqueued"
    DynamicJsonDocument json(JSON_OBJECT_SIZE(2) + 20);
    if (!getJSON(json))
    if (!getJSON(json, MSG::shoot))
        return false;
    
    // await "capture has finished"
    json = DynamicJsonDocument(JSON_OBJECT_SIZE(9) + 140);
    if (!getJSON(json, 128))
    if (!getJSON(json, MSG::imgCaptured, 128))
        return false;
    
    string key = "msg_id";
+3 −7
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ public:
    void close();
    

    
private:
    enum class MSG
    {
@@ -77,10 +76,9 @@ private:
    
    int _token;
    TcpSocket _sock;
    CustomReader _cr;
    
    CustomReader _reader;

    bool getJSON(DynamicJsonDocument& json, int expected_rval = 0);
    bool getJSON(DynamicJsonDocument& json, MSG expected_msg_id, int expected_rval = 0);
    static bool str2int (const char* s, int& i, int base = 0);
    
    std::string generateJSON(MSG msg);
@@ -90,8 +88,6 @@ private:





#endif /* COMMANDER_H */


Loading