Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs452Trainee
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tom Feng
cs452Trainee
Commits
82383601
Commit
82383601
authored
6 years ago
by
Tom Feng
Browse files
Options
Downloads
Patches
Plain Diff
final
parent
e3bcdeb0
No related branches found
Branches containing commit
No related tags found
1 merge request
!16
Withtime
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
lib/k4.c
+7
-6
7 additions, 6 deletions
lib/k4.c
lib/sensors.c
+5
-4
5 additions, 4 deletions
lib/sensors.c
lib/tools.c
+8
-2
8 additions, 2 deletions
lib/tools.c
lib/train-controller.c
+6
-1
6 additions, 1 deletion
lib/train-controller.c
lib/traintask.c
+15
-3
15 additions, 3 deletions
lib/traintask.c
with
41 additions
and
16 deletions
lib/k4.c
+
7
−
6
View file @
82383601
...
...
@@ -140,11 +140,11 @@ void FirstUserTask() {
// COM2 IOServer
Args
.
arg0
=
(
void
*
)
4
;
Args
.
arg0
=
(
void
*
)
12
;
Args
.
arg1
=
(
void
*
)
(
&
IServer2
);
tid
=
Create
(
&
Args
);
Args
.
arg0
=
(
void
*
)
4
;
Args
.
arg0
=
(
void
*
)
12
;
Args
.
arg1
=
(
void
*
)
(
&
OServer2
);
tid
=
Create
(
&
Args
);
...
...
@@ -165,7 +165,7 @@ void FirstUserTask() {
Args
.
arg1
=
(
void
*
)
(
&
TermOutNotifier
);
tid
=
Create
(
&
Args
);
// COM1 IO server
Args
.
arg0
=
(
void
*
)
3
;
Args
.
arg0
=
(
void
*
)
7
;
Args
.
arg1
=
(
void
*
)
(
&
IServer1
);
tid
=
Create
(
&
Args
);
//Delay(clkid,1);
...
...
@@ -174,7 +174,7 @@ void FirstUserTask() {
//Delay(clkid,1);
//bwprintf(COM2,"FUT: IS2 %d\n\r",tid);
Args
.
arg0
=
(
void
*
)
3
;
Args
.
arg0
=
(
void
*
)
7
;
Args
.
arg1
=
(
void
*
)
(
&
OServer1
);
tid
=
Create
(
&
Args
);
//bwprintf(COM2,"FUT: OS1 %d\n\r",tid);
...
...
@@ -270,17 +270,18 @@ void FirstUserTask() {
Delay
(
clkid
,
1
);
Args
.
arg0
=
(
void
*
)
4
;
Args
.
arg0
=
(
void
*
)
5
;
Args
.
arg1
=
(
void
*
)(
&
SensorPrintTask
);
tid
=
Create
(
&
Args
);
Delay
(
clkid
,
1
);
Args
.
arg0
=
(
void
*
)
3
;
Args
.
arg0
=
(
void
*
)
4
;
Args
.
arg1
=
(
void
*
)(
&
SensorNotifier
);
tid
=
Create
(
&
Args
);
Delay
(
clkid
,
1
);
Args
.
arg0
=
(
void
*
)
12
;
Args
.
arg1
=
(
void
*
)(
&
PathRouter
);
tid
=
Create
(
&
Args
);
...
...
This diff is collapsed.
Click to expand it.
lib/sensors.c
+
5
−
4
View file @
82383601
...
...
@@ -190,10 +190,11 @@ void SensorNotifier() {
int
counter
=
0
;
const
int
*
Universal
=
GetShared
();
Printf
(
COM2
,
"%s%c[%d;%dHSensor Notifier On%s"
,
SAVE_CURSOR
,
ESC
,
20
,
80
,
RESTORE_CURSOR
);
Putc
(
COM1
,
SENSOR_RESET
);
FOREVER
{
//Printf(COM1, "%c%c",SENSOR_RESET,SENSOR_REQUEST);
Putc
(
COM1
,
SENSOR_REQUEST
);
Printf
(
COM1
,
"%c%c"
,
SENSOR_RESET
,
SENSOR_REQUEST
);
//Putc(COM1,SENSOR_RESET);
//Putc(COM1,SENSOR_REQUEST);
SendMsg
.
TimeStamp
=
*
Universal
;
/*
for (i = 0; i < NUM_SENSORS_READ; i++) {
...
...
@@ -216,7 +217,7 @@ void SensorNotifier() {
Send
(
SensorServerID
,
(
void
*
)
&
SendMsg
,
sizeof
(
SSMsg
),
(
void
*
)
&
ReplyMsg
,
sizeof
(
int
));
bRead
=
0
;
}
Delay
(
ClkID
,
5
);
Delay
(
ClkID
,
10
);
}
}
This diff is collapsed.
Click to expand it.
lib/tools.c
+
8
−
2
View file @
82383601
...
...
@@ -318,8 +318,11 @@ char RegTrack(Train* T){
if
(
SensorD
>
D
){
Temp
=
T
->
LocBase
;
while
(
Temp
->
num
!=
T
->
NNext
->
num
){
Temp
->
TrainOwn
=
TrainID
;
Temp
->
reverse
->
TrainOwn
=
TrainID
;
bReg
=
(
!
(
Temp
->
TrainOwn
))
||
(
Temp
->
TrainOwn
==
TrainID
);
if
(
bReg
){
Temp
->
TrainOwn
=
TrainID
;
Temp
->
reverse
->
TrainOwn
=
TrainID
;
}
else
return
bReg
;
if
(
Temp
->
type
==
NODE_EXIT
)
break
;
switch
(
Temp
->
type
){
case
NODE_BRANCH
:
...
...
@@ -353,7 +356,10 @@ void FreeTrack(Train* T){
char
Dir
=
DIR_AHEAD
;
Temp
=
(
Temp
->
edge
)[
Dir
].
dest
;
int
TrainID
=
T
->
TrainID
;
int
counter
=
0
;
while
(
Temp
->
TrainOwn
==
TrainID
){
Printf
(
COM2
,
"%s%c[%d;%dHFreeT:%s %s"
,
SAVE_CURSOR
,
ESC
,
48
,
80
+
(
counter
<<
2
),
Temp
->
name
,
RESTORE_CURSOR
);
counter
++
;
Temp
->
TrainOwn
=
0
;
Temp
->
reverse
->
TrainOwn
=
0
;
switch
(
Temp
->
type
){
...
...
This diff is collapsed.
Click to expand it.
lib/train-controller.c
+
6
−
1
View file @
82383601
...
...
@@ -41,7 +41,9 @@ void TrainTask(){
MyTrain
->
NNext
=
GetNextSensor
(
MyTrain
->
Next
,
1
);
Printf
(
COM2
,
"%s%c[%d;%dH%d%s"
,
SAVE_CURSOR
,
ESC
,
28
+
MyTrain
->
Index
,
3
,
MyTrain
->
TrainID
,
RESTORE_CURSOR
);
RegTrack
(
MyTrain
);
if
(
RegTrack
(
MyTrain
)){
Printf
(
COM2
,
"%s%c[%d;%dH%d Failed!%s"
,
SAVE_CURSOR
,
ESC
,
28
+
MyTrain
->
Index
,
60
,
MyTrain
->
TrainID
,
RESTORE_CURSOR
);
}
FOREVER
{
// location
if
(
MyTrain
->
bChanged
){
...
...
@@ -68,6 +70,9 @@ void TrainTask(){
Printf
(
COM2
,
"%s%c[%d;%dHLast:%d,StopDist:%d %s"
,
SAVE_CURSOR
,
ESC
,
28
+
MyTrain
->
Index
,
80
,
0
,(
int
)
MyTrain
->
StopDist
,
RESTORE_CURSOR
);
}
//clear out
PRINTAT
(
28
+
MyTrain
->
Index
,
105
,
" "
);
TrackNode
*
Temp
=
MyTrain
->
LocBase
;
int
counter
=
0
;
char
Dir
;
...
...
This diff is collapsed.
Click to expand it.
lib/traintask.c
+
15
−
3
View file @
82383601
...
...
@@ -59,6 +59,7 @@ int UpdateTrain(Train* Trains, char* Sensors,int TimeStamp,int* Diner){
Diner
[
i
]
=
(
TimeStamp
+
(
int
)(
Trains
[
i
].
Dist
/
Trains
[
i
].
DymVel
));
// free the path behind it
if
(
!
RegTrack
(
&
Trains
[
i
])){
Printf
(
COM2
,
"%s%c[%d;%dHFailed!%s"
,
SAVE_CURSOR
,
ESC
,
28
+
i
,
58
,
RESTORE_CURSOR
);
Trains
[
i
].
Speed
=
0
;
Trains
[
i
].
bChanged
=
1
;
Printf
(
COM1
,
"%c%c"
,
0
,
Trains
[
i
].
TrainID
);
...
...
@@ -95,7 +96,9 @@ void UpdateNextOrNot(Train* TList,TrackNode* Switch,int *Dinner,const int* Unive
if
(
CurrentNext
==
SNextCur
){
if
(
CurrentNNext
==
SNextLast
){
TList
[
i
].
NNext
=
SNextCur
;
RegTrack
(
&
TList
[
i
]);
if
(
!
RegTrack
(
&
TList
[
i
])){
Printf
(
COM2
,
"%s%c[%d;%dHFailed!%s"
,
SAVE_CURSOR
,
ESC
,
28
+
i
,
58
,
RESTORE_CURSOR
);
}
TList
[
i
].
bChanged
=
1
;
}
else
continue
;
...
...
@@ -106,7 +109,9 @@ void UpdateNextOrNot(Train* TList,TrackNode* Switch,int *Dinner,const int* Unive
Dinner
[
i
]
=
(
*
Universal
+
((
Dist
-
TList
[
i
].
LocOff
)
/
TList
[
i
].
DymVel
)
+
10
);
TList
[
i
].
NNext
=
GetNextSensor
(
TList
[
i
].
Next
,
1
);
TList
[
i
].
Dist
=
Dist
;
RegTrack
(
&
TList
[
i
]);
if
(
!
RegTrack
(
&
TList
[
i
])){
Printf
(
COM2
,
"%s%c[%d;%dHFailed!%s"
,
SAVE_CURSOR
,
ESC
,
28
+
i
,
58
,
RESTORE_CURSOR
);
}
TList
[
i
].
bChanged
=
1
;
}
else
continue
;
}
...
...
@@ -128,6 +133,11 @@ void ReverseUpdate(Train* T,int TimeStamp,int *Dinner){
T
->
bChanged
=
1
;
int
Dist
=
T
->
Dist
;
Dist
=
Dist
-
T
->
LocOff
;
if
(
RegTrack
(
T
)){
Printf
(
COM2
,
"%s%c[%d;%dHFailed!%s"
,
SAVE_CURSOR
,
ESC
,
28
+
T
->
Index
,
58
,
RESTORE_CURSOR
);
FreeTrack
(
T
);
//}else{
}
if
(
T
->
Speed
){
*
Dinner
=
(
TimeStamp
+
(
int
)(
Dist
/
T
->
DymVel
));
}
else
{
...
...
@@ -157,7 +167,9 @@ void UpdateTrainSpeed(Train* T,int TimeStamp,int *Dinner){
Dist
=
Dist
-
T
->
LocOff
;
if
(
T
->
Speed
){
*
Dinner
=
(
TimeStamp
+
(
int
)(
Dist
/
T
->
DymVel
));
RegTrack
(
T
);
if
(
!
RegTrack
(
T
)){
Printf
(
COM2
,
"%s%c[%d;%dHFailed!%s"
,
SAVE_CURSOR
,
ESC
,
28
+
T
->
Index
,
58
,
RESTORE_CURSOR
);
}
}
else
{
if
((
T
->
Dist
-
T
->
LocOff
)
<
(
int
)
StpD
){
*
Dinner
=
(
TimeStamp
+
(
int
)(
Dist
/
BackUpV
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment