/*************************************************************************
  File name     : struct.h
  Module        : config_manager
  Author        : 
  Copyright     : 
  Version       : 0.1
  Created on    : 2022-3-21
  Creator       : amir.liang
  Description   :
      Data struct definitions required by Config.
***************************************************************************/
#ifndef __MW_CONFIG_STRUCT_H__
#define __MW_CONFIG_STRUCT_H__
#include <stdint.h>
#define MW_CFG_UUID_LEN		    (64)
#define MW_CFG_SERIAL_LEN		(32)
#define MW_CFG_SYSMODE_LEN		(32)
#define MW_CFG_OFFSET_LEN		(180)
#define MW_CFG_AE_METER_WEIGHT_CNT (96)
#define MW_CFG_IP_LEN			(16)
#define MW_CFG_SSID_LEN		    (32)
#define MW_CFG_PWD_LEN			(64)
#define MW_CFG_CON_PREFIX_LEN	(32)
#define MW_CFG_MAX_ID_NUM		(10)
#define MW_CFG_ID_LEN			(64)
#define MW_CFG_CCODE_LEN		    (4)
#define MW_CFG_MAX_CHN_NUM		(64)
#define MW_CFG_BTRC_VER_LEN	    (32)
#define MW_CFG_SENSOR_ID_LEN	    (16)
#define MW_CFG_ENCODE_STREAM_NUM	(2)
#define MW_CFG_AGING_STRING_LEN	(512)
/*
 * Base Group
 */
typedef struct
{
    uint32_t   factory_mode;
}Mw_CfgBase_FactoryMode_t;

typedef struct
{
    uint64_t   active_time;
}Mw_CfgBase_ActiveTime_t;

typedef struct Mw_Aging_Record_Cfg_Info_s
{
    uint16_t  width;
    uint16_t  height;
    uint8_t   fps;
    uint8_t   encodec;
    uint16_t  bit_rate;
} Mw_Aging_Record_Cfg_Info_t;

typedef struct
{
    uint8_t    aging_flag;
    uint8_t    aging_result_flag;
    uint16_t   aging_nums;
    uint32_t   aging_period;
    uint64_t   aging_start_time;
    uint64_t   aging_stop_time;
    Mw_Aging_Record_Cfg_Info_t aging_config1;
    Mw_Aging_Record_Cfg_Info_t aging_config2;
    Mw_Aging_Record_Cfg_Info_t aging_config3;
    uint8_t    error_info[MW_CFG_AGING_STRING_LEN];
} Mw_CfgBase_FactoryAgingInfo_t;

typedef struct
{
    uint8_t uuid[MW_CFG_UUID_LEN];
}Mw_CfgBase_ProductUUID_t;

typedef struct
{
    uint8_t sn[MW_CFG_UUID_LEN];
}Mw_CfgBase_ProductSerial_t;

typedef struct
{
    uint8_t audio_license[64];
    uint8_t recognition_license[128];
}Mw_CfgBase_License_t;


typedef struct
{
    uint32_t offset_x;
    uint32_t offset_y;
    uint32_t offset_z;

} Mw_CfgBase_GsensorCalib_t;

typedef struct
{
    Mw_CfgBase_FactoryMode_t       factory_mode;
    Mw_CfgBase_ActiveTime_t        active_time;
    Mw_CfgBase_FactoryAgingInfo_t  factory_aging_info;
    Mw_CfgBase_ProductUUID_t       product_uuid;
    Mw_CfgBase_ProductSerial_t     product_sn;
    Mw_CfgBase_License_t           license_info;
    Mw_CfgBase_GsensorCalib_t      gsensor_calib;
    uint8_t rsv[64];
}Mw_CfgBaseGroup_t;

/*
 * System Group
 */
typedef struct
{
    uint32_t enable;
    char ap_ssid[32];
    char ap_password[16];
}Mw_CfgSystem_Wifi_t;

typedef struct
{
    uint32_t enable;
}Mw_CfgSystem_Bluetooth_t;

