Skip to content

Commit 52d4920

Browse files
authored
Merge pull request #48 from IndTechSpprt/result-verification
Result verification
2 parents 3ccdfc9 + 76b3a75 commit 52d4920

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ pc_code/Algorithms/json_files/resnet18.json
3434
pc_code/Algorithms/json_files/test_resnet18_residual_convolution.json
3535
pc_code/Algorithms/json_files/test_resnet18_residual_merged.json
3636
pc_code/Fused/fused_layers_resnet18.json
37+
pc_code/Simulation/Simu_q/worker_4.json
38+
pc_code/Simulation/Simu_q/input_len_4.txt
39+
pc_code/Simulation/Simu_q/res_len_4.txt

MCU_code/PlatformIO_code/worker_code/include/communication.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
/// @brief All supported message headers
1818
enum MessageHeaders{
19+
Inference_Results = (byte)195,
1920
Adaptive_Pooling = (byte)196,
2021
ACK = (byte)197,
2122
Complete = (byte)198,

MCU_code/PlatformIO_code/worker_code/src/worker_code.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,19 @@ void setup() {
217217
}
218218
count += LINEAR_SEGMENT;
219219
}
220+
char results[MESSAGE_SIZE];
221+
int res_count = 0;
220222
for(int k = 0; k < result_length[j]; k++){
221223
Serial.print(k);
222224
Serial.print(" ");
223225
Serial.println(result[k]);
226+
results[RESERVED_BYTES + res_count] = result[k];
227+
res_count+=1;
224228
}
229+
results[0] = MCU_ID;
230+
results[1] = Inference_Results;
231+
write_length(results, res_count);
232+
client.write(results, MESSAGE_SIZE);
225233
}
226234
}
227235
#ifdef PROFILING

MCU_code/tcp.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@
6262
sockets = [None] * num_mcu
6363
addresses = [None] * num_mcu
6464
which = -1
65+
results_dict = dict()
6566
for count in range(num_mcu):
6667
# Accept a connection
6768
client_socket, client_address = server_socket.accept()
6869
client_socket.setblocking(0) # Set socket to non-blocking mode
6970
print(str(client_address[0]))
7071
for mcu in testbed:
7172
if str(client_address[0]) == ip_first_part+mcu["ip_end"]:
72-
which = int(mcu["mcu_id"])
73+
which = int(mcu["id"])
7374
sockets[which] = client_socket
7475
addresses[which] = client_address
7576
print(f"Connected to Arduino {which} at:", client_address)
@@ -208,6 +209,11 @@ def send_ack(sock, data):
208209
for i in range(6, 6 + len_int):
209210
to_adaptive_pooling.append(received_data[i])
210211
print(len(to_adaptive_pooling))
212+
213+
elif received_data[1] == 195:
214+
len_int = struct.unpack('<I', received_data[2:6])[0]
215+
print(f"received results data from MCU{received_data[0]}, len {len_int}")
216+
results_dict[str(received_data[0])] = struct.unpack('<' + 'B'*len(received_data[6:6+len_int]), received_data[6:6+len_int])
211217

212218
else:
213219
data_to_send = received_data
@@ -224,4 +230,11 @@ def send_ack(sock, data):
224230
for w in to_which:
225231
wait_for_ack(sockets[w], message_size)
226232
except KeyboardInterrupt:
233+
index = 0
234+
with open("inference_results_mcu.txt", 'w') as file:
235+
for count in range(num_mcu):
236+
for result in results_dict[str(count)]:
237+
file.write(str(index)+": "+str(result)+"\n")
238+
index+=1
239+
227240
print("Closing connection")

MCU_code/testbed.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"mcu_id": "0", "ip_end": "124", "mac_end": "235"}, {"mcu_id": "1", "ip_end": "123", "mac_end": "236"}, {"mcu_id": "2", "ip_end": "122", "mac_end": "237"},{"mcu_id": "3", "ip_end": "121", "mac_end": "238"}]
1+
[{"mcu_id": "0", "ip_end": "124", "mac_end": "235"}, {"mcu_id": "1", "ip_end": "123", "mac_end": "236"}, {"mcu_id": "2", "ip_end": "122", "mac_end": "237"}]

0 commit comments

Comments
 (0)