Example #1
0
def test_cksum():
    # sanity check algorithm
    digest = crc16_ccitt(b"123456789")

    assert digest == 0x29B1

    filename = cdir + "/../data/demo_ab.sor"
    with open(filename, mode='rb') as fh:
        data = fh.read()

    assert len(data) == 25708

    if sys.version_info > (3, 0):
        # python 3
        file_chk = data[-1] * 256 + data[-2]
    else:
        # python 2
        file_chk = ord(data[-1]) * 256 + ord(data[-2])

    assert file_chk == 38827

    newdata = data[0:-2]

    # print "* trunc size is ",len(newdata)

    digest = crc16_ccitt(newdata)

    assert digest == file_chk

    devnull = open(os.devnull, "w")
    # test against module (SOR version 1)
    status, results, tracedata = pyOTDR.sorparse(filename,
                                                 debug=True,
                                                 logfile=devnull)
    # print(results)
    # print "* Our calcuated check sum: ",digest
    assert results['Cksum']['checksum_ours'] == digest

    # print("--------------- ok version 1 -----------------------")

    # SOR version 2
    filename = cdir + "/../data/sample1310_lowDR.sor"
    status, results, tracedata = pyOTDR.sorparse(filename,
                                                 debug=True,
                                                 logfile=devnull)
    # status, results, tracedata = pyOTDR.sorparse(filename, debug=True, logfile=sys.stderr)

    assert results['Cksum']['checksum_ours'] == 62998
    assert results['Cksum']['checksum'] == 59892

    # print("--------------- ok version 2 -----------------------")

    return
Example #2
0
def main():
    if len(sys.argv) < 2:
        print("USAGE: %s SOR_file [format]" % sys.argv[0])
        print("     : format: JSON (default) or XML")
        sys.exit()

    logging.basicConfig(format='%(message)s')
    # logging.basicConfig()

    filename = sys.argv[1]
    opformat = "JSON"
    if len(sys.argv) >= 3:
        opformat = "XML" if sys.argv[2] == "XML" else "JSON"

    status, results, tracedata = pyOTDR.sorparse(filename)

    # construct data file name to dump results
    fn_strip, ext = os.path.splitext(os.path.basename(filename))
    if opformat == "JSON":
        datafile = fn_strip + "-dump.json"
    else:
        datafile = fn_strip + "-dump.xml"

    with open(datafile, "w") as output:
        pyOTDR.tofile(results, output, format=opformat)

    # construct data file name
    fn_strip, ext = os.path.splitext(os.path.basename(filename))
    opfile = fn_strip + "-trace.dat"

    with open(opfile, "w") as output:
        for xy in tracedata:
            output.write(xy)
Example #3
0
 def _load_file(self, url, _project=False):
     '''Load the raw SOR file from provided url into the internal data format'''
     if not _project:
         _, d_meta, l_raw_trace = sorparse(url)
         d_meta["url"] = url
     else:
         d_meta = _project["meta"]
         l_raw_trace = _project["raw_trace"]
     self.files[url] = {"meta": d_meta, "raw_trace": l_raw_trace}
     a_trace = self.__preprocess_data(d_meta, l_raw_trace)
     d_data= prepare_data({"meta":d_meta, "trace":a_trace}, self.window_len)
     filename = os.path.basename(url)
     item = QtGui.QStandardItem(filename)
     item.data = d_data
     self.project_model.appendRow(item)
Example #4
0
def test_map():
    filename = cdir + "/../data/demo_ab.sor"
    fh = parts.sorfile(filename)
    assert fh != None
    fh.close()

    status, results, trace = pyOTDR.sorparse(filename)

    assert status == 'ok'

    # map block
    ref = results['blocks']
    assert ref['Cksum']['pos'] == 25706
    assert ref['Cksum']['version'] == "1.00"

    assert ref['DataPts']['pos'] == 328
    assert ref['DataPts']['size'] == 23564

    return
Example #5
0
def _compare_(sor_filename):
    
    filename = cdir+"/../data/"+sor_filename
    fh = parts.sorfile(filename)
    assert fh != None
    fh.close()
    
    devnull = open( os.devnull, "w")
    status, results, tracedata = pyOTDR.sorparse(filename, debug=True, logfile=devnull)
    
    assert status == 'ok'
    
    # load and compare JSON file
    fn_strip, ext = os.path.splitext( os.path.basename(filename) )
    datafile = fn_strip+"-dump.json"
    
    jsonfile = cdir+"/../data/"+datafile
    
    with open(jsonfile) as jsf:
        jold = dict( json.load(jsf, encoding=None) )
        
    jnew = json.dumps(results, sort_keys=True )
    jnew = json.loads(jnew)
    
    jold = ordered(jold)
    jnew = ordered(jnew)
    
    assert jold == jnew
    
    # load and compare trace data
    tfile = fn_strip+"-trace.dat"
    tfile = cdir+"/../data/"+tfile
    
    with open(tfile) as jsf:
        count = 0
        for line in jsf:
            assert line.strip('\n') == tracedata[count]
            count += 1
    
    return
Example #6
0
def main():
    if len(sys.argv) < 2:
        print("USAGE: %s SOR_file [format]" % sys.argv[0])
        print("     : format: JSON (default) or XML")
        sys.exit()

    filename = sys.argv[1]
    opformat = "JSON"
    if len(sys.argv) >= 3:
        opformat = "XML" if sys.argv[2] == "XML" else "JSON"

    logfile = sys.stdout

    status, results, tracedata = pyOTDR.sorparse(filename,
                                                 debug=True,
                                                 logfile=logfile)

    # construct data file name to dump results
    fn_strip, ext = os.path.splitext(os.path.basename(filename))
    if opformat == "JSON":
        datafile = fn_strip + "-dump.json"
    else:
        datafile = fn_strip + "-dump.xml"

    with open(datafile, "w") as output:
        pyOTDR.tofile(results, output, format=opformat)

    # construct data file name
    fn_strip, ext = os.path.splitext(os.path.basename(filename))
    opfile = fn_strip + "-trace.dat"

    with open(opfile, "w") as output:
        for xy in tracedata:
            print(xy, file=output)

    sys.exit()
Example #7
0
def ConvertSORtoTPL(filename=None):
    return pyOTDR.sorparse(filename)