#include <stdio.h>
#include <string.h>
#include "mx_store.h"
#include "mx_alternator_data.h"

Store_t UserData;

void store_init(void)
{
    Storeinit(&UserData);
}

// 初始化Store_t结构体
void Storeinit(Store_t* store)
{
    store->mSoftMainVersion = 0;	   //主版本号
	store->mSoftSubVersion = 0;	       //次版本号
	//uint8_t bt_name[BT_NAME_MAX_LEN];
	store->mSetMode = 0;               //高字节 SET 1 为短按 2为长按  低字节 MODE 1 为短按 2为长按
	store->mSpeed = 0;                 //速度信息
	store->mGearInfo = 0;              //档位信息
	store->mTotalMile = 0;             //总计里程
    store->mTripMile = 0;              //单次行驶里程
    store->mMileClearTags = 0;         //小计里程清零标志
	store->mWifi = 0;				   //WIFI
	store->mBlueTooth = 0;             //蓝牙
	store->mTurn = 0;				   //转向 	0-无 1-左转 2-右转
	store->mTurnPrompt = 0;			   //转向提示	0无 1左 2右
    store->mTurnLight = 0;              //转向灯  0-无 1-左转向灯 2-右转向灯
    store->mBeamLight = 0;              //灯光	0-无灯光 1-远光 2-近光 3-自动大灯
    store->mSideMarkerLight = 0;        //示宽灯 0-无灯光 1-示宽灯
    store->mFanLight = 0;               //风扇灯 0-无灯光 1-灯亮
    store->mABSLight = 0;               //0-无灯光 1-灯亮
    store->mOilPressLight = 0;          //机油压力报警灯 0-无灯光 1-灯亮
    store->mEngineLight = 0;            //0-无灯光 1-灯亮
    store->mRefreshTags = 0;            //0-无刷新 1-油量/水温/电池电压刷新标志

    store->mLightValue = 0;             //灯光亮度,具体的light_value值
	store->mSelfCheck = 0;	           //开机自检
	store->mLightSensingVolt = 0;       //光感电压值 （暂定范围0-3300）

	//store->return_demo = 0;             //????
	memcpy(&store->mUuid, 0, 32*sizeof(char));
	memcpy(&store->mBT_name, 0, 32*sizeof(char));
	//UserData.mUuid[32] = {0};
	//UserData.mBT_name[32] = {0};
	store->mCurrentFaultCode = 0;		//当前故障码
	store->mHistoryFaultCode = 0;		//历史故障码

	store->mBTData_Inherit = 0;          //继承的蓝牙数据(保留)
	store->mTtrb = 0;					//开机检测是否获取到时间的标志
	store->mTtrb_Time = 0;				//设施时间后检测是否正常设置时间的标志
	store->mOdo_Reset = 0;				//小计里程清零后检测是否正常设置时间的标志
	store->mDemo_Position = 0;			//是否在demo展示界面的标志

    //告警错误
	store->mErr.mEngine = 0;
    store->mErr.mEngineOil = 0;
    store->mErr.mAbs = 0;
    store->mErr.mTcs = 0;
    store->mErr.mFan = 0;
    store->mErr.mNeutralGear = 0;
    store->mErr.mWaterTemper = 0;
    store->mErr.mBrakesFault = 0;

    //保存数据
	store->mSaveData.mFactorySet = 0;      //出厂设置
	store->mSaveData.mLanguage = 0;		   //语言
	store->mSaveData.mDisplayUint = 0;	   //单位
	store->mSaveData.mTheme = 0;		   //当前主题
	store->mSaveData.mThemeState = 0;	   //主题状态
	store->mSaveData.mLightValue = 0;	   //亮度
	store->mSaveData.mBT_OnOff = 0;		   //蓝牙
	store->mSaveData.mBT_State = 0;	   //状态
	store->mSaveData.mGearPos = 0;			//档位
	store->mSaveData.mFuel = 0;			//油量
	store->mSaveData.mTotalMile = 0;		//里程数

	//时间变量
	store->mTime.ucYear = 0;
	store->mTime.ucMonth = 0;
	store->mTime.ucDate = 0;
	store->mTime.ucHour = 0;
	store->mTime.ucMinute = 0;
	store->mTime.ucSecond = 0;

	store->mPlan = 0;		//总进度标志
	store->mPace = 0;		//分进度标志
	store->mUpGrade = 0;	    //内存拷贝标志

	//电摩专用属性
	store->mBatteryRatio = 0;      //电池电量占比  1个字节（eg100% 传输64）
	store->mBatteryVoltage = 0;    //电池电压 （eg3.3V 传输3300）

    //油摩专用属性
    store->mEspeed = 0;            //转速信息
	store->mFuel = 0;              //油量指示
	store->mWaterTemper = 0;       //水温指示
	store->mAccumulatorVolt = 0;   //电瓶电压

}

Store_t* store_get(void)
{
    return &UserData;
}

void store_set(Store_t store)
{
    UserData = store;
}

ErrorCode_t* error_code_get(void)
{
    return &UserData.mErr;
}

void error_code_set(ErrorCode_t error)
{
    UserData.mErr = error;
}
