/****************************************************************************************
*File Name : framereceive.c
*Copyright : TaianSUCCEED Company
*CPU : SST/SILICON
*RTOS : none
*Create Data : 2009/12/17
*Author : 郗富琦
*Abstract Description: 本文件实现信息帧的完整性和CRC校验,
* 按照不同的版本号实现
*****************************************************************************************/
#include "prototype.h"
#include "crc_16.h"
#include <string.h>
#include "communicationglobal.h"
#ifdef SUCCEEDPROTOCAL
#ifdef VERSION3
static Bool ReceiveFrameAsVersion3(UINT8 ucRecData, const UINT8 usCounter);
#endif
#ifdef VERSION2
static Bool ReceiveFrameAsVersion2(UINT8 ucRecData, const UINT16 usCounter, Frame_t * pstrReceFrame);
#endif
#ifdef VERSION1
static Bool ReceiveFrameAsVersion1(UINT8 ucRecData, const UINT16 usCounter, Frame_t * pstrReceFrame);
#endif
#ifdef VERSION0
static Bool ReceiveFrameAsVersion0(UINT8 ucRecData, const UINT16 usCounter, Frame_t * pstrReceFrame);
#endif
#endif
#ifdef JOHNFINLAYPROTOCAL
static Bool JohnFinlayProtocal(UINT8 ucRecData, const UINT8 usCounter);
#endif
/********************************************************************************************************************************
*函数名称: CheckFrameIntegrity
*函数参数: ucRecData: 接收到的字符
* aucReceivedData: 将接收到的有效数据存储于aucReceivedData数组中
* pucReceivedDataLength: 得到aucReceivedData实际存储数据量
*
*函数描述: 每收到一个字节,调用本函数一次, 调用该函数之前须关闭字符间隔定时器,
* 调用本函数后如果返回值为FALSE且g_bIsFrameStart为TRUE则打开字符间隔定时器.
* 倘若字符间隔定时器激活令g_bIsFrameStart = FALSE
* 如果用户打开WaitForACK定时器, 请调用函数后检测g_bIsFrameStart为TRUE后关闭WaitForACK定时器
*
* 本函数修改系统级全局变量g_bIsFrameStart
* 帧头不加入数组
*
*
*返回值: 0 -> 数据帧不完整
* 1 -> 数据帧完整;
* 2 -> 参数为空.
* 3 -> 超出数组存储空间
*
*函数作者: 郗富琦
*时 间: 2011.2.22
**********************************************************************************************************************************/
UINT8 CheckReceivedFrameIntegrity(UINT8 ucRecData, UINT8 aucReceivedData[], UINT8 * pucReceivedDataLength)
{
static UINT8 Version = 0;
if(NULL == pucReceivedDataLength || NULL == aucReceivedData)
return 2;
if(FALSE == g_bIsFrameStart)
{//帧结构未起始
if(0xFF == ucRecData)
{//发现帧头
* pucReceivedDataLength = 0;
g_bIsFrameStart = TRUE; //帧结构开始
}
return FALSE; //倘若发现帧头则表示帧结构不完整,倘若发现帧头则接收到的数据为干扰数据
}
//超出数组容纳空间
if(*pucReceivedDataLength >= RCV_SNDBUFFERLENGTH)
return 3;
//存储有效数据
aucReceivedData[* pucReceivedDataLength] = ucRecData;
//每收到字符,计数器加一
(*pucReceivedDataLength) ++;
if(1 == * pucReceivedDataLength)
{//版本号存储
Version = ucRecData;
return FALSE;
}
#ifdef SUCCEEDPROTOCAL //使用SUCCEED协议
if(Version >> 7)
{//SUCCEED协议
//版本号判断
switch(Version & 0X7F)
{
#ifdef VERSION0
case 0:
return ReceiveFrameAsVersion0(ucRecData, * pucReceivedDataLength, pstReceFrame);
break;
#endif
#ifdef VERSION1
case 1:
//return ReceiveFrameAsVersion1(ucRecData, * ucReceivedDataLength, pstReceFrame);
break;
#endif
#ifdef VERSION2
case 2:
//return ReceiveFrameAsVersion2(ucRecData, * ucReceivedDataLength, pstReceFrame);
break;
#endif
#ifdef VERSION3
case 3:
return ReceiveFrameAsVersion3(ucRecData, * pucReceivedDataLength);
#endif
default:
return FALSE;
}
}
#endif //使用SUCCEED协议
#ifdef SUCCEEDPROTOCAL
#ifdef JOHNFINLAYPROTOCAL
else
#endif
#endif
#ifdef JOHNFINLAYPROTOCAL
{//Johnfinally协议
return JohnFinlayProtocal(ucRecData, * pucReceivedDataLength);
}
#endif
return FALSE;
}
#ifdef JOHNFINLAYPROTOCAL
/********************************************************************************
*函数名称: JohnFinlayProtocal
*函数参数: ucRecData: 接收到的字符
* usCounter: 接收到的字符计数器,不包括帧头
* pstrReceFrame: 将接收到的信息存入该结构体中
*
*函数描述: 与约翰芬雷在线系统合作的有线版协议实现
* 从帧头后的第二个字节开始调用本函数
*
*返回值: TRUE->校验数据帧完整;
* FALSE->错误或者不完整.
*
*函数作者: 郗富琦
*时 间: 2009.12.22
************************************************************************************/
static Bool JohnFinlayProtocal(UINT8 ucRecData, const UINT8 usCounter)
{
static UINT8 ucFrameLengthWillGet = 0; //实际要接收的帧字节长度,从接收的信息帧中获取
if(usCounter > 3)
{
--ucFrameLengthWillGet;
if (ucFrameLengthWillGet == 0)
{
g_bIsFrameStart = FALSE;
return TRUE;
}
}
else if(3 == usCounter)
{
ucFrameLengthWillGet = ucRecData + 2;
}
return FALSE;
}
#endif
#ifdef VERSION3
static Bool ReceiveFrameAsVersion3(UINT8 ucRecData, const UINT8 usCounter)
{
static UINT8 ucFrameLengthWillGet = 0; //实际要接收的帧字节长度,从接收的信息帧中获取
if(usCounter > 2)
{
--ucFrameLengthWillGet;
if (ucFrameLengthWillGet == 0)
{
g_bIsFrameStart = FALSE;
return TRUE;
}
}
else if(2 == usCounter)
{//帧字节长度
ucFrameLengthWillGet = ucRecData + 2;
}
return FALSE;
}
#endif
#ifdef VERSION1
/********************************************************************************
*函数名称: ReceiveFrameAsVersion1
*函数参数: ucRecData: 接收到的字符
* usCounter: 接收到的字符计数器,不包括帧头
* pstrReceFrame: 将接收到的信息存入该结构体中
*
*函数描述: SUCCEED协议第一版接收函数的实现
* 从帧头后的第二个字节开始调用本函数
*
*返回值: TRUE->校验数据帧完整;
* FALSE->错误或者不完整.
*
*函数作者: 郗富琦
*时 间: 2009.12.22
************************************************************************************/
static Bool ReceiveFrameAsVersion1(UINT8 ucRecData, const UINT16 usCounter, Frame_t * pstReceFrame)
{
if(pstReceFrame == NULL)
{
return FALSE;
}
//之所以先判断7是为了提高效率
if(usCounter > 7)
{
u_usFrameLengthWillGet--;
//数据帧/附加信息 + CRC
if(u_usFrameLengthWillGet > 1)
{//数据帧/附加信息写入存储
if(DataFrame == pstReceFrame->CtlFlag)
{//数据帧数据
//////////////////////////////////////////////////////////////////////////
//把ucRecData写入到Flash中
//////////////////////////////////////////////////////////////////////////
}
else
{//命令帧或应答帧附加信息
if((usCounter - 7) > ACCESSORYLENGTH)
{
g_bIsFrameStart = FALSE;
return FALSE;
}
pstReceFrame->Accessories[usCounter - 8] = ucRecData;
}
}
else if(0 == u_usFrameLengthWillGet)
{//CRCH
g_bIsFrameStart = FALSE;
return TRUE;
}
}
else if(2 == usCounter)
{
pstReceFrame->LengthOfData = ucRecData;
}
else if(3 == usCounter)
{
u_ustmp = ucRecData;
pstReceFrame->LengthOfData |= u_ustmp << 8;
u_usFrameLengthWillGet = pstReceFrame->LengthOfData + 2;
pstReceFrame->LengthOfData -= 4; //附加信息长度为(帧长-4)
}
else if(4 == usCounter)
{
pstReceFrame->CtlFlag = ucRecData & 3;
pstReceFrame->AddressType = (ucRecData >> 3) & 3;
pstReceFrame->IsSuccessful = (ucRecData >> 2) & 1;
u_usFrameLengthWillGet--;
}
else if (5 == usCounter)
{
pstReceFrame->ID = ucRecData;
u_usFrameLengthWillGet--;
}
else if (6 == usCounter)
{
pstReceFrame->EquipmentType = ucRecData & 0X1F;
pstReceFrame->ChannelNum = (ucRecData>>5) + 1;
u_usFrameLengthWillGet--;
}
else if (7 == usCounter)
{
pstReceFrame->Command = ucRecData;
u_usFrameLengthWillGet--;
}
return FALSE;
}
#endif
#ifdef VERSION0
/********************************************************************************
*函数名称: ReceiveFrameAsVersion0
*函数参数: ucRecData: 接收到的字符
* usCounter: 接收到的字符计数�
CP.rar_cp协议
版权申诉
114 浏览量
2022-09-19
18:44:24
上传
评论
收藏 16KB RAR 举报
四散
- 粉丝: 54
- 资源: 1万+
最新资源
- 计算机视觉(CV)open CV 人脸识别程序.docx
- python 端午节游戏,选择三个传统的端午节活动之一:包粽子、赛龙舟或挂艾草 根据玩家的选择,游戏会描述相应的情节,并在完成后
- C语言各版块实验题库、实验汇报以及实验教学案例资源
- 数据库连接(MySQL与VS2022)_vs2022 mysql-CSDN博客 (2024_6_1 19_11_34).html
- Flappy bird小游戏
- 数电实验五:555单稳态触发电路、555单稳态触发电路、555构成的施密特触发器
- MySQLTuner,一个用Perl编写的脚本,它允许你快速审查MySQL安装情况,并进行调整以提高性能和稳定性
- 冒泡排序 基础排序 插入排序 快速排序 双路快速排序 三路快速排序 堆排序.zip
- 数电实验四:加法计数器、减法计数器、加法器、建议数字钟、74LS192功能测试
- JSP基于网络超市商品销售管理系统的设计与实现(源代码+lw).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