Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion content/en/docs/Tutorials/Emitter and Receiver/gameInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ if(receiver->getQueueLength() > 0) { // If receiver queue is not empty
char *receivedData = (char *)receiver->getData(); // Grab data as a string
float score = 0.0;
int time = 0;
int realTime = 0;
if (receivedData[0] == 'G') {
memcpy(&score, receivedData + 4, 4); // Score stored in bytes 4 to 7
memcpy(&time, receivedData + 8, 4); // Remaining time stored in bytes 8 to 11
cout << "Game Score: " << score << " Remaining time: " << time << endl;
memcpy(&realTime, receivedData + 12, 4); // Remaining real time stored in bytes 12 to 15
cout << "Game Score: " << score << " Remaining time: " << time << " Remaining real-world time: " << realTime << endl;
receiver->nextPacket(); // Discard the current data packet
}
}
4 changes: 2 additions & 2 deletions content/en/docs/Tutorials/Emitter and Receiver/gameInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

if receiver.getQueueLength() > 0: # If receiver queue is not empty
receivedData = receiver.getBytes()
tup = struct.unpack('c f i', receivedData) # Parse data into char, float, int
tup = struct.unpack('c f i i', receivedData)
if tup[0].decode("utf-8") == 'G':
print(f'Game Score: {tup[1]} Remaining time: {tup[2]}')
print(f'Game Score: {tup[1]} Remaining time: {tup[2]} Remaining real-world time: {tup[3]}')
receiver.nextPacket() # Discard the current data packet