Set up ECU proxy server
This commit is contained in:
parent
863841bd74
commit
483d054b2f
30
server/main.py
Normal file
30
server/main.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
async def proxy(reader, writer):
|
||||
message = await reader.read(1024)
|
||||
addr = writer.get_extra_info('peername')
|
||||
|
||||
try:
|
||||
print('Recvd from {}: {}'.format(addr[0], message))
|
||||
offset = 32
|
||||
date_time_obj = datetime.strptime(str(message)[offset:offset+14], '%Y%m%d%H%M%S') + timedelta(minutes=-5)
|
||||
send_str = '101' + datetime.strftime(date_time_obj, '%Y%m%d%H%M%S')
|
||||
send_data = send_str.encode()
|
||||
print('Sending to {}: {}'.format(addr[0], send_data))
|
||||
writer.write(send_data)
|
||||
await writer.drain()
|
||||
except ValueError:
|
||||
print('Ignored unnecessary data')
|
||||
|
||||
writer.close()
|
||||
|
||||
async def main():
|
||||
for port in [8995, 8996, 8997]:
|
||||
server = await asyncio.start_server(proxy, '192.168.69.69', port)
|
||||
task = asyncio.create_task(server.serve_forever())
|
||||
|
||||
# block here for now
|
||||
await task
|
||||
|
||||
asyncio.run(main())
|
Loading…
Reference in New Issue
Block a user