关闭

手机功耗分析:比对安捷伦电源数据

标签: 手机fileimportc
985人阅读 评论(0) 收藏 举报
分类:
import struct
binf=file("A new-3g-qq.bin","rb")
binf.seek(0x7c)
binf2=file("A OLD-3g-QQ.bin","rb")
fileheader=binf2.read(0x7c)
binf2.seek(0x7c)

checkpos=5
threhold=0.01

avergelen=5


def tocomb():
    binfc=file("comb.bin","wb+")
    binfc.write(fileheader)
    cnt=0
    rec=0
    v=0
    while 1:
            buf=binf.read(20)
            if len(buf)==20:
                dat=struct.unpack("fffii", buf)
                cnt+=1
                v+=dat[0]
                if cnt>=checkpos:
                    v = v/cnt
                    if rec<checkpos:
                        if v> threhold:
                            rec+=1
                        else:
                            rec=0
                        
                    if rec>=checkpos:
                        break
                    v=0
                    cnt=0
            else:
                break
            
    cnt=0
    rec=0
    v=0
    while 1:
            buf=binf2.read(20)
            if len(buf)==20:
                dat=struct.unpack("fffii", buf)
                cnt+=1
                v+=dat[0]
                if cnt>=checkpos:
                    v = v/cnt
                    if rec<checkpos:
                        if v> threhold:
                            rec+=1
                        else:
                            rec=0
                        
                    if rec>=checkpos:
                        break
                    v=0
                    cnt=0
            else:
                break
    val0=0
    val1=0
    delv=0
    totalcnt=0
    while 1:
            buf=binf.read(20)
            buf2=binf2.read(20)
            cnt+=1
            totalcnt=totalcnt+1.0
            if len(buf)==20 and len(buf2)==20:
                val0+=struct.unpack("f", buf[:4])[0]
                val1+=struct.unpack("f", buf2[:4])[0]
                if(cnt>=avergelen):
                    delv+=val0-val1                    
                    val0=val0/cnt
                    val1=val1/cnt
                    dat=struct.pack("fff", val0,val1,delv/totalcnt)
                    dat+='\0'*8
                    binfc.write(dat)
                    val0 = 0
                    val1 = 0
                    cnt = 0
            else:
                break            
    binfc.close()
    
def toaverage():
    cnt=0
    rec=0
    v=0
    while 1:
        buf=binf.read(20)
        if len(buf)==20:
            dat=struct.unpack("fffii", buf)
            cnt+=1
            v+=dat[0]
            if cnt>=10:
                v = v/cnt
                if rec<checkpos:
                    if v > threhold:
                        rec+=1
                    else:
                        rec=0
                    
                if rec>=checkpos:
                    print v
                v=0
                cnt=0
        else:
            break
tocomb()       

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:138926次
    • 积分:2793
    • 等级:
    • 排名:第12797名
    • 原创:142篇
    • 转载:0篇
    • 译文:0篇
    • 评论:47条
    文章分类
    最新评论