/******************************************************************************

                  版权所有 (C), 2013-2023, 科大智能电气有限公司

 ******************************************************************************
  文 件 名   : lib60870_public.c
  版 本 号   : V1.0
  生成日期   : 2022年04月07日
  最近修改   :
  功能描述   : 101及104规约实现中的任务管理及校验等功能
  函数列表   :
  修改历史   :
  1.日    期   : 2022年04月07日
    修改内容   : 创建文件
*******************************************************************************/
/*************************************文件包含*********************************/
#include "lib60870_public.h"

/***************************************数据定义*******************************/

/*************************************外部接口函数*****************************/
/**
 * @brief    规约发送任务调度
 * @param[in]  pstSelf-规约实体指针
 * @param[out] 无
 * @return     任务执行结果
 */
unsigned char CS10x_SendTask(CS10xHandle_t pstSelf)
{
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ReSend))  //重发标识
	{
		pstSelf->byTaskFlagId = TSKID_ReSend;
		return RESEND_TYPE;
	}

	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_Anomaly))  //异常帧
	{
		pstSelf->byTaskFlagId = TSKID_Anomaly;
		return LONG_TYPE;
	}

	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_Ack))  //回复应答帧
	{
		pstSelf->byTaskFlagId = TSKID_Ack;
		return SHORT_TYPE;
	}

	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_RequestLink))  // 101规约请求链路状态
	{
		pstSelf->byTaskFlagId = TSKID_RequestLink;
		return SHORT_TYPE;
	}

	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ResetLink))  // 101规约重置链路
	{
		pstSelf->byTaskFlagId = TSKID_ResetLink;
		return SHORT_TYPE;
	}

	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_MResponse))  // 101规约链路状态回复帧
	{
		pstSelf->byTaskFlagId = TSKID_MResponse;
		return SHORT_TYPE;
	}

	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_HeartBeat))  // 101规约心跳
	{
		pstSelf->byTaskFlagId = TSKID_HeartBeat;
		return SHORT_TYPE;
	}

	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_StartLink))  // 104规约启动链路
	{
		pstSelf->byTaskFlagId = TSKID_StartLink;
		return SHORT_TYPE;
	}

	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_StopLink))  // 104规约断开链路
	{
		pstSelf->byTaskFlagId = TSKID_StopLink;
		return SHORT_TYPE;
	}

	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_UTest))  // 104规约U帧TEST
	{
		pstSelf->byTaskFlagId = TSKID_UTest;
		return SHORT_TYPE;
	}

	/*规约不允许发送长帧，则直接返回*/
	if(CS104_TYPE_S == pstSelf->eCS10x_Type || CS104_TYPE_M == pstSelf->eCS10x_Type)
	{
		if(false == pstSelf->bContinueSendFlag)
		{
			return 0;
		}
	}
	else
	{
		if(pstSelf->uiResend_Tcn)
		{
			return 0;
		}
	}

	/*初始化完成*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_InitFinish))
	{
		pstSelf->byTaskFlagId = TSKID_InitFinish;
		return LONG_TYPE;
	}

	/*遥控命令报文*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_YkProcess))
	{
		pstSelf->byTaskFlagId = TSKID_YkProcess;
		return LONG_TYPE;
	}

	/*COS信息*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_SendCOS))
	{
		pstSelf->byTaskFlagId = TSKID_SendCOS;
		return LONG_TYPE;
	}

	/*事件顺序记录 SOE*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_SendSOE))
	{
		pstSelf->byTaskFlagId = TSKID_SendSOE;
		return LONG_TYPE;
	}

	/* 总招遥信响应遥信 */
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_SummonYx))
	{
		pstSelf->byTaskFlagId = TSKID_SummonYx;
		return LONG_TYPE;
	}

	/* 总招遥测响应遥测 */
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_SummonYc))
	{
		pstSelf->byTaskFlagId = TSKID_SummonYc;
		return LONG_TYPE;
	}

	/*总召响应*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_SummonResponse))
	{
		pstSelf->byTaskFlagId = TSKID_SummonResponse;
		return LONG_TYPE;
	}

	/* 故障事件 */
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_FaultSoe))
	{
		pstSelf->byTaskFlagId = TSKID_FaultSoe;
		return LONG_TYPE;
	}

	/*时钟同步报文*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_TimeSyn))
	{
		pstSelf->byTaskFlagId = TSKID_TimeSyn;
		return LONG_TYPE;
	}

	/*扰动数据*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_YcDisturb))
	{
		pstSelf->byTaskFlagId = TSKID_YcDisturb;
		return LONG_TYPE;
	}

	/*延时获得命令*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ObtainDelay))
	{
		pstSelf->byTaskFlagId = TSKID_ObtainDelay;
		return LONG_TYPE;
	}

	/*复位进程*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ResetProcess))
	{
		pstSelf->byTaskFlagId = TSKID_ResetProcess;
		return LONG_TYPE;
	}

	/*文件数据响应*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_FilePro))
	{
		pstSelf->byTaskFlagId = TSKID_FilePro;
		return LONG_TYPE;
	}

	/*电能量数据发送*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_DdData))
	{
		pstSelf->byTaskFlagId = TSKID_DdData;
		return LONG_TYPE;
	}

	/*总召电能量*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_DdSummon))
	{
		pstSelf->byTaskFlagId = TSKID_DdSummon;
		return LONG_TYPE;
	}

	/*总召电能量*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_DdTimeData))
	{
		pstSelf->byTaskFlagId = TSKID_DdTimeData;
		return LONG_TYPE;
	}

	/*修改参数定值区*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ChgConst))
	{
		pstSelf->byTaskFlagId = TSKID_ChgConst;
		return LONG_TYPE;
	}

	/*读取参数定值区*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ReadConst))
	{
		pstSelf->byTaskFlagId = TSKID_ReadConst;
		return LONG_TYPE;
	}

	/*读取定值参数*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ParamPreread))
	{
		pstSelf->byTaskFlagId = TSKID_ParamPreread;
		return LONG_TYPE;
	}

	/*读取定值参数-南网*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ParamRead_NanWang))
	{
		pstSelf->byTaskFlagId = TSKID_ParamRead_NanWang;
		return LONG_TYPE;
	}

	/*设置定值参数*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ParamPrewrite))
	{
		pstSelf->byTaskFlagId = TSKID_ParamPrewrite;
		return LONG_TYPE;
	}

	/*写参数定值-南网（类型标识 55）*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ParamWrite_NanWang))
	{
		pstSelf->byTaskFlagId = TSKID_ParamWrite_NanWang;
		return LONG_TYPE;
	}

	/*读定值参数响应传输-南网*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ParamReadResponse_NanWang))
	{
		pstSelf->byTaskFlagId = TSKID_ParamReadResponse_NanWang;
		return LONG_TYPE;
	}

	/*参数预置-南网*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ParamPreset_NanWang))
	{
		pstSelf->byTaskFlagId = TSKID_ParamPreset_NanWang;
		return LONG_TYPE;
	}

	/*固化定值参数-南网*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_ParamSolidify_NanWang))
	{
		pstSelf->byTaskFlagId = TSKID_ParamSolidify_NanWang;
		return LONG_TYPE;
	}

	/*启动升级*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_UpdateStart))
	{
		pstSelf->byTaskFlagId = TSKID_UpdateStart;
		return LONG_TYPE;
	}

	/*执行升级*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_UpdateExe))
	{
		pstSelf->byTaskFlagId = TSKID_UpdateExe;
		return LONG_TYPE;
	}

	/*长帧测试*/
	if(CheckClearTaskFlag(&pstSelf->stTaskFlags, TSKID_DataTest))
	{
		pstSelf->byTaskFlagId = TSKID_DataTest;
		return LONG_TYPE;
	}

	return 0;
}

