예제 #1
0
 def get_type_24 (self,
                  type,  # Can be B and aux. A and B should be tested aux was done just in case
                  msg24
                  ):
     
     if type == 'A':
         bits_a = ais_msg_24.encode(type = "A",
                                    params = msg24)
         nmea_a = uscg.create_nmea(bits_a,
                                   message_type = 24,
                                   aisChannel = "A")
         return nmea_a
     elif type == 'B':
         bits_b = ais_msg_24.encode(type = "B",
                                    params = msg24
                                    )
         nmea_b = uscg.create_nmea(bits_b,
                                   message_type = 24,
                                   aisChannel = "B")
         return nmea_b
     elif type == 'aux':
         bits_aux = ais_msg_24.encode(type = "aux",
                                      params = msg24)
         nmea_aux = uscg.create_nmea(bits_aux,
                                     message_type = 24,
                                     aisChannel = "B")
         return nmea_aux
예제 #2
0
 def get_type_1 (self,
                 msg01):
     
     bits = ais_msg_1.encode(msg01)
     nmea = uscg.create_nmea(bits,
                             message_type = 1)
     return nmea
예제 #3
0
 def get_type_5 (self,
                 msg05):
     
     bits = ais_msg_5.encode(msg05)
     nmea = list(uscg.create_nmea(bits,
                                  message_type = 5))
     
     return nmea
예제 #4
0
def test_this ():
    '''
    msgDict = {
        'MessageID': '1',
        'RepeatIndicator': options.RepeatIndicatorField,
        'UserID': options.UserIDField,
        'NavigationStatus': options.NavigationStatusField,
        'ROT': options.ROTField,
        'SOG': options.SOGField,
        'PositionAccuracy': options.PositionAccuracyField,
        'longitude': options.longitudeField,
        'latitude': options.latitudeField,
        'COG': options.COGField,
        'TrueHeading': options.TrueHeadingField,
        'TimeStamp': options.TimeStampField,
        'RegionalReserved': '0',
        'Spare': '0',
        'RAIM': options.RAIMField,
        'state_syncstate': options.state_syncstateField,
        'state_slottimeout': options.state_slottimeoutField,
        'state_slotoffset': options.state_slotoffsetField,
    }
    '''
    msg01 = {}
    msg01['MessageID'] = 1
    msg01['RepeatIndicator'] = 1
    msg01['MMSI'] = 1193046
    msg01['NavigationStatus'] = 3
    msg01['ROT'] = -2
    msg01['SOG'] = Decimal('101.9')
    msg01['PositionAccuracy'] = 1
    msg01['longitude'] = Decimal('-122.16328055555556')
    msg01['latitude'] = Decimal('37.424458333333334')
    msg01['COG'] = Decimal('34.5')
    msg01['TrueHeading'] = 41
    msg01['TimeStamp'] = 35
    msg01['RegionalReserved'] = 0
    msg01['Spare'] = 0
    msg01['RAIM'] = False
    # This is SOTDMA communication state fields
    # 19 bites long in type 18
    # 1 field comes before for communication state
    # type choice
    msg01['state_syncstate'] = 2
    msg01['state_slottimeout'] = 0
    msg01['state_slotoffset'] = 1221
    
    bits = encode(msg01)
    nmea = uscg.create_nmea(bits,
                            message_type = 1)
    return
예제 #5
0
def test_this():
    msg18 = {}
    msg18['MessageID'] = 18
    msg18['RepeatIndicator'] = 1
    msg18['MMSI'] = 1193046
    msg18['Reserved1'] = 0
    msg18['SOG'] = Decimal('101.9')
    msg18['PositionAccuracy'] = 1
    msg18['longitude'] = Decimal('-122.16328055555556')
    msg18['latitude'] = Decimal('37.424458333333334')
    msg18['COG'] = Decimal('34.5')
    msg18['TrueHeading'] = 41
    msg18['TimeStamp'] = 35
    msg18['Spare'] = 0
    msg18['cs_unit'] = False
    msg18['display_flag'] = False
    msg18['dsc_flag'] = False
    msg18['band_flag'] = False
    msg18['msg22_flag'] = False
    msg18['mode_flag'] = False
    msg18['RAIM'] = False
    # CommStateSelector 0 = SOTDMA
    ##CommStateSelector 1 = ITDMA
    msg18['CommStateSelector'] = 0
    # This state is ought to be filled
    # in full according tospecs
    #
    # This field can be SOTDMA or ITDMA communication state
    # 20 bites long
    # msg18['CommState'] = 0
    # What follows is SOTDMA communication state
    msg18['state_syncstate'] = 2
    msg18['state_slottimeout'] = 0
    msg18['state_slotoffset'] = 1221

    bits = encode(msg18)
    nmea = uscg.create_nmea(bits, message_type=18)
    return
