Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
adc2018-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
adc2018
adc2018-system
Commits
2cda9dfe
Commit
2cda9dfe
authored
Aug 14, 2018
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'comm-client' into 'comm'
Merge comm-client See merge request adc2018/adc2018-system!7
parents
a00ebf58
3b42d302
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
17 deletions
+40
-17
main.py
comm/client/main.py
+8
-9
adc2018solver.py
solver/adc2018solver.py
+32
-8
No files found.
comm/client/main.py
View file @
2cda9dfe
...
...
@@ -21,7 +21,6 @@ import adc2018solver as pynqrouter
app
=
Flask
(
__name__
)
args
=
{}
# pynq_thread = None
client_baseurl
=
""
@
app
.
route
(
'/start'
,
methods
=
[
"POST"
])
...
...
@@ -45,10 +44,15 @@ def start():
qseed
=
request
.
form
[
"qseed"
]
boardstr
=
BoardStr
.
conv_boardstr
(
qstr
.
split
(
'
\n
'
),
'random'
,
int
(
qseed
))
option
=
{
"name"
:
qname
,
"host"
:
args
[
'host'
],
"client"
:
client_baseurl
}
option
=
{
"name"
:
qname
,
"host"
:
args
[
'host'
],
"client"
:
client_baseurl
,
"req_id"
:
request
.
form
[
'req_id'
],
"resolver"
:
request
.
form
[
'resolver'
]
}
pynqrouter
.
start_solver
(
boardstr
,
qseed
,
option
)
# pynq_thread = pynqrouter.start_solver(boardstr, qseed, option)
# 実行だけ開始する
ans
[
"status"
]
=
"Processing"
...
...
@@ -64,8 +68,6 @@ def start():
@
app
.
route
(
'/stop'
)
def
stop
():
# global pynq_thread
if
pynqrouter
.
solver_thread
is
None
:
ans
=
{
"status"
:
"No threads"
}
else
:
...
...
@@ -73,15 +75,11 @@ def stop():
pynqrouter
.
stop_solver
()
ans
=
{
"status"
:
"Stopped"
}
# pynq_thread = None
return
json
.
dumps
(
ans
)
@
app
.
route
(
"/status"
)
def
status
():
# global pynq_thread
res_mes
=
""
if
pynqrouter
.
solver_thread
is
None
:
...
...
@@ -121,3 +119,4 @@ if __name__ == "__main__":
if
args
[
"debug"
]:
app
.
debug
=
True
app
.
run
(
host
=
'0.0.0.0'
,
port
=
args
[
"port"
],
threaded
=
True
)
solver/adc2018solver.py
View file @
2cda9dfe
...
...
@@ -78,6 +78,15 @@ def solve(boardstr, seed=12345, zero_padding=False, option=dict()):
print
(
seed
)
print
(
''
)
res
=
{
'client'
:
option
[
'client'
],
'qname'
:
option
[
'name'
],
'solution'
:
''
,
'cputime'
:
-
1.0
,
'req_id'
:
option
[
'req_id'
],
'solved'
:
False
}
# LINE数を数えてコンフィグするbitstreamを分岐
line_num
=
boardstr
.
count
(
'L'
)
if
line_num
<
127
:
...
...
@@ -89,7 +98,9 @@ def solve(boardstr, seed=12345, zero_padding=False, option=dict()):
else
:
solver_thread
.
stopped
()
solver_thread
=
None
return
{
'solved'
:
False
,
'solution'
:
''
,
'elapsed'
:
-
1.0
}
if
"host"
in
option
:
requests
.
post
(
"http://{}/post"
.
format
(
option
[
'host'
]),
data
=
res
)
return
res
# ボード文字列から X, Y, Z を読んでくる
size_x
=
(
ord
(
boardstr
[
1
])
-
ord
(
'0'
))
*
10
+
(
ord
(
boardstr
[
2
])
-
ord
(
'0'
))
...
...
@@ -137,7 +148,9 @@ def solve(boardstr, seed=12345, zero_padding=False, option=dict()):
if
(
solver_thread
is
not
None
)
and
(
not
solver_thread
.
is_running
()):
solver_thread
.
stopped
()
solver_thread
=
None
return
{
'solved'
:
False
,
'solution'
:
''
,
'elapsed'
:
-
1.0
}
if
"host"
in
option
:
requests
.
post
(
"http://{}/post"
.
format
(
option
[
'host'
]),
data
=
res
)
return
res
# 完了の確認
print
(
'Done!'
)
...
...
@@ -154,11 +167,11 @@ def solve(boardstr, seed=12345, zero_padding=False, option=dict()):
# 解けなかったらLEDを消す
mmio_led
.
write
(
0
,
0
)
sys
.
stderr
.
write
(
'Cannot solve it!
\n
'
)
res
=
{
'client'
:
option
[
'client'
],
'qname'
:
option
[
'name'
],
'answer'
:
''
,
'cputime'
:
-
1
}
if
"host"
in
option
:
requests
.
post
(
"http://{}/post"
.
format
(
option
[
'host'
]),
data
=
res
)
solver_thread
=
None
return
{
'solved'
:
False
,
'solution'
:
''
,
'elapsed'
:
-
1.0
}
return
res
print
(
'Solved!'
)
# 解けたらLEDを全部つける
...
...
@@ -185,13 +198,24 @@ def solve(boardstr, seed=12345, zero_padding=False, option=dict()):
solution
+=
str
(
boards
[
i
])
# 普通に表示
solution
+=
'
\n
'
res
=
{
'client'
:
option
[
'client'
],
'qname'
:
option
[
'name'
],
'solution'
:
solution
,
'cputime'
:
elapsed
,
'req_id'
:
option
[
'req_id'
],
'solved'
:
True
}
if
"resolver"
in
option
:
r
=
requests
.
post
(
"http://{}/post"
.
format
(
option
[
'resolver'
]),
data
=
res
)
elif
"host"
in
option
:
r
=
requests
.
post
(
"http://{}/post"
.
format
(
option
[
'host'
]),
data
=
res
)
if
solver_thread
is
not
None
:
solver_thread
.
stopped
()
res
=
{
'client'
:
option
[
'client'
],
'qname'
:
option
[
'name'
],
'answer'
:
solution
,
'cputime'
:
elapsed
}
if
"host"
in
option
:
r
=
requests
.
post
(
"http://{}/post"
.
format
(
option
[
'host'
]),
data
=
res
)
solver_thread
=
None
return
{
'solved'
:
True
,
'solution'
:
solution
,
'elapsed'
:
elapsed
}
return
res
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
"Solver with pynqrouter"
)
...
...
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