/**
 * @brief    置规约发送任务接口函数
 * @param[in]  pstSelf-规约实体指针
 * @param[in]  uiFlagNo-任务ID
 * @param[in]  usParam_low-传递参数低2字节，一般是指cot  usParam_hig 传递参数高2字节 一般指报文尾部的限定词
 * @param[out] 无
 * @return     无
 */
void SetSendTask(CS10xHandle_t pstSelf, unsigned int uiFlagNo, unsigned short usParam_low, unsigned short usParam_hig)
{
	SetTaskFlag(&pstSelf->stTaskFlags, uiFlagNo);
	pstSelf->uiaTaskParam[uiFlagNo] = usParam_hig;
	pstSelf->uiaTaskParam[uiFlagNo] = (pstSelf->uiaTaskParam[uiFlagNo] << 16) + usParam_low;
	return;
}

/***************************************************************
* @brief SetTaskFlag
        设置标志，将pFlags缓冲区内的第FlagNo个位置位成1
* @param[in] pstFlags 标志缓冲区首址
             uiFlagNo 标记号
* @return
***************************************************************/
void SetTaskFlag(VFLAGS *pstFlags, unsigned int uiFlagNo)
{
	unsigned int uiByteNo = 0; // FlagNo所处的字节号
	unsigned int uiBitNo  = 0;  // FlagNo在字节内所处的位号

	if(uiFlagNo >= MAX_FLAGNO)  //越界
	{
		return;
	}

	uiByteNo = uiFlagNo >> 3;
	uiBitNo = uiFlagNo & 0x7;
	pstFlags->ucFlag[uiByteNo] |= (1 << uiBitNo);
}