typedef struct
{
    uint32_t enable;
}Mw_CfgSystem_Usb_t;

typedef struct
{
    uint32_t type;
}Mw_CfgSystem_Sensor_t;

typedef struct
{
    uint32_t percent;
}Mw_CfgSystem_Battery_t;

typedef struct
{
    uint32_t enable;
}Mw_CfgSystem_Led_t;

typedef struct
{
    uint32_t enable;
}Mw_CfgSystem_Button_t;

typedef struct
{
    Mw_CfgSystem_Wifi_t wifi_info;
    Mw_CfgSystem_Bluetooth_t bt_info;
    Mw_CfgSystem_Usb_t usb_info;
    Mw_CfgSystem_Sensor_t sensor_info;
    Mw_CfgSystem_Battery_t battery_info;
    Mw_CfgSystem_Led_t led_info;
    Mw_CfgSystem_Button_t button_info;
    
    uint8_t rsv[128];
}Mw_CfgSystemGroup_t;

/*
 * Common Group
 */
typedef struct
{
    uint32_t cam_mode;
    uint32_t sub_mode;
}Mw_CfgCommon_CamMode_t;

typedef struct
{
    Mw_CfgCommon_CamMode_t mode;
    uint8_t rsv[64];
}Mw_CfgCommonGroup_t;

/*
 * Video Group
 */
typedef struct
{
    uint32_t rec_stream; /* see Mw_Cfg_VideoRecord_stream_e */
}Mw_CfgVideo_Record_stream_t;

typedef struct
{
    uint32_t resolution; /* see Mw_Cfg_VideoResolution_e */
    uint32_t fps;        /* see Mw_Cfg_VideoFps_e */
}Mw_CfgVideo_RecordSpec_t;

typedef struct
{
    uint32_t value[MW_CFG_ENCODE_STREAM_NUM]; //Mbps
}Mw_CfgVideo_Bitrate_t;


typedef struct
{
    uint32_t main_type; /* see Mw_Cfg_VideoCodecType_e */
    uint32_t sub_type;
}Mw_CfgVideo_Codec_t;


typedef struct //birate encode mode: CRB/VRB/SMART_VRB
{
    uint8_t value[MW_CFG_ENCODE_STREAM_NUM]; /* see Mw_Cfg_VideoBrateCtrlType_e */
}Mw_CfgVideo_BrateCtrl_t;


typedef struct
{
    Mw_CfgVideo_Record_stream_t stream;
    Mw_CfgVideo_RecordSpec_t   spec;
    Mw_CfgVideo_Bitrate_t      bitrate;
    Mw_CfgVideo_BrateCtrl_t    bratectrl;
    Mw_CfgVideo_Codec_t        codec;
    uint8_t rsv[128];
} Mw_CfgVideoGroup_t;

/*
 * Photo Group
 */
typedef struct
{
    uint32_t val;
}Mw_CfgPhoto_Resolution_t;

typedef struct {
    uint16_t capnum;
    uint16_t aebnum;          /* should be 0 or the same the CapNum. maximum SVC_STL_MAX_AEB_NUM */
    uint16_t strmmsk;         /* yuv stream mask for CapType = SVC_CAP_TYPE_YUV, or vin mask for CapType = SVC_CAP_TYPE_RAW */
    uint8_t  pictype;         /* 0 - normal picture. 1 - video thumbnail. 2 - dump YUV. */
    uint8_t  syncencstart;
    uint8_t  caponly;
    uint8_t  captype;         /* SVC_CAP_TYPE_YUV - yuv capture, SVC_CAP_TYPE_RAW - raw capture */
    uint8_t  stopliveview;
    uint16_t timelapsemsk;
    uint8_t  Rsvd[16];
} Mw_CfgPhoto_Capcfg_t;

typedef struct
{
    Mw_CfgPhoto_Resolution_t resolution;
    Mw_CfgPhoto_Capcfg_t     capcfg;
    uint8_t rsv[128];
}Mw_CfgPhotoGroup_t;

