Removed icons
This commit is contained in:
parent
30281d2244
commit
f03151c8a4
|
|
@ -47,7 +47,7 @@ def verify_message(message: bytes) -> tuple[bool, str]:
|
|||
print(f"CRC mismatch: received {crc_str} calculated {crc_calc:04X}")
|
||||
return False, None
|
||||
|
||||
print(f"✅ Valid message received: {payload_str}")
|
||||
print(f"Valid message received: {payload_str}")
|
||||
return True, payload_str
|
||||
|
||||
|
||||
|
|
@ -130,11 +130,11 @@ import asyncio
|
|||
|
||||
async def handle_client(reader: asyncio.StreamReader, writer: asyncio.StreamWriter):
|
||||
addr = writer.get_extra_info('peername')
|
||||
print(f"📡 Connection from {addr}")
|
||||
print(f"Connection from {addr}")
|
||||
|
||||
try:
|
||||
data = await reader.readuntil(b'\r')
|
||||
print(f"📥 Raw received: {data}")
|
||||
print(f"Raw received: {data}")
|
||||
|
||||
is_valid, payload = verify_message(data)
|
||||
response = b"\n0004NACK\r" # fallback
|
||||
|
|
@ -142,7 +142,7 @@ async def handle_client(reader: asyncio.StreamReader, writer: asyncio.StreamWrit
|
|||
if is_valid and payload:
|
||||
parsed = parse_sia_payload(payload)
|
||||
parsed["source_ip"] = str(addr[0])
|
||||
print("📦 Parsed payload:")
|
||||
print("Parsed payload:")
|
||||
print(json.dumps(parsed, indent=2))
|
||||
sia_data = parsed
|
||||
# Connect to MariaDB
|
||||
|
|
@ -175,7 +175,7 @@ async def handle_client(reader: asyncio.StreamReader, writer: asyncio.StreamWrit
|
|||
|
||||
cursor.execute(query, values)
|
||||
conn.commit()
|
||||
print("✅ Inserted signal into database.")
|
||||
print("Inserted signal into database.")
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
|
@ -187,25 +187,25 @@ async def handle_client(reader: asyncio.StreamReader, writer: asyncio.StreamWrit
|
|||
length = str(hex(len(response_payload))).split('x')
|
||||
response = f"\n{crc:04X}00{length[1].upper()}{response_payload}\r".encode()
|
||||
|
||||
print(f"✅ Sending response: {response}")
|
||||
print(f"Sending response: {response}")
|
||||
else:
|
||||
print("❌ Invalid message. Sending fallback NACK.")
|
||||
print("Invalid message. Sending fallback NACK.")
|
||||
|
||||
writer.write(response)
|
||||
await writer.drain()
|
||||
|
||||
except asyncio.IncompleteReadError:
|
||||
print("⚠️ Connection closed before end of message")
|
||||
print("Connection closed before end of message")
|
||||
except Exception as e:
|
||||
print(f"🔥 Error: {e}")
|
||||
print(f"Error: {e}")
|
||||
finally:
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
print(f"🔌 Connection with {addr} closed")
|
||||
print(f"Connection with {addr} closed")
|
||||
|
||||
async def main():
|
||||
server = await asyncio.start_server(handle_client, host='0.0.0.0', port=9000)
|
||||
print("🚀 Listening on TCP port 9000 for SIA-DCS messages")
|
||||
print("Listening on TCP port 9000 for SIA-DCS messages")
|
||||
async with server:
|
||||
await server.serve_forever()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue