getNbrTableForZMAC.py
上传用户:joranyuan
上传日期:2022-06-23
资源大小:3306k
文件大小:3k
- import os, sys, string, time
- #resultPath = '.'
- resultPath = '/home/acwarrie/research/drandNbrTable'
- #os.chdir(resultPath)
- #first2 = True
- sinkAddr = sys.argv[1]
- for num in range(1, 31):
- os.chdir(resultPath + '/run' + str(num))
- print '---------------------------------------- run' + str(num)
- first2 = True
- outFile = open('nbrTable_'+ str(num) +'.nc', 'w')
- for file in os.listdir(resultPath + '/run' + str(num)):
- tok = string.split(file, '_')
- if tok[0] <> 'h':
- continue
- moteID = tok[1]
- isSome = False
- print 'Now looking into neighbors of ' + moteID
- fDat = open(file, 'r')
- for line in fDat.readlines():
- tok = string.split(line, ' ')
- if((string.strip(tok[0]) == 'MyInfo')):
- index = 2
- myID = string.strip(tok[index])
- if(myID == sinkAddr):
- myID = "0"
-
- mySLOT = string.strip(tok[index+2])
- myFRAME = string.strip(tok[index+4])
- if(myFRAME == '255'):
- continue
- if(myID <> '255'):
- if(first2):
- outFile.write('if(TOS_LOCAL_ADDRESS == ' + myID +') {n')
- first2 = False;
- else:
- outFile.write('else if(TOS_LOCAL_ADDRESS == ' + myID +') {n')
- outFile.write(' ownSlot = ' + mySLOT +';n')
- outFile.write(' localFrameLength = ' + myFRAME +';n')
- fDat.close()
- fDat = open(file, 'r')
- order = 0
- for line in fDat.readlines():
- tok = string.split(line, ' ')
- if(string.strip(tok[0]) == 'TwoHopNodeID(FRAME)'):
- index = 2
- isSome = True
- nbrID = string.strip(tok[index])
- if(nbrID == sinkAddr):
- nbrID = "0"
- nbrSLOT = string.strip(tok[index+2])
- nbrFRAME = string.strip(tok[index+4])
- if(nbrID <> '255'):
- outFile.write(' nbrInfo[' + str(order) + '].nodeID = ' + nbrID +';n')
- outFile.write(' nbrInfo[' + str(order) + '].bitMap = TWO_HOP;n')
- outFile.write(' nbrInfo[' + str(order) + '].frame = ' + nbrFRAME +';n')
- outFile.write(' nbrInfo[' + str(order) + '].slot = ' + nbrSLOT +';n')
- outFile.write(' Blacklist(nbrInfo[' + str(order) + '].slot, nbrInfo[' + str(order) + '].frame);n')
- order = order+1
- if(isSome):
- outFile.write('} n')
- fDat.close()
-