/*
 * Audio Group
 */
typedef struct
{
    uint32_t bits_per_sample;
    uint32_t aac_bitrate;
    uint32_t volume;
    uint32_t enable_DMIC;
}Mw_CfgAudio_Encode_t;

typedef struct
{
    Mw_CfgAudio_Encode_t encode;
    uint8_t rsv[128];
}Mw_CfgAudioGroup_t;

/*
 * Image Group
 */
typedef struct
{
    uint32_t val;
}Mw_CfgImage_Brightness_t;

typedef struct
{
    uint32_t val;
}Mw_CfgImage_Contrast_t;

typedef struct
{
    uint32_t val;
}Mw_CfgImage_Sharpness_t;

typedef struct
{
    uint32_t exposure_mode;
    int32_t shutter;   //M mode, 1/8000s->-8000000; 120->120000
    uint32_t iso;       //M mode
    float shutter_limit;   //A mode
    uint32_t iso_limit;       //S mode
    float ev_bias;   //P mode
    uint32_t wb_mode;
    uint32_t wb_temp;   //M mode
}Mw_CfgImage_AAA_t;

typedef struct
{
    uint32_t value;
}Mw_CfgImage_AntiFlicker_t;

typedef struct
{
    Mw_CfgImage_Brightness_t brightness;
    Mw_CfgImage_Contrast_t contrast;
    Mw_CfgImage_Sharpness_t sharpness;
    Mw_CfgImage_AAA_t aaa;
    Mw_CfgImage_AntiFlicker_t anti_flicker;
    uint8_t rsv[128];
}Mw_CfgImageGroup_t;

/*
 * Other Group
 */

typedef struct
{
    uint32_t time;
    uint32_t brightness;
}Mw_CfgOther_Lcd_t;
typedef struct
{
    uint32_t enable;
}Mw_CfgOther_Qcap_t;
typedef struct
{
    Mw_CfgOther_Lcd_t lcd_info;
    Mw_CfgOther_Qcap_t quick_cap;
    uint8_t rsv[128];
}Mw_CfgOtherGroup_t;

/*
 * App Group
 */
typedef struct
{
    uint32_t val;
}Mw_CfgApp_Gui_t;

typedef struct
{
    Mw_CfgApp_Gui_t gui;
    uint8_t rsv[128];
}Mw_CfgAppGroup_t;

/*
 * ALL
 */
typedef struct
{
    uint32_t magic;
    uint16_t version;
    uint16_t total_size;
    uint32_t age;          //use the max(main.age, back.age) part
    uint32_t checksum;
}Mw_CfgHeader_t;

typedef struct
{
    Mw_CfgHeader_t header;
    Mw_CfgBaseGroup_t base_info;
    Mw_CfgSystemGroup_t system_info;

}Mw_CfgSysPart_t;


typedef struct
{
    Mw_CfgHeader_t header;

    Mw_CfgCommonGroup_t common_info;
    Mw_CfgVideoGroup_t video_info;
    Mw_CfgPhotoGroup_t photo_info;
    Mw_CfgAudioGroup_t audio_info;
    Mw_CfgImageGroup_t image_info;
    Mw_CfgOtherGroup_t other_info;
    Mw_CfgAppGroup_t app_info;


    uint8_t rsv[256];
}Mw_CfgUserPart_t;

/*
 * Profile related
 */
typedef struct
{
    char val[64];
} Mw_CfgProfileName_t;

typedef struct
{
    uint32_t    valid;
    Mw_CfgProfileName_t name;

    Mw_CfgCommonGroup_t common_info;
    Mw_CfgVideoGroup_t video_info;
    Mw_CfgPhotoGroup_t photo_info;
    Mw_CfgAudioGroup_t audio_info;
    Mw_CfgImageGroup_t image_info;
    uint8_t rsv[256];
}Mw_CfgProfileSetting_t;

#endif