/***************************************************************
* @brief GetTaskFlag
        获取pFlags缓冲区内的第FlagNo个位置的状态位
* @param[in] pstFlags 标志缓冲区首址
             uiFlagNo 标记号
* @return    标志状态，1 有效，0 无效
***************************************************************/
unsigned int GetTaskFlag(VFLAGS *pstFlags, unsigned int uiFlagNo)
{
	// 设置每个模块的标志
	unsigned int uiByteNo = 0;              // FlagNo所处的字节号
	unsigned int uiBitNo  = 0;              // FlagNo在字节内所处的位号
	unsigned char *pucFlag  = (unsigned char *)pstFlags; //
	uiByteNo = uiFlagNo >> 3; //第5到8位
	uiBitNo  = uiFlagNo & 7;   //取低三位
	return (pucFlag[uiByteNo] & (1 << uiBitNo));
}

/***************************************************************
* @brief ClearTaskFlag
        清除标志，将pFlags缓冲区内的第FlagNo个位置位成0
* @param[in]  pstFlags 标志缓冲区首址
              uiFlagNo 标记号
* @return
***************************************************************/
void ClearTaskFlag(VFLAGS *pstFlags, unsigned int uiFlagNo)
{
	unsigned int uiByteNo = 0;
	unsigned int uiBitNo  = 0;

	if(uiFlagNo >= MAX_FLAGNO)
	{
		return;
	}

	uiByteNo = uiFlagNo >> 3;
	uiBitNo = uiFlagNo & 0x7;
	pstFlags->ucFlag[uiByteNo] &= ~(1 << uiBitNo);

	// pstFlags->ucFlag[uiFlagNo] = 0;
}

/***************************************************************
* @brief CheckClearTaskFlag
        检查清除任务标志，若任务标志第dwFlagNo位有效，将其清除
        然后返回1,否则返回0
* @param[in] pstFlags  标志缓冲区首址
*            uiFlagNo  标记号
* @return    1      任务标志第uiFlagNo位有效
             0     任务标志第uiFlagNo位无效
***************************************************************/
int CheckClearTaskFlag(VFLAGS *pstFlags, unsigned int uiFlagNo)
{
	if(!GetTaskFlag(pstFlags, uiFlagNo))
	{
		return 0;
	}

	ClearTaskFlag(pstFlags, uiFlagNo);
	return 1;
}

/**
 * @brief     清除所有任务接口
 * @param[in]  pstSelf
 * @param[out]    无
 * @return     无
 */
