zoukankan      html  css  js  c++  java
  • 使用python进行传输层的帧的类型判断

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

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

    使用字符串的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
     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' + '
    ' #add '
    ' is correct.
                elif list1[1][0] == '1':
                    print(str(i)+' first frame')
                    text_line = text_line[:-2]+ ' FF' + '
    ' #add '
    ' is correct.
                elif list1[1][0] == '2':
                    print(str(i)+' consecutive frame')
                    text_line = text_line[:-2]+ ' CF' + '
    ' #add '
    ' is correct.'
                elif list1[1][0] == '3':
                    print(str(i)+' FlowControl')
                    text_line = text_line[:-2]+ ' FC' + '
    ' #add '
    ' is correct.
                else:
                    print(str(i)+' error!')
                i= i+1
                
                fd1_new.write(text_line)
            else:
                break
    finally:
        fd1.close()
        fd1_new.close()
        
  • 相关阅读:
    (第二周)效能测试
    (第二周)新小学四则运算
    (第二周)项目点评
    (第二周)通读《构建之法》有感
    (第二周)scrum站立会议
    (第二周) 燃尽图
    (第一周)工作总结
    (第一周)小学四则运算
    软件工程第三次作业
    软件工程第二次作业
  • 原文地址:https://www.cnblogs.com/praiseslow/p/13255864.html
Copyright © 2011-2022 走看看