Exemplo n.º 1
0
def main():
    ship = 'knossos'
    if len(sys.argv) > 1: ship = sys.argv[1]
    try:
        print ships[ship][2]
    except:
        pass
    f = open(ships[ship][1])
    l = f.readline()
    for l in f:
        try:
            fields = l.split('\t')
            lat = float(fields[3])
            lon = float(fields[4])
            sog = float(fields[2])
            cog = float(fields[5])
        except ValueError:
            print >> sys.stderr, l,
            continue
        aismsg = aislib.AISPositionReportMessage(mmsi=ships[ship][0],
                                                 pa=1,
                                                 lon=int((lon) * 60 * 10000),
                                                 lat=int((lat) * 60 * 10000),
                                                 heading=int(cog),
                                                 sog=int(sog * 10),
                                                 cog=int(cog * 10),
                                                 status=0,
                                                 ts=60,
                                                 raim=1,
                                                 comm_state=82419)
        ais = aislib.AIS(aismsg)
        payload = ais.build_payload(False)
        print payload
        time.sleep(2)
        #   print "nav status: %d" % aismsg.get_attr("status")

        aismsg2 = ais.decode(payload)
        ais2 = aislib.AIS(aismsg2)
        payload2 = ais2.build_payload(False)


#   print payload2
#   print "nav status: %d" % aismsg2.get_attr("status")

#print aismsg.id
#print aismsg.repeat

#bitstr = aismsg.build_bitstream()
#print bitstr.bin
# #print bitstr.len
    f.close()
Exemplo n.º 2
0
    def getAisStr(self, mssi_, LatLon):
        # status
        # 0 - undarway
        # 1 - anchore
        # 2 - not under command
        # 3 - restricted movability
        # 4 - contrained
        # 5 - moored
        # 6 - aground
        # 7 - engaged in finish
        # 8 - under way sailing
        # 9 - high speed craft
        # 10 - wing in ground effect
        # 11 - power driven vessel towing
        # 12 - power driven vessel pushing
        # 13 - reserved 13
        # 15 - undefined

        a = aislib.AISPositionReportMessage(mmsi=mssi_,
                                            pa=1,
                                            lon=int((LatLon.lon) * 60 * 10000),
                                            lat=int((LatLon.lat) * 60 * 10000),
                                            status=15,
                                            ts=30,
                                            raim=0,
                                            comm_state=0)
        ais = aislib.AIS(a)
        #print("ais",ais)
        p = ais.build_payload(False)
        #print("payload",p)
        return p
 def aisCallback(self, data):
     rospy.loginfo(data)
     for ship in data.ships:
         aisreport = ais.AISPositionReportMessage(
             mmsi=ship.ID,
             lon=int(ship.lon * 600000),
             lat=int(ship.lat * 600000),
             heading=int(headingToBearingDegrees(ship.headingDegrees)) %
             360)
         aismsg = ais.AIS(aisreport)
         sock.sendto(aismsg.build_payload(), (UDP_IP, UDP_PORT))
Exemplo n.º 4
0
    def as_AIS_report(self, route={}):
        # Message Type 5
        aismsg = aislib.AISStaticAndVoyageReportMessage(mmsi=self.mmsi,
            imo=self.imo,
            callsign=self.callsign,
            shipname=self.name,
            shiptype=36,
            to_bow=5,to_stern=5,to_port=1,to_starboard=1, 
            draught=int(self.draught * 10.0),
            epfd=1, month=5, day=14, hour=20, minute=15,
            destination='CANBERRA')

        ais = aislib.AIS(aismsg)
        payload = ais.build_payload(False)
        return payload
Exemplo n.º 5
0
 def as_AIS_pos_report(self):
     # return an NMEA encoded position report
     
     aismsg = aislib.AISPositionReportMessage( \
         mmsi = self.vessel.mmsi, \
         status = 8, \
         sog = int(self.speed*10.0), \
         pa = 1, \
         lon = int(self.pos.x * 600000),
         lat = int(self.pos.y * 600000),
         # lon = (25*60+00)*10000,
         # lat = (35*60+30)*10000,
         cog = int(self.course * 10.0),
         ts = 40,
         raim = 1,
         comm_state = 82419
     )
     ais = aislib.AIS(aismsg)
     payload = ais.build_payload(False)
     return payload
Exemplo n.º 6
0
# Tests for Message Type 1
#

print('Tests for Message Type 1')

aismsg = aislib.AISPositionReportMessage(mmsi=237772000,
                                         status=8,
                                         sog=75,
                                         pa=1,
                                         lon=(25 * 60 + 00) * 10000,
                                         lat=(35 * 60 + 30) * 10000,
                                         cog=2800,
                                         ts=40,
                                         raim=1,
                                         comm_state=82419)
ais = aislib.AIS(aismsg)
payload = ais.build_payload(False)
print(payload)  # !AIVDM,1,1,,A,13RhLp801;QjL>0DD38:t?w@2D7k,0*3E
aismsg2 = ais.decode(payload)
ais2 = aislib.AIS(aismsg2)
payload2 = ais2.build_payload(False)
assert payload == payload2

#
# Tests for Message Type 2 (payload format as type 1)
#

print('Tests for Message Type 2 (payload format as type 1)')

aismsg = aislib.AISPositionReportMessage(id=2,
                                         mmsi=237772000,
Exemplo n.º 7
0
                 int_lat_1 = int(latfloat)
                 int_lat_1 = int_lat_1 * 60 * 10000
                 int_lat_2 = latfloat - float((int(latfloat)))
                 int_lat_2 = int_lat_2 * 60 * 10000
                 int_lat_3 = int_lat_2 + int_lat_1
                 aismsg.lat = int(int_lat_3)
                 int_long_1 = int(longfloat)
                 int_long_1 = int_long_1 * 60 * 10000
                 int_long_2 = longfloat - float((int(longfloat)))
                 int_long_2 = int_long_2 * 60 * 10000
                 int_long_3 = int_long_2 + int_long_1
                 aismsg.lon = int(int_long_3)
                 heading = float(doc.Document.Style.IconStyle.heading.text)
                 heading = heading * 10
                 aismsg.cog = int(heading)
                 ais = aislib.AIS(aismsg)
                 payload = ais.build_payload(False)
                 conn.send(payload)
                 conn.send('\n\r')
         time.sleep(1)
 except KeyboardInterrupt:
     print("Got ctrl+c, exit... bye!")
     #conn.close()
     #p.close()
     s.close()
     sys.exit()
 except:
     print("Session closed, restart server")
     #conn.close()
     #p.close()
     s.close()
Exemplo n.º 8
0
    # current_waypoint = data_yaml['current_waypoint']
    longitude, latitude = transform(inProj, outProj, east, north)
    # print(longitude, latitude)
    aismsg1 = aislib.AISPositionReportMessage(
        mmsi=imei,
        sog=min(int(round(data_yaml['gnss_speed'] * 19.4384)),
                1022),  # vitesse en dixieme de noeuds
        pa=1,
        lat=int(round(latitude * 60e4)),
        lon=int(round(longitude * 60e4)),
        cog=min(int(data_yaml['gnss_heading'] * 10.), 3599)  #, # max 3600
        # ts = msg_date.second
    )

    ais1 = aislib.AIS(aismsg1)
    payload1 = ais1.build_payload(False)
    ser.write(payload1 + '\n')

    aismsg2 = aislib.AISStaticAndVoyageReportMessage(shipname=ship_name,
                                                     mmsi=imei,
                                                     epfd=3,
                                                     month=msg_date.month,
                                                     day=msg_date.day,
                                                     hour=msg_date.hour,
                                                     minute=msg_date.minute,
                                                     destination="WAYPOINT " +
                                                     str(current_waypoint))
    ais2 = aislib.AIS(aismsg2)
    payload2 = ais2.build_payload(False)
    ser.write(payload2 + '\n')