资源描述
帧格式以下:
功效号
[FD]
数据长度
[LB]
数据1
[DS]
… 数据n
[DS]
校验和
[CS]
其中LB、 DS在命令帧和应答帧中无。
差错控制与校验采取纵向冗余校验(LRC)。
发送方校验和生成方法:
将FD、 LB、 DS域逐一字节相加求和, 在求和过程中舍弃进位, 最终将所得和(单个字节)取补码作为检验和(CS)。
生成校验和函数为:
static unsigned char LRC(auchMsg, usDataLen) /* 函数返回 unsigned char 类型 LRC 结果*/
unsigned char *auchMsg ; /* 要计算 LRC 报文*/
unsigned short usDataLen ; /* 报文字节数 */
{
unsigned char uchLRC = 0 ; /* LRC 初始化 */
while (usDataLen--) /* 完成整个报文缓冲区 */
uchLRC += *auchMsg++ ; /* 缓冲区字节相加, 无进位 */
return ((unsigned char)(-((char)uchLRC))) ; /* 返回二进制补码 */
}
接收方校验方法:
将全部接收到数据, 即FD、 LB、 DS、 CS等域逐一字节相加求和, 在求和过程中舍弃进位, 若结果为零(低字节)则传输无错, 不然犯错。
应答:
接收方对接收数据进行校验后, 若无错则向发送方发送传输无错应答帧, 若有错则向发送方发送传输犯错应答帧。
所需通信数据分为: 数据帧、 命令帧、 应答帧
上行数据: 下位机(单片机)向上位机(PC机)传送数据
⑴ 初始化上位机(IPC): FD=0x01 (InitPC)
单片机将电梯模拟器参数发送至PC机, 初始化PC机端可视化程序。PC机上可视化程序完成初始化后, 应向单片机发送初始化完成命令。
帧格式:
功效号
IPC
数据长度
[LB]
数据
[DS]
校验和
[CS]
其中数据域格式以下:
参数号1
参数1
……
参数号n
参数n
⑵ 发送模拟器状态信息: FD=0x02 (SendMsgToPC)
包含: 轿厢位置, 轿厢状态——上行/下行/停止, 轿厢运行速度
帧格式:
功效号
[FD]
数据长度
[LB]
轿厢位置
低字节
轿厢位置
高字节
轿厢状态
轿厢行速
校验和
[CS]
其中轿厢状态:
上行——0x05
下行——0x0A
停止——0x00
⑶开门命令: FD=0x03
帧格式:
功效号
[FD]
校验和
[CS]
⑷开门到位命令: FD=0x04
帧格式:
功效号
[FD]
校验和
[CS]
⑸关门命令: FD=0x05
帧格式:
功效号
[FD]
校验和
[CS]
⑹关门到位命令: FD=0x06
帧格式:
功效号
[FD]
校验和
[CS]
⑺问询上位机是否准备好: FD=0x07 (IfPCReady)
帧格式:
功效号
[FD]
校验和
[CS]
下行数据: 上位机(PC机)向下位机(单片机)传送数据
⑴上位机准备好: FD=0x11
帧格式:
功效号
[FD]
校验和
[CS]
⑵初始化完成: FD=0x12 (PCInitFinish)
帧格式:
功效号
[FD]
校验和
[CS]
⑶修改模拟器参数: FD=0x13 (AlterPara)
帧格式:
功效号
[FD]
校验和
[CS]
⑷完成修改模拟器参数: FD=0x14 (FinishAlterPara)
帧格式:
功效号
[FD]
校验和
[CS]
⑸下送模拟器参数: FD=0x15 (SendParaToMCU)
帧格式:
功效号
[FD]
数据长度
[LB]
数据
[DS]
校验和
[CS]
其中数据域格式以下:
参数号1
参数1
……
参数号n
参数n
应答帧:
⑴接收到数据无错: FD=0xF1
帧格式:
功效号
[FD]
校验和
[CS]
⑵接收到数据犯错: FD=0xF2
帧格式:
功效号
[FD]
校验和
[CS]
模拟器运行步骤图
修改模拟器参数步骤图
模拟器参数定义
//参数号定义
#define ID_Total_Floors 1
#define ID_Special_Floor_A 3
#define ID_Special_Floor_B 5
#define ID_ID_Observe_Para 7
#define ID_Dist_Bottom_Limit_Location 10
#define ID_Dist_Bottom_Restrict_Location 11
#define ID_Duration_Close_LiftDoor 16
#define ID_Duration_Open_LiftDoor 17
#define ID_Factor_FreqDivid_Hall 18
#define ID_Polarity_Photoswitch 19
#define ID_Floor_Lift_Lieto 29
#define ID_Location_Lift 30
#define ID_Length_UnivFloor 2
#define ID_Length_Special_Floor_A 4
#define ID_Length_Special_Floor_B 6
#define ID_Length_Floor_Level_Board 8
#define ID_Length_Speed_Alter_Board 9
#define ID_Dist_Bottom_SpAlter_UpEnd 12
#define ID_Dist_Top_SpAlter_LowEnd 13
#define ID_Dist_Top_Restrict_Location 14
#define ID_Dist_Top_Limit_Location 15
ubyte Total_Floors; //最高楼层数
ubyte Special_Floor_A; //专用楼层号A
ubyte Special_Floor_B; //专用楼层号B
ubyte ID_Observe_Para; //观察参数号
ubyte Dist_Bottom_Limit_Location; //下极限与底楼平层距离(向下计算), 单位: 厘米
ubyte Dist_Bottom_Restrict_Location; //下限位与底楼平层距离(向下计算), 单位: 厘米
ubyte Duration_Close_LiftDoor; //电梯关门到位时间, 单位: 秒
ubyte Duration_Open_LiftDoor; //电梯开门到位时间, 单位: 秒
ubyte Factor_FreqDivid_Hall; //输入霍尔脉冲分频系数
ubyte Polarity_Photoswitch; //平层区光电开关极性: 0 - 进入平层区光电开关输出断开, 1 - 进入平层区光电开关输出闭合
ubyte Floor_Lift_Lieto; //电梯目前楼层
uword Location_Lift; //电梯位置值, 单位: 厘米
uword Length_UnivFloor; //通用楼层距离, 单位: 厘米
uword Length_Special_Floor_A; //专用楼层号A楼层距离(向上计算), 单位: 厘米
uword Length_Special_Floor_B; //专用楼层号B楼层距离(向上计算), 单位: 厘米
uword Length_Floor_Level_Board; //平层挡板长度, 单位: 毫米
uword Length_Speed_Alter_Board; //上、 下强换挡板长度, 单位: 厘米
uword Dist_Bottom_SpAlter_UpEnd; //下强换顶端与底楼平层距离(向上计算), 单位: 厘米
uword Dist_Top_SpAlter_LowEnd; //上强换底端与顶楼平层距离(向下计算), 单位: 厘米
uword Dist_Top_Restrict_Location; //上限位与顶楼平层距离(向上计算), 单位: 厘米
uword Dist_Top_Limit_Location; //上极限与顶楼平层距离(向上计算), 单位: 厘米
展开阅读全文