Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
x393_sata
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
x393_sata
Commits
282f41b3
Commit
282f41b3
authored
Dec 10, 2016
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+logger
parent
727bf4bc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
0 deletions
+111
-0
x393sata_logger.py
py393sata/x393sata_logger.py
+111
-0
No files found.
py393sata/x393sata_logger.py
0 → 100644
View file @
282f41b3
#!/usr/bin/env python
# encoding: utf-8
from
__future__
import
print_function
from
__future__
import
division
import
os
import
x393_mem
import
time
import
sys
def
get_wp
(
mem
):
return
((
mem
.
read_mem
(
0x80000ffc
)
>>
10
)
&
0xffc
)
+
0x80001000
def
get_len
(
p1
,
p0
):
return
p1
-
p0
# Temporary
# because mm[start_offset:end_offset] might not work properly
# last 64 bytes get bad
def
mem_write_to_file
(
mem
,
bf
,
start_addr
,
length
):
with
open
(
"/dev/mem"
,
"r+b"
)
as
f
:
first_page
=
start_addr
//
mem
.
PAGE_SIZE
last_page
=
(
start_addr
+
length
-
1
)
//
mem
.
PAGE_SIZE
for
page_num
in
range
(
first_page
,
last_page
+
1
):
start_offset
=
0
if
page_num
==
first_page
:
start_offset
=
start_addr
-
mem
.
PAGE_SIZE
*
page_num
end_offset
=
mem
.
PAGE_SIZE
if
page_num
==
last_page
:
end_offset
=
start_addr
+
length
-
mem
.
PAGE_SIZE
*
page_num
page_addr
=
page_num
*
mem
.
PAGE_SIZE
mm
=
mem
.
wrap_mm
(
f
,
page_addr
)
for
i
in
range
(
start_offset
,
end_offset
,
4
):
bf
.
write
(
mm
[
i
:
i
+
4
])
debug_mode
=
0
dry_mode
=
0
filename
=
"/tmp/x393mem.log"
MAX_SIZE
=
20000000
TIMEOUT
=
10
BUF_SIZE
=
4096
BUF_START
=
0x80001000
BUF_END
=
0x80002000
mem
=
x393_mem
.
X393Mem
(
debug_mode
,
dry_mode
,
1
)
run
=
True
wp_old
=
BUF_START
time_old
=
time
.
time
()
if
os
.
path
.
isfile
(
filename
):
os
.
remove
(
filename
)
#
#f = open(filename,"w+b")
#mem_write_to_file(mem, f, 0x80001000, 64)
#f.close()
#mem.mem_save(self, filename, start_addr, length)
#sys.exit()
while
(
run
):
if
not
os
.
path
.
isfile
(
filename
):
f
=
open
(
filename
,
"w+b"
)
wp_new
=
get_wp
(
mem
)
if
wp_new
==
wp_old
:
to
=
time
.
time
()
-
time_old
#print("Skipping, dt= "+str(to))
if
to
>
TIMEOUT
:
print
(
"Timeout: "
+
str
(
to
)
+
" s"
)
f
.
close
()
break
else
:
time_old
=
time
.
time
()
l
=
get_len
(
wp_new
,
wp_old
)
if
(
l
<
0
):
#write end
l
=
BUF_END
-
wp_old
mem_write_to_file
(
mem
,
f
,
wp_old
,
l
)
#write_start
l
=
wp_new
-
BUF_START
mem_write_to_file
(
mem
,
f
,
BUF_START
,
l
)
else
:
mem_write_to_file
(
mem
,
f
,
wp_old
,
l
)
#print("Going to write something of size ="+str(l))
wp_old
=
wp_new
if
os
.
path
.
getsize
(
filename
)
>
MAX_SIZE
:
print
(
"Close, then rename"
)
f
.
close
()
os
.
rename
(
filename
,
filename
+
".0"
)
#print(get_wp(mem))
# open file
#with open(filename, "w+b") as bf:
# get pointer and read mem
# write to file
#_mem_write_to_file (self, bf, start_addr, length)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment