This is based on QuecPython.
Currently AIS-140 (2016) is supported.
The purpose of this library is to provide the building blocks to construct a vehicle location tracking and emergency button. The library does not provide a completed solution, as any implementation is specific for its intended use. The documents in this library should be inspected, as these documents provided guidance on how best to build a complete solution.
Note:
To run these examples the dependency usocket is required!
The demo/ais_client_demo.py is a Vehicle Location Tracking and Emergency Button demo.
fromusr.aisimportAISClient# Receive Server Commands Funtion.defserver_cmd(cmd, key, val):
"""This function is for receiving server commands. Args: cmd(str): SET/GET/CLR. key(str): PIP - Primary Server IP PPT - Primary Server Port SIP - Secondary Server IP SPT - Secondary Server Port EO - Emergency OFF ED - Emergency Duration APN - Network APN SL - Speed Limit VN - Vehicle Registration Number UR - Update Rate URE - Update Rate Emergency URH - Update Rate Health Packet VID - Vendor ID ODM - Set Odometer val(str): Value of commmand key. """print("cmd[%s], key[%s], val[%s]"% (cmd, key, val))
defmain():
# Init AIS Client.cfg= {
"ip": "xxx.xxx.xxx.xxx",
"port": 9000,
}
ais_client=AISClient(**cfg)
ais_client.set_callback(server_cmd)
# Connect Serverres=ais_client.connect()
# Send Login Packetlogin_kwargs= {...}
res=ais_client.send_login(**login_kwargs)
print("ais_client.send_login() %s"%res)
# Send Health Monitoring Packethbt_kwargs= {...}
res=ais_client.send_heart_beat(**hbt_kwargs)
print("ais_client.send_heart_beat() %s"%res)
# Send Location/Alert Information Packetlai_kwargs= {...}
res=ais_client.send_loction_alert_information(**lai_kwargs)
print("ais_client.send_loction_alert_information() %s"%res)
# Send Emergency Packetmeg_kwargs= {...}
res=ais_client.send_emergency(**meg_kwargs)
print("ais_client.send_emergency() %s"%res)
# Disconnect Serverres=ais_client.disconnect()
print("ais_client.disconnect() %s"%res)|-- code
|-- ais.py
|-- logging.py
|-- demo
|-- ais_client_demo.py
|-- ais_server_demo.py
|-- docs
|-- AIS-140 (2016).pdf
|-- VT140-Protocol_V1._20200104.pdfcodefloder is incloud AIS client codes.code/ais.pyis incloud all ais client requests interface.code/logging.pyis log module.
demofloder is incloud AIS client demo and AIS server demo.demo/ais_client_demo.pyis an AIS client demo base on QuecPython.demo/ais_server_demo.pyis an AIS server demo base on CPython.
docsfloder is incloud AIS-140 protocal documents.
If you have your own AIS-140 server, you can skip this instruction.
Operating System: Window or Linux.
Language: Python (Python-3.11.2).
- Change your server port in
demo/ais_server_demo.py.
SERVER_PORT=31500# Change this port value for your own server port.
...
if__name__=='__main__':
try:
logging.info("Start Server !")
socket_serve=TCPServer(('', SERVER_PORT), ReceiveHandler)
foriinrange(THREAD_WORKERS_NUM):
t=Thread(target=socket_serve.serve_forever)
t.daemon=Truet.start()
socket_serve.serve_forever()
exceptKeyboardInterrupt:
socket_serve.shutdown()
logging.info("Stop Server !")- Running
python demo/ais_server_demo.py. When output[INFO] xxxx-xx-xxx xxx xx:xx:xx ais_server_demo.py: Start Server !, the server is started.
>>> python ais_server_demo.py
[INFO] xxxx-xx-xxx xxx xx:xx:xx ais_server_demo.py: Start Server !You need to use our QuecPython module.
- Config your server host and port in
demo/ais_client_demo.py
if__name__=="__main__":
# Init AIS Client.cfg= {
"ip": "xxx.xxx.xxx.xxx",
"port": 9000,
} # Use your own server ip and port.ais_client=AISClient(**cfg)
ais_client.set_callback(server_cmd)- Download code to QuecPython module
Note:
You can find documents in QuecPython Document Center for how to download python code and running python demo in our QuecPython module
You can download full code floder and demo/ais_client_demo.py to our QuecPython module and run ais_client_demo.py to test AIS-140 Vehicle Location Tracking and Emergency Button.
You can see log ais_client.send_login() True. in our QPYcom REPL, than the Login Packet message is sented to server.
Note:
You can refer to
demo/ais_client_demo.pyto write client requests that conform to business logic.