void ClearAllTaskflgs(CS10xHandle_t pstSelf)
{
	pstSelf->stRecvBuf.usWritePtr = 0;
	pstSelf->stRecvBuf.usReadPtr = 0;
	pstSelf->stSendBuf.usWritePtr = 0;
	pstSelf->stSendBuf.usReadPtr = 0;
	memset(&pstSelf->stTaskFlags, 0, sizeof(VFLAGS));                      //任务
	memset(pstSelf->uiaTaskParam, 0, MAX_FLAGNO * sizeof(unsigned short)); //任务参数
	pstSelf->byTaskFlagId = 0;
	pstSelf->ucInitStatus = 0; // 初始化完成状态
	pstSelf->ucFirstAct = 0;
	pstSelf->uiFrameTmCnt = 0;
	pstSelf->uiHeart_Tcn = 0;
	pstSelf->uiSummon_Tcn = 0;
	pstSelf->uiESummon_Tcn = 0;
	pstSelf->uiTimeSyn_Tcn = 0;
	pstSelf->usYxSendNum          = 0;
	pstSelf->usYcSendNum          = 0;
	pstSelf->usDisTurbYcSendNum   = 0;
	pstSelf->usDdSendNum          = 0;
	pstSelf->usSoeSendNum         = 0;
	pstSelf->usSoeSendNoAckNum    = 0;     /*Soe发送未确认数量*/
	pstSelf->usCosSendNoAckNum    = 0;
	pstSelf->usEventSendNoAckNum  = 0;     /*事件发送未确认数量*/
	pstSelf->usDduSendNoAckNum  = 0;
	pstSelf->usDiturbYcSendNoAckNum  = 0;
	pstSelf->usSoeSendSetup  = 0;
	pstSelf->usDdSummonSetup  = 0;
	pstSelf->ucParamFlag  = 0;
	pstSelf->usParamSendNum  = 0;
	pstSelf->ucPmPresetFlag  = 0;
	pstSelf->uiPmPresetTimeout  = 0;
	pstSelf->ucTransStatus  = 0;
	pstSelf->uiTransTimerCur  = 0;
	pstSelf->uiTransTimerMax  = 0;
	pstSelf->bContinueSendFlag  = 0;
	pstSelf->ucInitStep  = 0;
	pstSelf->ucSelf_FCB  = 0;
	pstSelf->ucRxAckFlag  = 0;
	pstSelf->ucRxLinkStatusFlag  = 0;
	pstSelf->ucRxLinkRequestFlag  = 0;
	pstSelf->ucRxLinkResetFlag  = 0;
	pstSelf->ucRxInitFinishFlag  = 0;
	pstSelf->ucHeart_Resend_Flag  = 0;
	pstSelf->ucFileTransFrame  = 0;
	pstSelf->usFileNoneAckNum  = 0;
	pstSelf->usResend_Ncn  = 0;
	pstSelf->uiResend_Tcn  = 0;
	pstSelf->uiRelink_Tcn  = 0;
	pstSelf->uiInit_Tcn  = 0;
	pstSelf->uiReInit_Tcn  = 0;
	pstSelf->uiInit_Resend_Ncn  = 0;
	pstSelf->usSendNum         = 0;    /*Send Counter  */
	pstSelf->usRecvNum         = 0;    /*Receive Counter*/
	pstSelf->usAckSendNum      = 0; /*Receive Ack Counter*/
	pstSelf->usAckRecvNum      = 0; /*Have Ack Receive Counter*/
	pstSelf->stM_vTimer[0].bRun  = 0;
	pstSelf->stM_vTimer[1].bRun  = 0;
	pstSelf->stM_vTimer[2].bRun  = 0;
	pstSelf->stM_vTimer[3].bRun  = 0;
}

/**
 * @brief    8位校验和计算函数
 * @param[in]  pucBuf-数据指针
 * @param[in]  ucLen-数据长度
 * @param[out] 无
 * @return     校验和
 */
unsigned char checksum_8(unsigned char *pucBuf, unsigned char ucLen)
{
	unsigned char ucSum = 0;
	unsigned char uci   = 0;

	for(uci = 0; uci < ucLen; uci++)
	{
		ucSum += pucBuf[uci];
	}

	ucSum = ucSum & 0xff;
	return ucSum;
}

/**
 * @brief Check比对Tag类型与长度关系
 *
 * @param ucTag
 * @param ucLen
 * @return int
 */
int CheckParamTagAndLen(unsigned char ucTag, unsigned char ucLen)
{
	bool bResult = true;

	switch(ucTag)
	{
		case TAG_TPYE_BOOL:
		case TAG_TPYE_TINY:
		case TAG_TPYE_UTINY:
			if(ucLen != 1)
			{
				bResult = false;
			}

			break;

		case TAG_TPYE_SHORT:
		case TAG_TPYE_USHORT:
			if(ucLen != 2)
			{
				bResult = false;
			}

			break;

		case TAG_TPYE_INT:
		case TAG_TPYE_UINT:
		case TAG_TPYE_FLOAT:
			if(ucLen != 4)
			{
				bResult = false;
			}

			break;

		case TAG_TPYE_LONG:
		case TAG_TPYE_ULONG:
		case TAG_TPYE_DOUBLE:
			if(ucLen != 8)
			{
				bResult = false;
			}

			break;

		case TAG_TPYE_STR:
			if(ucLen > 64)
			{
				bResult = false;
			}

			break;

		default:
			bResult = false;
			break;
	}

	return bResult;
}

/*
 *  Prototype      : CP56Time2a_Pack2Buf
 *  Description    : 打包Cp56时间到缓冲
 *  @param[in]     : unsigned char *pucOutBuf
 *  @param[in]     : const __CP56Time2a *pstCp56
 *  @param[out]    : None
 *  @Return        :
 *
 *
 *
 *  History        :
 *  1.Date         : 2023/6/6
 *    Author       : wqw
 *    Modification : Created function
 *
 */
unsigned char CP56Time2a_Pack2Buf(unsigned char *pucOutBuf, const __CP56Time2a *pstCp56)
{
	if(NULL == pstCp56)
	{
		memset(pucOutBuf, 0, 7);
	}
	else
	{
		pucOutBuf[0] = pstCp56->ucLMs;
		pucOutBuf[1] = pstCp56->ucHMs;
		pucOutBuf[2] = pstCp56->ucMin;
		pucOutBuf[3] = pstCp56->ucHour;
		pucOutBuf[4] = pstCp56->ucWeek;
		pucOutBuf[5] = pstCp56->ucMonth;
		pucOutBuf[6] = pstCp56->ucYear;
	}

	return 7;
}

/*
 *  Prototype      : CP56Time2a_GetFromBuf
 *  Description    : 从缓冲解析Cp56时间
 *  @param[in]     : const unsigned char *pucInBuf
 *  @param[in]     : __CP56Time2a *pstCp56
 *  @param[out]    : None
 *  @Return        : 0=失败 1=成功
 *
 *
 *
 *  History        :
 *  1.Date         : 2023/6/6
 *    Author       : wqw
 *    Modification : Created function
 *
 */
unsigned char CP56Time2a_GetFromBuf(const unsigned char *pucInBuf, __CP56Time2a *pstCp56)
{
	if(NULL == pstCp56)
	{
		return 0;
	}

	pstCp56->ucLMs = pucInBuf[0];
	pstCp56->ucHMs = pucInBuf[1];
	pstCp56->ucMin = pucInBuf[2];
	pstCp56->ucHour = pucInBuf[3];
	pstCp56->ucWeek = pucInBuf[4];
	pstCp56->ucMonth = pucInBuf[5];
	pstCp56->ucYear = pucInBuf[6];
	return 1;
}