예제 #6
0
def test_author ():
    from optparse import OptionParser
    
    parser = OptionParser(usage = "%prog [options]")
    
    parser.add_option('--unit-test', dest = 'unittest', default = False, action = 'store_true',
                      help = 'run the unit tests')
    parser.add_option('-v', '--verbose', dest = 'verbose', default = False, action = 'store_true',
                      help = 'Make the test output verbose')
    
    # FIX: remove nmea from binary messages.  No way to build the whole packet?
    # FIX: or build the surrounding msg 8 for a broadcast?
    typeChoices = ('aisbinary', 'nmeapayload', 'nmea')  # FIX: what about a USCG type message?
    parser.add_option('-t', '--type', choices = typeChoices, type = 'choice',
                      dest = 'ioType', default = 'nmeapayload',
                      help = 'What kind of string to write for encoding (' + ', '.join(
                          typeChoices) + ') [default: %default]')
    
    outputChoices = ('std', 'html', 'csv', 'sql', 'kml', 'kml-full')
    parser.add_option('-T', '--output-type', choices = outputChoices,
                      type = 'choice', dest = 'outputType', default = 'std',
                      help = 'What kind of string to output (' + ', '.join(outputChoices) + ') '
                                                                                            '[default: %default]')
    
    parser.add_option('-o', '--output', dest = 'outputFileName', default = None,
                      help = 'Name of the python file to write [default: stdout]')
    
    parser.add_option('-f', '--fields', dest = 'fieldList', default = None,
                      action = 'append', choices = fieldList,
                      help = 'Which fields to include in the output.  Currently only for csv '
                             'output [default: all]')
    
    parser.add_option('-p', '--print-csv-field-list', dest = 'printCsvfieldList',
                      default = False, action = 'store_true',
                      help = 'Print the field name for csv')
    
    parser.add_option('-c', '--sql-create', dest = 'sqlCreate', default = False,
                      action = 'store_true',
                      help = 'Print out an sql create command for the table.')
    
    parser.add_option('--latex-table', dest = 'latexDefinitionTable',
                      default = False, action = 'store_true',
                      help = 'Print a LaTeX table of the type')
    
    parser.add_option('--text-table', dest = 'textDefinitionTable', default = False,
                      action = 'store_true',
                      help = 'Print delimited table of the type (for Word table importing)')
    
    parser.add_option('--delimt-text-table', dest = 'delimTextDefinitionTable',
                      default = '    ',
                      help = 'Delimiter for text table [default: \'%default\'] '
                             '(for Word table importing)')
    
    dbChoices = ('sqlite', 'postgres')
    parser.add_option('-D', '--db-type',
                      dest = 'dbType',
                      default = 'postgres',
                      choices = dbChoices, type = 'choice',
                      help = 'What kind of database (' + ', '.join(dbChoices) + ') '
                                                                                '[default: %default]')
    
    addMsgOptions(parser)
    
    (options, args) = parser.parse_args()
    success = True
    
    if not success:
        sys.exit('Something Failed')
    del success  # Hide success from epydoc
    
    if options.unittest:
        sys.argv = [sys.argv[0]]
        if options.verbose:
            sys.argv.append('-v')
        unittest.main()
    
    outfile = sys.stdout
    if None != options.outputFileName:
        outfile = open(options.outputFileName, 'w')
    
    if options.doEncode:
        # Make sure all non required options are specified.
        if None == options.RepeatIndicatorField:
            parser.error("missing value for RepeatIndicatorField")
        if None == options.UserIDField:
            parser.error("missing value for UserIDField")
        if None == options.NavigationStatusField:
            parser.error("missing value for NavigationStatusField")
        if None == options.ROTField:
            parser.error("missing value for ROTField")
        if None == options.SOGField:
            parser.error("missing value for SOGField")
        if None == options.PositionAccuracyField:
            parser.error("missing value for PositionAccuracyField")
        if None == options.longitudeField:
            parser.error("missing value for longitudeField")
        if None == options.latitudeField:
            parser.error("missing value for latitudeField")
        if None == options.COGField:
            parser.error("missing value for COGField")
        if None == options.TrueHeadingField:
            parser.error("missing value for TrueHeadingField")
        if None == options.TimeStampField:
            parser.error("missing value for TimeStampField")
        if None == options.RAIMField:
            parser.error("missing value for RAIMField")
        if None == options.state_syncstateField:
            parser.error("missing value for state_syncstateField")
        if None == options.state_slottimeoutField:
            parser.error("missing value for state_slottimeoutField")
        if None == options.state_slotoffsetField:
            parser.error("missing value for state_slotoffsetField")
    msgDict = {
        'MessageID': '1',
        'RepeatIndicator': options.RepeatIndicatorField,
        'UserID': options.UserIDField,
        'NavigationStatus': options.NavigationStatusField,
        'ROT': options.ROTField,
        'SOG': options.SOGField,
        'PositionAccuracy': options.PositionAccuracyField,
        'longitude': options.longitudeField,
        'latitude': options.latitudeField,
        'COG': options.COGField,
        'TrueHeading': options.TrueHeadingField,
        'TimeStamp': options.TimeStampField,
        'RegionalReserved': '0',
        'Spare': '0',
        'RAIM': options.RAIMField,
        'state_syncstate': options.state_syncstateField,
        'state_slottimeout': options.state_slottimeoutField,
        'state_slotoffset': options.state_slotoffsetField,
    }
    
    bits = encode(msgDict)
    
    if 'binary' == options.ioType:
        print(str(bits))
    elif 'nmeapayload' == options.ioType:
        # FIX: figure out if this might be necessary at compile time
        bitLen = len(bits)
        if bitLen % 6 != 0:
            bits = bits + BitVector(size = (6 - (bitLen % 6)))  # Pad out to multiple of 6
        print(aisbinary.bitvectoais6(bits)[0])
    
    # FIX: Do not emit this option for the binary message payloads.  Does not make sense.
    elif 'nmea' == options.ioType:
        nmea = uscg.create_nmea(bits)
        print(nmea)
    else:
        sys.exit('ERROR: unknown ioType.  Help!')
        
        if options.sqlCreate:
            sqlCreateStr(outfile, options.fieldList, dbType = options.dbType)
        
        if options.latexDefinitionTable:
            latexDefinitionTable(outfile)
        
        # For conversion to word tables
        if options.textDefinitionTable:
            textDefinitionTable(outfile, options.delimTextDefinitionTable)
        
        if options.printCsvfieldList:
            # Make a csv separated list of fields that will be displayed for csv
            if None == options.fieldList:
                options.fieldList = fieldList
            import io
            
            buf = io.StringIO()
            for field in options.fieldList:
                buf.write(field + ',')
            result = buf.getvalue()
            if result[-1] == ',':
                print(result[:-1])
            else:
                print(result)
        
        if options.doDecode:
            if len(args) == 0:
                args = sys.stdin
            for msg in args:
                bv = None
                
                if msg[0] in ('$', '!') and msg[3:6] in ('VDM', 'VDO'):
                    # Found nmea
                    # FIX: do checksum
                    bv = aisbinary.ais6tobitvec(msg.split(',')[5])
                else:  # either binary or nmeapayload... expect mostly nmeapayloads
                    # assumes that an all 0 and 1 string can not be a nmeapayload
                    binaryMsg = True
                    for c in msg:
                        if c not in ('0', '1'):
                            binaryMsg = False
                            break
                    if binaryMsg:
                        bv = BitVector(bitstring = msg)
                    else:  # nmeapayload
                        bv = aisbinary.ais6tobitvec(msg)
                
                printFields(decode(bv)
                            , out = outfile
                            , format = options.outputType
                            , fieldList = options.fieldList
                            , dbType = options.dbType
                            )
    
    return
예제 #7
0
 def get_type_18 (self,
                  msg18):
     bits = ais_msg_18.encode(msg18)
     nmea = uscg.create_nmea(bits,
                             message_type = 18)
     return nmea