Skip to content

Commit 0c686cc

Browse files
committed
Added script for creating log files
1 parent 3d2d0cb commit 0c686cc

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# this script can be used to generate log files for the CANedge e.g. for testing WiFi transfer
2+
3+
import os
4+
import hashlib
5+
6+
# specify details of log files (device ID should match your test device)
7+
device_id = "534F281B"
8+
file_type = "MF4"
9+
sessions = 120
10+
splits = 50
11+
size_bytes = 2 * 1024 * 1024
12+
13+
# function for creating files
14+
def sha256_file(path):
15+
digest = hashlib.sha256()
16+
with open(path, "rb") as f:
17+
while True:
18+
buf = f.read(65536)
19+
if len(buf) == 0:
20+
break
21+
digest.update(buf)
22+
return digest.hexdigest().upper()
23+
24+
# run loop to create log files in folders
25+
dir_path = os.path.dirname(os.path.abspath(__file__))
26+
27+
for session_no in range(1, sessions + 1):
28+
for split_no in range(1, splits + 1):
29+
tmp_file_name = "{}.mf4".format(split_no)
30+
tmp_file_path = os.path.join(dir_path, tmp_file_name)
31+
32+
with open(tmp_file_path, "w+") as f:
33+
f.seek(size_bytes - 1)
34+
f.write("\0")
35+
36+
# Calculate digest of file
37+
digest = sha256_file(tmp_file_path)
38+
39+
# create folder name
40+
folder = f'{session_no}'.zfill(8)
41+
42+
# Check whether the specified path exists or not
43+
isExist = os.path.exists(folder)
44+
45+
if not isExist:
46+
# Create a new directory because it does not exist
47+
os.makedirs(folder)
48+
49+
# Create file name
50+
new_file_name = folder + "\\" + f"{split_no}".zfill(8) + ".MF4"
51+
# new_file_name = "{}_{:08}_{:08}-{}.mf4".format(device_id, session_no, split_no, digest)
52+
new_file_path = os.path.join(dir_path, new_file_name)
53+
54+
os.rename(tmp_file_path, new_file_path)

0 commit comments

Comments
 (0)