Spaces:
Sleeping
Sleeping
Update turbowarp-server/qr-converter.py
Browse files- turbowarp-server/qr-converter.py +11 -13
turbowarp-server/qr-converter.py
CHANGED
|
@@ -102,33 +102,31 @@ print("[INFO] Starting main loop...")
|
|
| 102 |
while True:
|
| 103 |
try:
|
| 104 |
n1 = get_var("n1")
|
| 105 |
-
if n1 and len(n1) >= 3 and n1[0] == "0": #
|
| 106 |
-
set_var("n1", "01")
|
| 107 |
print("[INFO] Received new request from n1.")
|
| 108 |
if get_var("n0") == "0": # 他ユーザー未使用
|
| 109 |
-
print("[INFO] n0 is free, starting processing...")
|
| 110 |
set_var("n0", "1")
|
| 111 |
user_id = n1[1:3] # 実際のIDはここを調整
|
| 112 |
encoded_prompt = n1[3:]
|
| 113 |
prompt = decode_prompt(encoded_prompt)
|
| 114 |
-
|
| 115 |
# 画像生成
|
| 116 |
img = generate_image(prompt)
|
| 117 |
scratch_data = resize_and_encode(img)
|
| 118 |
-
|
| 119 |
-
# パケット分割
|
| 120 |
packets = split_packets(scratch_data)
|
| 121 |
for i, pkt in enumerate(packets):
|
| 122 |
-
|
| 123 |
-
set_var("n1", pkt) # 送信
|
| 124 |
time.sleep(0.2)
|
| 125 |
-
# 次パケット送信待ち
|
| 126 |
while get_var("n1") != "11":
|
| 127 |
-
print("[INFO] Waiting for ACK '11'...")
|
| 128 |
time.sleep(0.1)
|
| 129 |
-
|
| 130 |
-
#
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
| 132 |
set_var("n0", "0")
|
| 133 |
except Exception as e:
|
| 134 |
print(f"[ERROR] Exception in main loop: {e}")
|
|
|
|
| 102 |
while True:
|
| 103 |
try:
|
| 104 |
n1 = get_var("n1")
|
| 105 |
+
if n1 and len(n1) >= 3 and n1[0] == "0": # 未処理フラグ
|
|
|
|
| 106 |
print("[INFO] Received new request from n1.")
|
| 107 |
if get_var("n0") == "0": # 他ユーザー未使用
|
|
|
|
| 108 |
set_var("n0", "1")
|
| 109 |
user_id = n1[1:3] # 実際のIDはここを調整
|
| 110 |
encoded_prompt = n1[3:]
|
| 111 |
prompt = decode_prompt(encoded_prompt)
|
| 112 |
+
|
| 113 |
# 画像生成
|
| 114 |
img = generate_image(prompt)
|
| 115 |
scratch_data = resize_and_encode(img)
|
| 116 |
+
|
| 117 |
+
# パケット分割・送信
|
| 118 |
packets = split_packets(scratch_data)
|
| 119 |
for i, pkt in enumerate(packets):
|
| 120 |
+
set_var("n1", pkt)
|
|
|
|
| 121 |
time.sleep(0.2)
|
|
|
|
| 122 |
while get_var("n1") != "11":
|
|
|
|
| 123 |
time.sleep(0.1)
|
| 124 |
+
|
| 125 |
+
# --- ここで既読フラグに変更 ---
|
| 126 |
+
set_var("n1", "01" + n1[2:])
|
| 127 |
+
print("[INFO] Marked n1 as processed.")
|
| 128 |
+
|
| 129 |
+
# 処理完了後リセット
|
| 130 |
set_var("n0", "0")
|
| 131 |
except Exception as e:
|
| 132 |
print(f"[ERROR] Exception in main loop: {e}")
|