/*
*********************************************************************************************************
*                                       IAR Development Kits
*                                              on the
*
*                                    Nano130
*
* Filename      : def_data.c
* Version       : V1.00
* Programmer(s) : Qian Xianghong
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/

#include  "includes.h"

// 硬件版本号（TTS-罐箱-槽车-低功耗4G）【该版本号用于升级时确定硬件版本】
const uint8_t HARDWARE_VER_MINOR = 10; // 智能液位仪（STM32版，本地指针显示）

// 客户和选项组合配置【该版本号用于上传到服务器，确定具体配置】
#ifdef _LOCAL_NEEDLE_VER_
	const uint8_t HARDWARE_VER_MAJOR = 0;	
#endif
#ifdef _PRAXAIR_TTS_VER_
	const uint8_t HARDWARE_VER_MAJOR = 202;	
#endif
#ifdef _PRAXAIR_DOL_VER_
	const uint8_t HARDWARE_VER_MAJOR = 203;
#endif
#ifdef _YINGDE_TTS_VER_
	const uint8_t HARDWARE_VER_MAJOR = 212;	
#endif
#ifdef _YINGDE_DOL_VER_
	const uint8_t HARDWARE_VER_MAJOR = 222;
#endif
#ifdef _LINDE_HTTPS_CHARGE_VER_
	const uint8_t HARDWARE_VER_MAJOR = 213;	
#endif
#ifdef _LINDE_HTTPS_VER_
	const uint8_t HARDWARE_VER_MAJOR = 223;
#endif
#ifdef _MESSER_TTS_VER_
	const uint8_t HARDWARE_VER_MAJOR = 214;
#endif
#ifdef _FAYEKONG_TTS_VER_
	const uint8_t HARDWARE_VER_MAJOR = 215;
#endif
#ifdef _BAOGANG_TTS_VER_
	const uint8_t HARDWARE_VER_MAJOR = 216;
#endif
#ifdef _FUSHIKANG_TTS_VER_
	const uint8_t HARDWARE_VER_MAJOR = 218;
#endif
#ifdef _ZHONGHAIYOU_BOX_VER_
	const uint8_t HARDWARE_VER_MAJOR = 219;
#endif
#ifdef _BOX_500_2_VER_
	const uint8_t HARDWARE_VER_MAJOR = 162;
#endif
#ifdef _BOX_1000_2_VER_
	const uint8_t HARDWARE_VER_MAJOR = 163;
#endif
#ifdef _BOX_1000_3_VER_
	const uint8_t HARDWARE_VER_MAJOR = 164;
#endif
#ifdef _CAOCHE_VER_
	const uint8_t HARDWARE_VER_MAJOR = 149;
#endif
#ifdef _LANSHI_TTS_VER_
	const uint8_t HARDWARE_VER_MAJOR = 217;
#endif
#ifdef _CHATE_TTS_VER_
	const uint8_t HARDWARE_VER_MAJOR = 225;
#endif

// 软件版本号
const uint8_t SOFTWARE_VER_MAJOR = 1;
const uint8_t SOFTWARE_VER_MINOR = 10;	// TTS-4G低功耗
// 软件日期
const uint8_t SOFTWARE_DATE_YEAR = 25;
const uint8_t SOFTWARE_DATE_MONTH = 2;
const uint8_t SOFTWARE_DATE_DAY = 21;

// 存储格式版本号=1.1
const uint8_t CONFIG_FORMAT_VER_MAJOR = 1;
const uint8_t CONFIG_FORMAT_VER_MINOR = 1;	// 新结构整体式，带双向通信

// 远传协议版本号
const uint8_t REPORT_PROTOCOL_VER_MAJOR = 0;
// 0: 压力单位为bar，1：压力单位为KPa, 107: 支持历史数据发送
const uint8_t REPORT_PROTOCOL_VER_MINOR = 107;

// DTU参数
const uint32_t DTU_BAUDRATE = 115200ul;
const uint8_t DTU_PARITY = PARITY_NONE;

// 蓝牙协议版本号
const uint8_t BLUETOOTH_PROTOCOL_VER_MAJOR = 1;
const uint8_t BLUETOOTH_PROTOCOL_VER_MINOR = 0;

// 蓝牙参数
const uint32_t BLUETOOTH_BAUDRATE = 9600ul;
const uint8_t BLUETOOTH_PARITY = PARITY_NONE;

// 存放全部配置和采集数据的结构体
data_buff_t dcBuff = {0};

// MQTT/HTTPS/HTTP服务器列表
const char SERVER_URLs[][100] =
{
	// 林德服务器
	"/TelemetryWebService.TelemetryWebContract.svc/Postmeasurements",
	// 中海油阿里云服务器
	"iot-as-mqtt.cn-shanghai.aliyuncs.com",
};

// 各个数据块的长度
const uint8_t	Config_DataLen[] =
{
	sizeof(config_bottle_t),
	sizeof(config_sensor_t),
	sizeof(config_data_t),
	sizeof(config_display_t),
	sizeof(sysinfo_sample_t),
	sizeof(sysinfo_power_t),
	sizeof(sysinfo_display_t),
	sizeof(sysinfo_bluetooth_t),
	sizeof(data_dtu_t),
	sizeof(data_sample_t),
	sizeof(adc_sample_t),
};

// 各个数据区的地址
const void*	Config_DataPtr[] =
{
	&dcBuff.configBottle,
	&dcBuff.configSensor,
	&dcBuff.configData,
	&dcBuff.configDisplay,
	&dcBuff.sampleInfo,
	&dcBuff.powerInfo,
	&dcBuff.displayInfo,
	&dcBuff.bluetoothInfo,
	&dcBuff.dtuData,
	&dcBuff.sampleData,
	&dcBuff.adcData,	
};

// 液体密度：LNG=0.42g/cm3=420kg/m3
//            O2=1.143g/cm3=1143kg/m3
//            N2=0.81g/cm3=810kg/m3
//            AR=1.402g/cm3=1402kg/m3
//           CO2=1.024g/cm3=1024kg/m3
const float LSrc_Density[] = {0.42, 1.143, 0.81, 1.402, 1.024}; // 单位kg/L

// 液体密度： H2=0.071g/cm3=71kg/m3
//           CNG=0.071g/cm3=71kg/m3
//            He=0.125g/cm3=125kg/m3
//            C2H4=0.568g/cm3=568kg/m3
//            LPG=0.539g/cm3=539kg/m3
//           NH3=0.618g/cm3=618kg/m3
//           PENT=0.630g/cm3=630kg/m3
//           POPO=1.038g/cm3=1038kg/m3
const uint16_t LSrc_DensityExt[] = {71, 71, 125, 568, 539, 618, 630, 1038}; // 单位kg/m3

// 设置和获取介质密度
void Config_SetDensity(uint8_t source, float density)
{
	if(source < sizeof(dcBuff.configBottle.density) / sizeof(float))
		dcBuff.configBottle.density[source] = density;
	else
		dcBuff.configBottle.densityExt[source - sizeof(dcBuff.configBottle.density) / sizeof(float)] = (uint16_t) (density * 1000);
}

float Config_GetDensity(uint8_t source)
{
	if(source < sizeof(dcBuff.configBottle.density) / sizeof(float))
		return dcBuff.configBottle.density[source];
	return dcBuff.configBottle.densityExt[source - sizeof(dcBuff.configBottle.density) / sizeof(float)] * 0.001;
}

// 多项式为x16+x15+x2+1,LSB顺序
uint16_t do_crc_16(unsigned short crc_reg, uint8_t *message, int16_t len)
{
    int16_t i, j;
    uint16_t current;
       
    for (i = 0; i < len; i++)
    {
        current = message[i];
        for (j = 0; j < 8; j++)
        {
            if ((crc_reg ^ current) & 0x0001)
                crc_reg = (crc_reg >> 1) ^ 0xA001;
            else
                crc_reg >>= 1;
            current >>= 1;
        }
    }
    return crc_reg;
}

// 检查固定的字段
uint32_t Config_CheckValid(rd_buff_t *rdBuff, uint8_t DC)
{
	if(rdBuff->header.mark != CONFIG_MARK_LS)
		return FALSE;
	if(rdBuff->header.product != CONFIG_PRODUCT_CY)
		return FALSE;
	if(rdBuff->header.DC != DC)
		return FALSE;
	if(rdBuff->header.ver.major != CONFIG_FORMAT_VER_MAJOR || rdBuff->header.ver.minor != CONFIG_FORMAT_VER_MINOR)
		return FALSE;
	if(do_crc_16(0, rdBuff->buff, CONFIG_DATA_LEN(DC)) != 0)
		return FALSE;
	return TRUE;
}

// 写入固定的字段
void Config_ForceValid(rd_buff_t *rdBuff, uint8_t DC)
{
	uint8_t pos = CONFIG_DATA_LEN(DC) - 2;
	
	rdBuff->header.mark = CONFIG_MARK_LS;
	rdBuff->header.product = CONFIG_PRODUCT_CY;
	rdBuff->header.DC = DC;
	rdBuff->header.ver.major = CONFIG_FORMAT_VER_MAJOR;
	rdBuff->header.ver.minor = CONFIG_FORMAT_VER_MINOR;
	Int2ByteS(rdBuff->buff, pos, do_crc_16(0, rdBuff->buff, pos));
}

// 设置储罐参数的默认值
void Config_setBottleDefParam(data_buff_t *dataBuff)
{
	uint8_t i;
	
	memset(&dataBuff->configBottle, 0, sizeof(dataBuff->configBottle));

#if defined(_PRAXAIR_SERVER_)	
	dataBuff->configBottle.serverVer = 3;	// 服务器参数版本号: 普莱克斯专用版本
#elif defined(_LINDE_SERVER_)
	dataBuff->configBottle.serverVer = 4;	// 服务器参数版本号: 林德专用版本
#elif defined(_BAOGANG_SERVER_)
	dataBuff->configBottle.serverVer = 5;	// 服务器参数版本号: 宝钢专用版本
#else
	dataBuff->configBottle.serverVer = 0;	// 服务器参数版本号: 安捷汇版本
#endif	
	dataBuff->configBottle.updateFlag = 1;	// 参数更新标志
	
	dataBuff->configBottle.addr = 1;
	dataBuff->configBottle.type = BOTTLE_TYPE_LYING;
	dataBuff->configBottle.source = SOURCE_N2;
	dataBuff->configBottle.len = 10000;
	dataBuff->configBottle.diameter = 2650;
	dataBuff->configBottle.lenExtra = 0;
	for(i = 0; i < sizeof(dataBuff->configBottle.density) / sizeof(float); i++)
		dataBuff->configBottle.density[i] = LSrc_Density[i];
	for(i = 0; i < sizeof(dataBuff->configBottle.densityExt) / sizeof(uint16_t); i++)
		dataBuff->configBottle.densityExt[i] = LSrc_DensityExt[i];
	dataBuff->configBottle.chargePct = 100;
	dataBuff->configBottle.measureType = MEASURE_DPRESS;
	
	// 以下参数，如为0则表示无效
	
	dataBuff->configBottle.fullPct = 0;	// 满液位百分比
	dataBuff->configBottle.emptyPct = 0;	// 空液位百分比
	
	dataBuff->configBottle.priPct = 0;		// 关键液位百分比
	dataBuff->configBottle.orderPct = 0;	// 订货液位百分比
	dataBuff->configBottle.planMount = 0;	// 每日计划用量
	dataBuff->configBottle.predictMount = 0;	// 每日预测用量
	dataBuff->configBottle.warnVolt = 0;		// 电压报警低点: 10mV
	dataBuff->configBottle.warnVoltH = 0;		// 电压报警高点: 10mV
	
	dataBuff->configBottle.warnPress = 0;		// 压力报警低点: KPa
	dataBuff->configBottle.warnPressH = 0;		// 压力报警高点
	
	dataBuff->configBottle.options = 0x0003;	// 参数开关
	dataBuff->configBottle.ts = 0;				// 参数时间戳
	dataBuff->configBottle.dispMode = DISP_MODE_ALL; // 显示模式
	
//#ifdef _PRAXAIR_SERVER_
//	// praxair
//	dataBuff->configBottle.floorLevel = 0;
//	dataBuff->configBottle.span = 0;
//	dataBuff->configBottle.spanPeriod = 3600;
//#else
//	// others
	dataBuff->configBottle.warnVacuumH = 0;			// 真空度报警高点：0.01Pa
	dataBuff->configBottle.warnTempr = 0;		// 温度报警高点: ℃


	Config_ForceValid((rd_buff_t *) &dataBuff->configBottle, CAN_DC_BOTTLE_CONFIG);
}

// 设置传感器参数的默认值
void Config_setSensorDefParam(data_buff_t *dataBuff)
{
	uint8_t i;
	
	memset(&dataBuff->configSensor, 0, sizeof(dataBuff->configSensor));

	dataBuff->configSensor.sensorWeight.lowRange = 0;
	dataBuff->configSensor.sensorWeight.highRange = 100000ul;	// 100000kg
	dataBuff->configSensor.sensorWeight.zeroValue = 84030ul;	// 经验值
	dataBuff->configSensor.sensorWeight.fullValue = 1613530ul;	// 经验值

//#ifndef _USE_CAPACITY_SENSOR_
//	#if defined(_DOL_VER_)
//		dcBuff.configSensor.sensorDPress.lowRange = 0;			// 0KPa
//		dcBuff.configSensor.sensorDPress.highRange = 150;        // 150KPa
//		dcBuff.configSensor.sensorDPress.zeroValue = 710;	 	// 理论值：4mA * 130Ω / 3.0v
//		dcBuff.configSensor.sensorDPress.fullValue = 3550; 		// 理论值：20mA * 130Ω / 3.0v
//	#elif defined(_LOCAL_NEEDLE_VER_)
//		dcBuff.configSensor.sensorDPress.lowRange = 0;			// 0KPa
//		dcBuff.configSensor.sensorDPress.highRange = 15;        // 15KPa
//		dcBuff.configSensor.sensorDPress.zeroValue = 683;	 	// 理论值：0.5v / 3.0v
//		dcBuff.configSensor.sensorDPress.fullValue = 3823; 		// 理论值：2.8v / 3.0v
//	#else
		dcBuff.configSensor.sensorDPress.lowRange = 0;			// 0KPa
		dcBuff.configSensor.sensorDPress.highRange = 50;        // 50KPa
		dcBuff.configSensor.sensorDPress.zeroValue = 683;	 	// 理论值：0.5v / 3.0v
		dcBuff.configSensor.sensorDPress.fullValue = 3823; 		// 理论值：2.8v / 3.0v
//	#endif
//#else	
//	dataBuff->configSensor.sensorCap.c1ADC = 1114;				// 电容c1标定ADC值
//	dataBuff->configSensor.sensorCap.c2ADC = 3417;        		// 电容c2标定ADC值
//	dataBuff->configSensor.sensorCap.baseC = 708 * 10;	 			// 底电容(pF)
//	dataBuff->configSensor.sensorCap.refC = 439 * 10; 				// 增长电容(pF)
//#endif
	
//#ifndef _DOL_VER_
	dataBuff->configSensor.sensorPress.lowRange = 0;			// 0MPa
	dataBuff->configSensor.sensorPress.highRange = 4000;        // 4MPa
	dataBuff->configSensor.sensorPress.zeroValue = 683;	 		// 理论值：0.5v / 3.0v
	dataBuff->configSensor.sensorPress.fullValue = 3823; 		// 理论值：2.8v / 3.0v
//#else
//	dataBuff->configSensor.sensorPress.lowRange = 0;			// 0MPa
//	dataBuff->configSensor.sensorPress.highRange = 5000;        // 5MPa
//	dataBuff->configSensor.sensorPress.zeroValue = 710;		// 理论值：4mA * 130Ω / 3.0v
//	dataBuff->configSensor.sensorPress.fullValue = 3550;	// 理论值：20mA * 130Ω / 3.0v
//#endif
	
//	for(i = 0; i < sizeof(dataBuff->configSensor.sensorEPress) / sizeof(press_param_t); i++)
//	{
//		dataBuff->configSensor.sensorEPress[i].lowRange = 0;		// 0MPa
//		dataBuff->configSensor.sensorEPress[i].highRange = 4000;    // 4MPa
//		dataBuff->configSensor.sensorEPress[i].zeroValue = 710;		// 理论值：4mA * 130Ω / 3.0v
//		dataBuff->configSensor.sensorEPress[i].fullValue = 3550;	// 理论值：20mA * 130Ω / 3.0v
//	}

//#ifndef _USE_PT100_SENSOR_		
//	for(i = 0; i < sizeof(dataBuff->configSensor.sensorMTempr) / sizeof(tempr_param_t); i++)
//	{
//		dataBuff->configSensor.sensorMTempr[i].lowRange = -200;		// -200℃
//		dataBuff->configSensor.sensorMTempr[i].highRange = 80;		// 80℃
//		dataBuff->configSensor.sensorMTempr[i].zeroValue = 710;		// 理论值：4mA * 130Ω / 3.0v
//		dataBuff->configSensor.sensorMTempr[i].fullValue = 3550;	// 理论值：20mA * 130Ω / 3.0v
//	}
//#else
//	for(i = 0; i < sizeof(dataBuff->configSensor.sensorPTempr) / sizeof(pt100_param_t); i++)
//	{
//		// 导线在18℃下每米电阻为0Ω，温度每下降1℃导线电阻下降1.3‰，假设导线长度为1.7米。
//		// （此处默认为忽略导线电阻，实际可根据测量偏差手动调节）
//		
//		// 在0℃下，导线电阻为0*1.7*（1- 18 * 1.3‰） = 0Ω
//		// PT100铂电阻的阻值和温度的关系直接查表，在0℃下为100Ω。
//		dataBuff->configSensor.sensorPTempr[i].calibrateT = 0 * 10;	// 校准温度0℃
//		dataBuff->configSensor.sensorPTempr[i].calibrateR = (int16_t) ((100 * _PT100_MULTI_ + 0) * 10);	// 0℃下PT100电阻+线电阻（1.7米）
//		
//	#if _PT100_MULTI_ == 5		
//		// 在-200℃下，导线电阻为0*1.7*（1- 218 * 1.3‰） = 0Ω，PT500电阻为92.6Ω，在电桥下测得电压为2.917v
//		// (2.5-(0+92.6+4500)/(0+92.6+9500)*5)*15.7+1.25=2.917v
//		dataBuff->configSensor.sensorPTempr[i].zeroValue = 3983;		// 理论值：2.917v / 3.0v
//		
//		// 在80℃下，导线电阻为0*1.7*（1+ 62 * 1.3‰） = 0Ω，PT500电阻为654.5Ω，在电桥下测得电压为0.653v
//		// (2.5-(0+654.5+4500)/(0+654.5+9500)*5)*15.7+1.25=0.653v
//		dataBuff->configSensor.sensorPTempr[i].fullValue = 891;			// 理论值：0.653v / 3.0v
//	#else	// PT1000
//		// 在-200℃下，导线电阻为0*1.7*（1-218 * 1.3‰） = 0Ω，PT1000电阻为185.2Ω，在电桥下测得电压为2.917v
//		// (2.5-(0+185.2+9000)/(0+185.2+19000)*5)*15.7+1.25=2.917v
//		dataBuff->configSensor.sensorPTempr[i].zeroValue = 3983;		// 理论值：2.917v / 3.0v
//		
//		// 在80℃下，导线电阻为0*1.7*（1+62 * 1.3‰） = 0Ω，PT1000电阻为1309Ω，在电桥下测得电压为0.653v
//		// (2.5-(0+1309+9000)/(0+1309+19000)*5)*15.7+1.25=0.653v
//		dataBuff->configSensor.sensorPTempr[i].fullValue = 891;			// 理论值：0.653v / 3.0v
//	#endif
//	}
//#endif
	
	Config_ForceValid((rd_buff_t *) &dataBuff->configSensor, CAN_DC_SENSOR_CONFIG);
}

// 设置数据参数的默认值
void Config_setDataDefParam(data_buff_t *dataBuff)
{
	memset(&dataBuff->configData, 0, sizeof(dataBuff->configData));

#if defined(_PRAXAIR_SERVER_) || defined(_LINDE_SERVER_)
	strcpy(dataBuff->configData.server, "tts.praxair.com.cn");
	dataBuff->configData.port = 7005;
#elif defined(_LANSHI_SERVER_)
	strcpy(dataBuff->configData.server, "pazx.cd-ls.cn");
	dataBuff->configData.port = 8088;
	strcpy(dataBuff->configData.gpsServer, "track.cd-ls.cn");
	dataBuff->configData.gpsPort = 8070;
#elif defined(_FUSHIKANG_SERVER_)
	strcpy(dataBuff->configData.server, "183.56.160.149 ");
	dataBuff->configData.port = 7888;
#elif defined(_ZHONGHAIYOU_SERVER_)	// mqtt提交到阿里云	
	dataBuff->configData.port = 1883;
//#elif defined(_LINDE_SERVER_)		// https提交到林德服务器
//	strcpy(dataBuff->configData.server, "Telemetry.Linde.com");
//	dataBuff->configData.port = 443;
#else // _ANJIEHUI_SERVER_
	strcpy(dataBuff->configData.server, "data.ajhiot.com");	// 2021.03.31修改
	dataBuff->configData.port = 8088;
	strcpy(dataBuff->configData.gpsServer, "track.ajhiot.com");
	dataBuff->configData.gpsPort = 8070;
#endif

#if defined(_PRAXAIR_SERVER_) || defined(_LINDE_SERVER_)
	strcpy(dataBuff->configData.upgServer, dataBuff->configData.server);
#else
	strcpy(dataBuff->configData.upgServer, "extra.cd-ls.cn");
#endif
	dataBuff->configData.upgPort = 7006;

#if defined(_PRAXAIR_TTS_VER_) || defined(_PRAXAIR_DOL_VER_)
	dataBuff->configData.intervalSample = 3600;
	dataBuff->configData.intervalTrans = 21600;
#elif defined(_YINGDE_TTS_VER_) || defined(_YINGDE_DOL_VER_)
	dataBuff->configData.intervalSample = 900;
	dataBuff->configData.intervalTrans = 7200;
#elif defined(_LINDE_HTTPS_CHARGE_VER_) || defined(_LINDE_HTTPS_VER_)
	dataBuff->configData.intervalSample = 900;
	dataBuff->configData.intervalTrans = 21600;
#elif defined(_MESSER_TTS_VER_)
	dataBuff->configData.intervalSample = 1800;
	dataBuff->configData.intervalTrans = 21600; //1800; // 暂不上传，故临时降低发送频率
#elif defined(_FAYEKONG_TTS_VER_)
	dataBuff->configData.intervalSample = 1800;
	dataBuff->configData.intervalTrans = 21600;
#elif defined(_BAOGANG_TTS_VER_)
	dataBuff->configData.intervalSample = 1800;
	dataBuff->configData.intervalTrans = 3600;
#elif defined(_BOX_VER_)
	dataBuff->configData.intervalSample = 3600;
	dataBuff->configData.intervalTrans = 3600;
#elif defined(_CAOCHE_VER_)
	dataBuff->configData.intervalSample = 300;
	dataBuff->configData.intervalTrans = 300;
#elif defined(_CHATE_TTS_VER_)
	dataBuff->configData.intervalSample = 1800;
	dataBuff->configData.intervalTrans = 21600;
#elif defined(_LOCAL_NEEDLE_VER_)
	dataBuff->configData.intervalSample = 60;
	dataBuff->configData.intervalTrans = 60;
#else	// _LANSHI_TTS_VER_
	dataBuff->configData.intervalSample = 3600;
	dataBuff->configData.intervalTrans = 21600;
#endif

	dataBuff->configData.intervalGPS = 4;
	dataBuff->configData.intervalGPSTrans = 60;
	dataBuff->configData.timeLag = 8;
	
	Config_ForceValid((rd_buff_t *) &dataBuff->configData, CAN_DC_DATA_CONFIG);
}

// 设置显示参数的默认值
void Config_setDisplayDefParam(data_buff_t *dataBuff)
{
	memset(&dataBuff->configDisplay, 0, sizeof(dataBuff->configDisplay));

	dataBuff->configDisplay.lightDelay = 0;
	dataBuff->configDisplay.dispDelay = 30;
	dataBuff->configDisplay.unit = DISP_UNIT_METRIC;
	dataBuff->configDisplay.L_Unit = UNIT_MMH2O;
	strcpy(dataBuff->configDisplay.pwd1, "2222");		// 储罐参数修改密码
	strcpy(dataBuff->configDisplay.pwd2, "3003");		// 传感器标定密码
	strcpy(dataBuff->configDisplay.APN, "CMIOT");
	dataBuff->configDisplay.bdCommander = 0x03300D;		// 北斗指挥机卡号

	dataBuff->configDisplay.op_HARDWARE_VER_MAJOR = HARDWARE_VER_MAJOR;	// 硬件配置（不同客户和选项的组合）
#ifdef _DISP_MMWC_ONLY_
	dataBuff->configDisplay.op_DISP_MMWC_ONLY = 1;
#endif

#ifdef _DOL_VER_	
	dataBuff->configDisplay.op_DOL_VER = 1;
#endif
#ifdef _BOX_VER_	
	dataBuff->configDisplay.op_BOX_VER = 1;
#endif
#ifdef _CELL_LOCATION_	
	dataBuff->configDisplay.op_CELL_LOCATION = 1;
#endif
#ifdef _LEVEL_SENSOR_ONLY_	
	dataBuff->configDisplay.op_LEVEL_SENSOR_ONLY = 1;
#endif
#ifdef _USE_PT100_SENSOR_	
	dataBuff->configDisplay.op_USE_PT100_SENSOR = 1;
#endif
	dataBuff->configDisplay.op_PT100_MULTI = _PT100_MULTI_;
#ifdef _PT100_3LINE_	
	dataBuff->configDisplay.op_PT100_3LINE = 1;
#endif
#ifdef _DIFF_RESIST_	
	dataBuff->configDisplay.op_DIFF_RESIST = 1;
#endif
#ifdef _SEND_GPS_DATA_	
	dataBuff->configDisplay.op_SEND_GPS_DATA = 1;
#endif
#ifdef _USE_CAPACITY_SENSOR_	
	dataBuff->configDisplay.op_USE_CAPACITY_SENSOR = 1;
#endif
#if defined(_ZHONGHAIYOU_SERVER_)	// mqtt提交到阿里云	
	dataBuff->configDisplay.op_SERVER_PROTOCOL = SERVER_PROTOCOL_MQTT;
	dataBuff->configDisplay.op_SERVER_INDEX = 1;
//#elif defined(_LINDE_SERVER_)		// https提交到林德服务器
//	dataBuff->configDisplay.op_SERVER_PROTOCOL = SERVER_PROTOCOL_HTTPS;
//	dataBuff->configDisplay.op_SERVER_INDEX = 0;
#else
	dataBuff->configDisplay.op_SERVER_PROTOCOL = SERVER_PROTOCOL_TCP;
#endif
#ifdef _FUSHIKANG_SERVER_	
	dataBuff->configDisplay.op_UNIDIR_COMM = 1;
#endif

	Config_ForceValid((rd_buff_t *) &dataBuff->configDisplay, CAN_DC_DISPLAY_CONFIG);
}

// 填充采集板系统信息
void Config_fillSampleInfo(data_buff_t *dataBuff)
{
	memset(&dataBuff->sampleInfo, 0, sizeof(dataBuff->sampleInfo));
	
	dataBuff->sampleInfo.boardFlag = CONFIG_BOARD_SELF;
	dataBuff->sampleInfo.hardVer.major = dcBuff.configDisplay.op_HARDWARE_VER_MAJOR;
	dataBuff->sampleInfo.hardVer.minor = HARDWARE_VER_MINOR;
	dataBuff->sampleInfo.softVer.major = SOFTWARE_VER_MAJOR;
	dataBuff->sampleInfo.softVer.minor = SOFTWARE_VER_MINOR;
	dataBuff->sampleInfo.softDate.year = SOFTWARE_DATE_YEAR;
	dataBuff->sampleInfo.softDate.month = SOFTWARE_DATE_MONTH;
	dataBuff->sampleInfo.softDate.day = SOFTWARE_DATE_DAY;
}

// 填充电源板系统信息
void Config_fillPowerInfo(data_buff_t *dataBuff)
{
	memset(&dataBuff->powerInfo, 0, sizeof(dataBuff->powerInfo));
	
	dataBuff->powerInfo.boardFlag = CONFIG_BOARD_SELF;
	dataBuff->powerInfo.hardVer.major = dcBuff.configDisplay.op_HARDWARE_VER_MAJOR;
	dataBuff->powerInfo.hardVer.minor = HARDWARE_VER_MINOR;
	dataBuff->powerInfo.softVer.major = SOFTWARE_VER_MAJOR;
	dataBuff->powerInfo.softVer.minor = SOFTWARE_VER_MINOR;
	dataBuff->powerInfo.softDate.year = SOFTWARE_DATE_YEAR;
	dataBuff->powerInfo.softDate.month = SOFTWARE_DATE_MONTH;
	dataBuff->powerInfo.softDate.day = SOFTWARE_DATE_DAY;
	dataBuff->powerInfo.protocolVer.major = REPORT_PROTOCOL_VER_MAJOR;
	dataBuff->powerInfo.protocolVer.minor = REPORT_PROTOCOL_VER_MINOR;
	dataBuff->powerInfo.baudrate = DTU_BAUDRATE;
	dataBuff->powerInfo.parity = DTU_PARITY;
}

// 填充显示板系统信息
void Config_fillDisplayInfo(data_buff_t *dataBuff)
{
	memset(&dataBuff->displayInfo, 0, sizeof(dataBuff->displayInfo));
	
	dataBuff->displayInfo.boardFlag = CONFIG_BOARD_SELF;
	dataBuff->displayInfo.hardVer.major = dcBuff.configDisplay.op_HARDWARE_VER_MAJOR;
	dataBuff->displayInfo.hardVer.minor = HARDWARE_VER_MINOR;
	dataBuff->displayInfo.softVer.major = SOFTWARE_VER_MAJOR;
	dataBuff->displayInfo.softVer.minor = SOFTWARE_VER_MINOR;
	dataBuff->displayInfo.softDate.year = SOFTWARE_DATE_YEAR;
	dataBuff->displayInfo.softDate.month = SOFTWARE_DATE_MONTH;
	dataBuff->displayInfo.softDate.day = SOFTWARE_DATE_DAY;
}

// 填充蓝牙板系统信息
void Config_fillBluetoothInfo(data_buff_t *dataBuff)
{
	memset(&dataBuff->bluetoothInfo, 0, sizeof(dataBuff->bluetoothInfo));
	
	dataBuff->bluetoothInfo.boardFlag = CONFIG_BOARD_SELF;
	dataBuff->bluetoothInfo.hardVer.major = dcBuff.configDisplay.op_HARDWARE_VER_MAJOR;
	dataBuff->bluetoothInfo.hardVer.minor = HARDWARE_VER_MINOR;
	dataBuff->bluetoothInfo.softVer.major = SOFTWARE_VER_MAJOR;
	dataBuff->bluetoothInfo.softVer.minor = SOFTWARE_VER_MINOR;
	dataBuff->bluetoothInfo.softDate.year = SOFTWARE_DATE_YEAR;
	dataBuff->bluetoothInfo.softDate.month = SOFTWARE_DATE_MONTH;
	dataBuff->bluetoothInfo.softDate.day = SOFTWARE_DATE_DAY;
	dataBuff->bluetoothInfo.protocolVer.major = BLUETOOTH_PROTOCOL_VER_MAJOR;
	dataBuff->bluetoothInfo.protocolVer.minor = BLUETOOTH_PROTOCOL_VER_MINOR;
	dataBuff->bluetoothInfo.baudrate = BLUETOOTH_BAUDRATE;
	dataBuff->bluetoothInfo.parity = BLUETOOTH_PARITY;
}

// 检查参数修改标志
uint32_t Config_CheckUpdate(data_buff_t *dataBuff)
{
	uint8_t i;
	
	if(!dataBuff->configBottle.updateFlag)
		return FALSE;
	
	for(i = 0; i < 6; i++)
	{
		if(dataBuff->configBottle.PSN[i] != 0)
			return TRUE;
	}
	
	return FALSE;
}
