Skip to content

Commit

Permalink
Fix strToUInt32 (#2)
Browse files Browse the repository at this point in the history
Now the data should be correct.
  • Loading branch information
Teddy-van-Jerry committed Aug 30, 2023
1 parent efd5916 commit 4a5c834
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
10 changes: 9 additions & 1 deletion reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ def print_table(df):
df = read_parquet_file(file_path)

# print the data table
print_table(df)
# print_table(df)

timestamp = df.iloc[0, 0]
noise = df.iloc[0, 1]

# print timestamp and noise in HEX
print('timestamp: ', hex(timestamp))
print('noise: ', hex(noise))


# end time
end_time = time.time()
Expand Down
5 changes: 4 additions & 1 deletion src/pkt_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@ uint32_t Pkt_Parse::Data::bytesToUInt32(const std::array<std::byte, 4>& bytes) {

uint32_t Pkt_Parse::Data::strToUInt32(const std::string& str) {
assert(str.size() == 4); // str must be length of 4
return str[0] << 24 | str[1] << 16 | str[2] << 8 | str[3];
return (static_cast<uint32_t>(static_cast<uint8_t>(str[0])) << 24) |
(static_cast<uint32_t>(static_cast<uint8_t>(str[1])) << 16) |
(static_cast<uint32_t>(static_cast<uint8_t>(str[2])) << 8) |
static_cast<uint32_t>(static_cast<uint8_t>(str[3]));
}
6 changes: 4 additions & 2 deletions tests/udp_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import time
import argparse

message = "#" + "0" * 1039 # 1040 bytes
message = b"\x31\xd4\x91\xb2\x34\x01\xd2\x04" + b"\x00" * 1032

print(len(message))

def send_udp_packet(host, port, data, quiet=False):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(data.encode(), (host, port))
sock.sendto(data, (host, port))
if not quiet:
print(f"Sent packet with length {len(data)} to {host}:{port}")
except Exception as e:
Expand Down

0 comments on commit 4a5c834

Please sign in to comment.