import socket import os from crccheck.crc import CrcArc def clear_screen(): os.system("cls" if os.name == "nt" else "clear") def send_tcp_message(host, port, message: bytes): try: with socket.create_connection((host, port), timeout=10) as sock: print(f"📤 Sending: {message}") sock.sendall(message) response = sock.recv(1024) print(f"📥 Received: {response}") except Exception as e: print(f"❌ Error sending message: {e}") def build_sia_dcs_message(): client_id = input("Enter Client ID (e.g. 1234): ").zfill(4) code = input("Enter Event Code (e.g. OP, RP, BA): ").upper() zone = input("Enter Zone (e.g. 01): ").zfill(2) image_url = input("Optional Image URL (or leave blank): ") body = f'"SIA-DCS"0001L0#{client_id}[{client_id}|Nri1/{code}{zone}]' if image_url: body += f'[V{image_url}]' data_bytes = body.encode("ascii") crc = CrcArc.calc(data_bytes) length = len(data_bytes) full_message = f"\n{crc:04X}{length:04X}{body}\r".encode("ascii") return full_message def build_adm_cid_message(): line = input("Enter phone line number (e.g. 01): ").zfill(2) account = input("Enter account number (e.g. 1234): ").zfill(4) code = input("Enter event code (e.g. 401): ").zfill(3) qualifier = input("Enter qualifier (1=New, 3=Restore): ").zfill(1) area = input("Enter partition/area (e.g. 1): ").zfill(2) zone = input("Enter zone/user (e.g. 005): ").zfill(3) # ADM-CID format: \r\nLLL:18QCCC[AAAA|EEMMZZ]\r cid_data = f'18{qualifier}{code}[{account}|{area}{area}{zone}]' msg = f"\r\n{line}{cid_data}\r".encode("ascii") return msg def main(): clear_screen() print("🚨 Alarm Test Sender") host = input("Enter receiver IP (e.g. 127.0.0.1): ") port = int(input("Enter port (e.g. 9000): ")) while True: print("\nChoose protocol:") print("1. Send SIA-DCS message") print("2. Send ADM-CID message") print("3. Exit") choice = input("Select (1/2/3): ") if choice == "1": msg = build_sia_dcs_message() send_tcp_message(host, port, msg) elif choice == "2": msg = build_adm_cid_message() send_tcp_message(host, port, msg) elif choice == "3": print("👋 Bye!") break else: print("Invalid choice") if __name__ == "__main__": main()