C++代码审阅--ice104协议从站(2)

代码理解

IEC104NASlave.h主应用程序头文件
接上篇,中文注释即理解,已在前篇注释过的理解不再重新注释,有需要请翻看前面篇章。
C++代码审阅–ice104协议从站(1)

// IEC104NASlave.h : main header file for the IEC104NASLAVE application 
//IEC104NASLAVE应用程序的主头文件

#if !defined(AFX_IEC104NASLAVE_H__3727DC37_9D6F_4120_B349_19C8571514A5__INCLUDED_)
#define AFX_IEC104NASLAVE_H__3727DC37_9D6F_4120_B349_19C8571514A5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"		// main symbols
#if !defined(_AFXDLL)
#define _AFXDLL
#endif //!defined(_AFXDLL)

/
// CIEC104NASlaveApp:
// See IEC104NASlave.cpp for the implementation of this class
//
class CIEC104NASlaveApp : public CWinApp //定义基类CIEC104NASlaveApp,派生类CWinApp,继承公有成员
{
public:
	CIEC104NASlaveApp(); //这就是公有成员,成员有public(公有成员),private(私有成员),prctected(受保护成员)三种,默认private。

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CIEC104NASlaveApp)
	public:
	virtual BOOL InitInstance();//这也是公有成员,允许有多个public,编译效果是一样的,virtual定义一个布尔类型的虚函数(理解跟多态有关,先不管)
	//}}AFX_VIRTUAL

// Implementation

	//{{AFX_MSG(CIEC104NASlaveApp)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP() 
	/*
	DECLARE_MESSAGE_MAP()宏作用是向类中添加消息映射必要的结构体和函数声明,
	在实现了类函数.cpp文件中加入BEGIN_MESSAGE_MAP,再加入每个消息处理函数的宏入口,在用END_MESSAGE_MAP结束
	*/
};


/

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_IEC104NASLAVE_H__3727DC37_9D6F_4120_B349_19C8571514A5__INCLUDED_)

文件含义

IEC104NASLAVE应用程序的主头文件,定义了一个CIEC104NASlaveApp基类和 CWinApp派生类
该类有两个共有成员,一个是CIEC104NASlaveApp()以及InitInstance(),最后声明了一个DECLARE_MESSAGE_MAP()宏。

涉及基础知识

1.include和define:https://blog.csdn.net/helenchen1995/article/details/100031072
2.头文件和源文件C++中的 .h 和 .cpp 详解
3.条件编译https://blog.csdn.net/qq_36662437/article/details/81476572
4.类和对象https://www.runoob.com/cplusplus/cpp-classes-objects.html
5.类和对象访问修饰符https://www.runoob.com/cplusplus/cpp-class-access-modifiers.html
6.注释https://www.runoob.com/cplusplus/cpp-comments.html
7.宏定义https://blog.csdn.net/u012308586/article/details/90407932
8.MFChttps://baike.baidu.com/item/MFC/2530850?fr=aladdin
9.继承https://www.runoob.com/cplusplus/cpp-inheritance.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
# IEC104 Protocol of IEC104 and IEC101 ## by chendajie 2014-2015 ## 电网IEC104/IEC101通信协议 ============================== 隔离协议内容与平台或者硬件相关性,已经在stm32平台和linux平台移植测试通过,可轻松移植到其他平台。 ============================================================================ 队列实现的隔离,目前实现简单的先入先出队列,可根据需求用其他队列算法替换。 移植调用实现: 1.在不同平台下,实现_iec10x结构体的函数指针(利用函数指针实现的接口)。 2.调用RegisterIEC10XMoudle,注册实现的_iec10x接口。 3.创建线程一调用Iex104_Receive管理收包解析。 4.创建线程二调用Iec10x_Scheduled实现出队调度。 5.创建线程三实现状态机Iec104_StateMachine,实现协议状态管理,协议包组包入队。 代码内容 IEC0x目录 iec101.c iec101协议包内容 iec104.c iec104协议包内容 iec10x.c 队列初始化,入队出对实现,队列优先级等相关实现,队列调度实现 PRIO_QUEUE_Iec10x.c 队列具体算法实现 test目录 linux上简单测试代码,仅供参考,作者具体协议应用在stm32上,利用状态机控制数据包入队与出队调度 重要函数: Iec10x_Scheduled:出队调度 IEC10X_Enqueue:入队函数 IEC10X_Dequeue:出队函数 IEC10X_FindQHead:查找最高优先级数据包 IEC10X_XXX:前缀为IEC10X_的函数为各个协议包的组包函数 Iec104_StateMachine: 104协议状态机 Iex104_Receive:收包解析 RegisterIEC10XMoudle:协议模块注册,初始化 重要结构体: 用函数指针实现的移植接口,根据不同平台与硬件特性,选择性实现以下接口 typedef struct _iec10x { char * name; int (* Init)(void); void (* Delay_ms)(uint16_t); void (* CloseLink)(void); void *(* Malloc)(uint8_t NumByte); void (* Free)(void *buffer); uint8_t (* enqueue)(Iec10x_PrioQueue_T *QueueHdr, Iec10x_PrioNode_T *NewNode); Iec10x_PrioNode_T *(* dequeue)(Iec10x_PrioQueue_T * QueueHdr); Iec10x_PrioNode_T *(* FindQHead)(Iec10x_PrioQueue_T * QueueHdr); char (* GetPrio)(void); void (* InitQueue)(Iec10x_PrioQueue_T *PrioQueue); void (* ClearQueue)(Iec10x_PrioQueue_T * QueueHdr); uint8_t (* Send)(int socketfd,char *data,int len); uint32_t (* SetTime)(PCP56Time2a_T time); uint32_t (* GetTime)(PCP56Time2a_T time); int8_t (* GetStationState)(uint16_t Addr, uint8_t DevType); float (* GetStaValue)(uint16_t Addr, uint8_t DevType); uint16_t (* GetLinkAddr)(void); int8_t (* GetInfoNum)(uint8_t *InfoNum, uint8_t DevType); int8_t (* SetConfig)(long Value, uint32_t addr); int8_t (* SaveFirmware)(uint8_t FirmLen, uint8_t *buf,uint32_t FirmwareType, uint32_t Iec10x_Update_SeekAddr); int8_t (* CheckFirmware)(uint32_t FirmwareType, uint32_t TotalLen); int8_t (* UpdateFirmware)(uint32_t FirmwareType); int8_t (* BackoffFirmware)(uint32_t FirmwareType); #ifdef IEC10XLOCK void (* LOCK)(void); void (* UNLOCK)(void); #endif } *PIEC10X_T, IEC10X_T;

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值