forked from tanchou/Verilog
Refactor ultrasonic FPGA module: replace sig_in with sig_ok for improved signal handling and update ESP32 command processing to support new client list command
This commit is contained in:
@@ -114,22 +114,29 @@ void processCommand(uint8_t* data, int length) {
|
||||
case 0x03: { // Request Connected Devices
|
||||
wifi_sta_list_t staList;
|
||||
if (esp_wifi_ap_get_sta_list(&staList) == ESP_OK) {
|
||||
byte packet[3 + 1 + 6 * 10 + 2]; // max 10 clients
|
||||
uint8_t index = 0;
|
||||
packet[index++] = 0x02;
|
||||
packet[index++] = 0x04;
|
||||
packet[index++] = staList.num; // LEN
|
||||
|
||||
for (int i = 0; i < staList.num; i++) {
|
||||
byte packet[12] = {0x02, 0x02, 0x01}; // 0x01 = connect
|
||||
memcpy(packet + 3, staList.sta[i].mac, 6);
|
||||
packet[9] = 0x1B;
|
||||
packet[10] = 0x03;
|
||||
Serial.write(packet, 11);
|
||||
memcpy(&packet[index], staList.sta[i].mac, 6);
|
||||
index += 6;
|
||||
}
|
||||
|
||||
packet[index++] = 0x1B;
|
||||
packet[index++] = 0x03;
|
||||
|
||||
Serial.write(packet, index);
|
||||
} else {
|
||||
byte packet[] = {0x02, 0x00, 0x02, 0x1B, 0x03}; // Erreur : args
|
||||
Serial.write(packet, sizeof(packet));
|
||||
byte error[] = {0x02, 0x00, 0x02, 0x1B, 0x03}; // Erreur : args
|
||||
Serial.write(error, sizeof(error));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 0x04: { // Send Message
|
||||
case 0x05: { // Send Message
|
||||
if (length < 12) {
|
||||
byte packet[] = {0x02, 0x00, 0x02, 0x1B, 0x03}; // args error
|
||||
Serial.write(packet, sizeof(packet));
|
||||
|
@@ -0,0 +1,60 @@
|
||||
import serial
|
||||
import time
|
||||
|
||||
START_BYTE = 0x02
|
||||
END_BYTES = [0x1B, 0x03]
|
||||
|
||||
def build_command(opcode, payload=b''):
|
||||
frame = bytearray()
|
||||
frame.append(START_BYTE)
|
||||
frame.append(opcode)
|
||||
frame.extend(payload)
|
||||
frame.extend(END_BYTES)
|
||||
return frame
|
||||
|
||||
def send_command(ser, opcode, payload=b''):
|
||||
frame = build_command(opcode, payload)
|
||||
print(f"Envoi : {[hex(b) for b in frame]}")
|
||||
ser.write(frame)
|
||||
|
||||
def main():
|
||||
port = 'COM5'
|
||||
baud = 115200
|
||||
|
||||
try:
|
||||
with serial.Serial(port, baud, timeout=2) as ser:
|
||||
while True:
|
||||
print("\nCommandes disponibles :")
|
||||
print("1. État du Wi-Fi")
|
||||
print("2. Liste des clients connectés")
|
||||
print("3. Envoyer un message")
|
||||
print("4. Quitter")
|
||||
|
||||
choix = input("Choix (1-4) : ")
|
||||
|
||||
if choix == "1":
|
||||
send_command(ser, 0x01)
|
||||
elif choix == "2":
|
||||
send_command(ser, 0x03)
|
||||
elif choix == "3":
|
||||
msg = input("Message à envoyer : ")
|
||||
msg_bytes = msg.encode('utf-8')
|
||||
send_command(ser, 0x05, msg_bytes)
|
||||
elif choix == "4":
|
||||
print("Fermeture.")
|
||||
break
|
||||
else:
|
||||
print("Choix invalide.")
|
||||
|
||||
time.sleep(0.5)
|
||||
|
||||
print("Réponse reçue :")
|
||||
while ser.in_waiting:
|
||||
byte = ser.read(1)
|
||||
print(f"Reçu : 0x{byte[0]:02X}")
|
||||
|
||||
except serial.SerialException as e:
|
||||
print(f"Erreur de port série : {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user