首页 > 编程语言 > 详细

使用python进行传输层的帧的类型判断

时间:2020-07-06 17:31:49      阅读:52      评论:0      收藏:0      [点我收藏+]

以下是按照一定规则,判断传输层的帧的种类的。

打开文件,按照行读取文件,然后进行写文件,注意,写入的是另外一个新创建的文件,不是原文件,这样也避免了对原文件的破坏。

使用字符串的split方法对其进行了处理。

#use the basic file and string operation.
import re

#str1 = ‘19:45:40:9854 Rx 1 0x7E0 s 8 02 10 03 00 00 00 00 00\r\n fdfdfdfdf‘
fd1 = open(BUSMASTERLogFile_0.log, r)
fd1_new = open(BUSMASTERLogFile_0_new.log, w)
#str_list1 = fd1.readlines()
i = 0

try:
    while True:
        text_line = fd1.readline()
        if text_line:
            list1 = text_line.split( s 8 )
            if list1[1][0] == 0:
                print(str(i)+ single frame)
                text_line = text_line[:-2]+  SF + \n #add ‘\n‘ is correct.
            elif list1[1][0] == 1:
                print(str(i)+ first frame)
                text_line = text_line[:-2]+  FF + \n #add ‘\n‘ is correct.
            elif list1[1][0] == 2:
                print(str(i)+ consecutive frame)
                text_line = text_line[:-2]+  CF + \n #add ‘\n‘ is correct.‘
            elif list1[1][0] == 3:
                print(str(i)+ FlowControl)
                text_line = text_line[:-2]+  FC + \n #add ‘\n‘ is correct.
            else:
                print(str(i)+ error!)
            i= i+1
            
            fd1_new.write(text_line)
        else:
            break
finally:
    fd1.close()
    fd1_new.close()
    

 

使用python进行传输层的帧的类型判断

原文:https://www.cnblogs.com/praiseslow/p/13255864.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!