/*
 *  Prototype      : IntBytes_Pack2Buf
 *  Description    : 按字节数打包Int数据
 *  @param[in]     : unsigned char *pucOutBuf
 *  @param[in]     : unsigned int uiVal
 *  @param[in]     : unsigned char ucSize
 *  @param[out]    : None
 *  @Return        : 封装字节数量
 *
 *
 *
 *  History        :
 *  1.Date         : 2023/6/6
 *    Author       : wqw
 *    Modification : Created function
 *
 */
unsigned char IntBytes_Pack2Buf(unsigned char *pucOutBuf, unsigned int uiVal, unsigned char ucSize)
{
	if(0 == ucSize || ucSize > 4)
	{
		return 0;
	}

	for(unsigned char i = 0; i < ucSize; i++)
	{
		pucOutBuf[i] = uiVal;
		uiVal >>= 8;
	}

	return ucSize;
}

/*
 *  Prototype      : IntBytes_GetFromBuf
 *  Description    : 按照字节大小从缓冲中获取Int数据
 *  @param[in]     : const unsigned char *pucInBuf
 *  @param[in]     : unsigned char ucSize
 *  @param[out]    : None
 *  @Return        :
 *
 *
 *
 *  History        :
 *  1.Date         : 2023/6/6
 *    Author       : wqw
 *    Modification : Created function
 *
 */
unsigned int IntBytes_GetFromBuf(const unsigned char *pucInBuf, unsigned char ucSize)
{
	unsigned int uiVal = 0;

	if(0 == ucSize || ucSize > 4)
	{
		return 0;
	}

	for(unsigned char i = 0; i < ucSize; i++)
	{
		uiVal |= ((unsigned int)pucInBuf[i] << (i * 8));
	}

	return uiVal;
}

/*
 *  Prototype      : Float_Pack2Buf
 *  Description    : 打包浮点数到缓冲
 *  @param[in]     : unsigned char *pucOutBuf
 *  @param[in]     : float fVal
 *  @param[out]    : None
 *  @Return        :
 *
 *
 *
 *  History        :
 *  1.Date         : 2023/6/12
 *    Author       : wqw
 *    Modification : Created function
 *
 */
unsigned char Float_Pack2Buf(unsigned char *pucOutBuf, float fVal)
{
	memcpy(pucOutBuf, &fVal, 4);
	return 4;
}

/*
 *  Prototype      : Float_GetFromBuf
 *  Description    : 缓冲获取浮点数
 *  @param[in]     : const unsigned char *pucInBuf
 *  @param[out]    : None
 *  @Return        :
 *
 *
 *
 *  History        :
 *  1.Date         : 2023/6/12
 *    Author       : wqw
 *    Modification : Created function
 *
 */
float Float_GetFromBuf(const unsigned char *pucInBuf)
{
	float fVal = 0;
	memcpy(&fVal, pucInBuf, 4);
	return fVal;
}

/*
 *  Prototype      : U16_Pack2Buf
 *  Description    : 打包无符号短整型到缓冲
 *  @param[in]     : unsigned char *pucOutBuf
 *  @param[in]     : unsigned short usVal
 *  @param[out]    : None
 *  @Return        :
 *
 *
 *
 *  History        :
 *  1.Date         : 2023/6/12
 *    Author       : wqw
 *    Modification : Created function
 *
 */
unsigned char U16_Pack2Buf(unsigned char *pucOutBuf, unsigned short usVal)
{
	memcpy(pucOutBuf, &usVal, 2);
	return 2;
}

/*
 *  Prototype      : U16_GetFromBuf
 *  Description    : 从缓冲获取无符号短整型
 *  @param[in]     : const unsigned char *pucInBuf
 *  @param[out]    : None
 *  @Return        :
 *
 *
 *
 *  History        :
 *  1.Date         : 2023/6/12
 *    Author       : wqw
 *    Modification : Created function
 *
 */
unsigned short U16_GetFromBuf(const unsigned char *pucInBuf)
{
	unsigned short usVal = 0;
	memcpy(&usVal, pucInBuf, 2);
	return usVal;
}



/***************************************内部函数*******************************/
