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
0181898d
Commit
0181898d
authored
6 years ago
by
aht2nguy
Browse files
Options
Downloads
Patches
Plain Diff
sensors working BUT showing 2 copies at a time
parent
98472a1a
No related branches found
Branches containing commit
No related tags found
2 merge requests
!16
Withtime
,
!15
Samplek4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/sensors.h
+2
-1
2 additions, 1 deletion
include/sensors.h
include/types.h
+3
-1
3 additions, 1 deletion
include/types.h
lib/sensors.c
+77
-73
77 additions, 73 deletions
lib/sensors.c
with
82 additions
and
75 deletions
include/sensors.h
+
2
−
1
View file @
0181898d
...
...
@@ -60,8 +60,9 @@ The s88 units can be told to reset its memory after a dump to the computer, or i
void
SensorPrintTask
();
void
ProcessSensors
(
char
*
SensorInput
,
char
*
Chars
,
char
*
Nums
,
int
*
FirstFullLoop
,
int
*
NumSensors
);
//
void ProcessSensors(char* SensorInput, char*
Sensor
Chars, char*
SensorNums
, int* NumSensors);
void
ProcessData
(
int
*
Sensors
,
char
*
SensorChars
,
int
*
SensorNums
);
void
SensorServer
();
void
SensorNotifier
();
...
...
This diff is collapsed.
Click to expand it.
include/types.h
+
3
−
1
View file @
0181898d
...
...
@@ -90,7 +90,9 @@ typedef enum SensorServerMessageType {
typedef
struct
SensorServerMessage
{
SSMsgType
Type
;
char
*
SensorInput
;
// char* SensorInput;
char
*
SensorChars
;
int
*
SensorNums
;
}
SSMsg
;
...
...
This diff is collapsed.
Click to expand it.
lib/sensors.c
+
77
−
73
View file @
0181898d
...
...
@@ -10,89 +10,73 @@
#include
<clockserver-api.h>
#include
<td-shared.h>
void
SensorPrintTask
()
{
void
SensorPrintTask
()
{
//char* SensorChars, int* SensorNums) {
SSMsg
SendMsg
,
ReplyMsg
;
int
i
,
j
,
ColPos
;
char
*
SensorChars
,
*
SensorNums
,
*
pChars
,
*
pNums
;
int
NumSensors
=
0
;
int
FirstFullLoop
=
0
;
int
i
,
ColPos
;
char
*
SensorChars
;
int
*
SensorNums
;
char
SensorServerName
[]
=
"SensorServer"
;
int
SensorServerID
=
WhoIs
(
SensorServerName
);
int
SensorServerID
=
WhoIs
(
SensorServerName
);
//MyParentTid();
// char ClkServerName[] = "ClockServer";
// int ClkServerID = WhoIs(ClkServerName);
FOREVER
{
SendMsg
.
Type
=
SENSOR_QUERY
;
Send
(
SensorServerID
,
(
void
*
)
&
SendMsg
,
sizeof
(
SSMsg
),
(
void
*
)
&
ReplyMsg
,
sizeof
(
ReplyMsg
));
ProcessSensors
(
ReplyMsg
.
SensorInput
,
SensorChars
,
SensorNums
,
&
FirstFullLoop
,
&
NumSensors
);
NumSensors
=
NumSensors
<
NUM_SENSORS_DISPLAYED
?
NumSensors
:
NUM_SENSORS_DISPLAYED
;
if
(
FirstFullLoop
&&
(
NumSensors
<
NUM_SENSORS_DISPLAYED
))
{
// Printf(COM2,"a\n\r");
// int Diff = NUM_SENSORS_DISPLAYED - NumSensors;
for
(
i
=
0
;
i
<
NUM_SENSORS_DISPLAYED
;
i
++
)
{
// j = (MAX_NUM_SENSORS-Diff + i) % MAX_NUM_SENSORS;
j
=
NumSensors
-
1
;
if
(
j
<
0
)
j
+=
80
;
pChars
[
i
]
=
SensorChars
[
j
];
pNums
[
i
]
=
SensorNums
[
j
];
}
}
else
{
// Printf(COM2,"b\n\r");
for
(
i
=
0
;
i
<
NumSensors
;
i
++
)
{
pChars
[
i
]
=
SensorChars
[
NumSensors
-
i
-
1
];
pNums
[
i
]
=
SensorNums
[
NumSensors
-
i
-
1
];
}
}
if
(
NumSensors
)
{
// Printf(COM2,"NS %d \n\r", NumSensors);
for
(
i
=
0
;
i
<
NumSensors
;
i
++
)
{
//Printf(COM2, "%d\n\r", SensorNums[i]);
ColPos
=
11
+
i
*
5
;
if
((
int
)
pNums
[
i
]
<
10
)
{
Printf
(
COM2
,
"%s%c[19;%dH%c0%d%s"
,
SAVE_CURSOR
,
27
,
ColPos
,
pChars
[
i
],
(
int
)
pNums
[
i
],
RESTORE_CURSOR
);
//Printf(COM2,"y");
}
else
{
Printf
(
COM2
,
"%s%c[19;%dH%c%d%s"
,
SAVE_CURSOR
,
27
,
ColPos
,
pChars
[
i
],
(
int
)
pNums
[
i
],
RESTORE_CURSOR
);
//Printf(COM2,"x");
}
}
SensorChars
=
ReplyMsg
.
SensorChars
;
SensorNums
=
ReplyMsg
.
SensorNums
;
for
(
i
=
0
;
i
<
NUM_SENSORS_DISPLAYED
;
i
++
)
{
ColPos
=
11
+
i
*
5
;
if
(
SensorNums
[
i
]
<
10
)
Printf
(
COM2
,
"%s%c[19;%dH%c0%d%s"
,
SAVE_CURSOR
,
27
,
ColPos
,
SensorChars
[
i
],
SensorNums
[
i
],
RESTORE_CURSOR
);
else
Printf
(
COM2
,
"%s%c[19;%dH%c%d%s"
,
SAVE_CURSOR
,
27
,
ColPos
,
SensorChars
[
i
],
SensorNums
[
i
],
RESTORE_CURSOR
);
// Printf(COM2,"SPT %c%d\n\r",SensorChars[i],SensorNums[i]);
}
}
}
void
ProcessSensors
(
char
*
SensorInput
,
char
*
Chars
,
char
*
Nums
,
int
*
FirstFullLoop
,
int
*
NumSensors
)
{
int
i
,
j
,
SensorNum
,
Index
,
First
;
int
Num
,
Temp
;
}
void
ProcessData
(
int
*
Sensors
,
char
*
SensorChars
,
int
*
SensorNums
)
{
int
i
,
j
,
Num
,
SensorNum
,
Index
,
First
;
char
SensorChar
;
// Printf(COM2,"PS %s\n\r",SensorInput);
int
Temp
=
0
;
char
LookUpOffset
[
10
]
=
"EAABBCCDDE"
;
for
(
i
=
0
;
i
<
NUM_SENSORS_READ
;
i
++
)
{
SensorChar
=
'A'
+
(
i
/
2
);
SensorChar
=
LookUpOffset
[
i
];
//
'A' + (i/2);
First
=
i
%
2
;
Index
=
1
;
Num
=
128
;
Temp
=
(
int
)
SensorInput
[
i
];
FOREVER
{
if
(
Temp
==
0
)
break
;
if
(
Temp
>=
Num
)
{
if
(
Sensors
[
i
]
==
0
)
break
;
// Printf(COM2,"Char %c\n\r", SensorChar);
// Printf(COM2,"NumTotal %d\n\r", Sensors[i]);
if
(
Sensors
[
i
]
>=
Num
)
{
SensorNum
=
First
*
8
+
Index
;
Temp
-=
Num
;
// Printf(COM2,"here1\n\r");
Chars
[
*
NumSensors
]
=
SensorChar
;
Nums
[
*
NumSensors
]
=
(
char
)
SensorNum
;
//char or break
// Printf(COM2,"%c%d ",SensorChar,SensorNum);
*
NumSensors
+=
1
;
if
(
*
NumSensors
==
MAX_NUM_SENSORS
)
{
*
FirstFullLoop
=
1
;
*
NumSensors
=
0
;
}
// Printf(COM2,"Sensor Num %d\n\r", SensorNum);
Sensors
[
i
]
-=
Num
;
//if ((SensorChar != SensorChars[0]) || (SensorNum != SensorNums[0])) {
// Temp++;
for
(
j
=
NUM_SENSORS_DISPLAYED
-
1
;
j
>
0
;
j
--
)
{
SensorChars
[
j
]
=
SensorChars
[
j
-
1
];
SensorNums
[
j
]
=
SensorNums
[
j
-
1
];
}
SensorChars
[
0
]
=
SensorChar
;
SensorNums
[
0
]
=
(
SensorNum
+
8
)
%
16
?
(
SensorNum
+
8
)
%
16
:
16
;
// Printf(COM2,"ProcessData %c%d\n\r",SensorChars[0],SensorNums[0]);
//}
}
Num
/=
2
;
Index
++
;
}
//Printf(COM2, " NS%d ", *NumSensors);
}
// Printf(COM2,"In array:%d\n\r", Temp);
}
void
SensorServer
()
{
...
...
@@ -102,12 +86,13 @@ void SensorServer() {
Message
RcvSlot
;
RcvSlot
.
Addr
=
(
void
*
)(
&
RcvMsg
);
Buffer
SendQ
;
char
*
SensorInput
;
int
*
SensorNums
;
char
*
SensorChars
;
int
i
,
ColPos
;
AP
Args
;
Buffer
WL
;
int
WLStorage
[
MAX_NUM_TD
];
InitBuffer
(
&
WL
,(
void
*
)
WLStorage
,
(
int
)(
MAX_NUM_TD
));
Buffer
**
AllSendQ
=
GetAllSendQ
();
...
...
@@ -133,32 +118,42 @@ void SensorServer() {
if
(
bReceived
==
0
){
Res
=
Receive
(
SenderID
,
(
void
*
)
&
RcvSlot
,
sizeof
(
SSMsg
));
SenderID
=
RcvSlot
.
SenderID
;
// Printf(COM2,"bReceived == 0 SensorID %d SendQLen %d Temp %d\n\r", SenderID, SendQ.Length, RcvMsg.Type);
}
bReceived
=
0
;
// Printf(COM2,"bReceived == 1 SensorID %d SendQLen %d Type %d\n\r", SenderID, SendQ.Length, RcvMsg.Type);
switch
(
RcvMsg
.
Type
){
case
SENSOR_QUERY
:
// Putc(COM2,'q');
// Printf(COM2,"SensorQuery ID %d SendQLen %d\n\r", SenderID, SendQ.Length);
FeedBuffer
(
&
WL
,
(
void
*
)
SenderID
);
break
;
case
SENSOR_NOTIFIER
:
//Putc(COM2,'t');
//Printf(COM2,"SensorNotifier\n\r");
ReplyMsg
.
Type
=
SENSOR_RESPONSE
;
Reply
(
SenderID
,
(
void
*
)
&
ReplyMsg
,
sizeof
(
ReplyMsg
));
SensorInput
=
RcvMsg
.
SensorInput
;
// Printf(COM2,"SS %s\n\r",SensorInput);
SensorChars
=
RcvMsg
.
SensorChars
;
SensorNums
=
RcvMsg
.
SensorNums
;
while
(
WL
.
Length
>
0
)
{
// Putc(COM2,'l');
BufferFIFO
(
&
WL
,
(
void
*
)
&
SenderID
);
ReplyMsg
.
SensorInput
=
SensorInput
;
// Printf(COM2,"SenderID in loop %d", SenderID);
ReplyMsg
.
SensorChars
=
SensorChars
;
ReplyMsg
.
SensorNums
=
SensorNums
;
Reply
(
SenderID
,
(
void
*
)
&
ReplyMsg
,
sizeof
(
SSMsg
));
BufferPopHead
(
&
WL
);
}
break
;
default:
Printf
(
COM2
,
"Sensor Server: Unrecognized RcvMsg Type.
\n\r
"
);
break
;
}
}
else
{
bReceived
=
1
;
// Printf(COM2, "SS ABOUT TO Block\n\r");
Receive
(
-
1
,
(
void
*
)
&
RcvSlot
,
sizeof
(
SSMsg
));
SenderID
=
RcvSlot
.
SenderID
;
Res
=
0
;
...
...
@@ -167,26 +162,35 @@ void SensorServer() {
}
void
SensorNotifier
()
{
char
SensorInput
[
NUM_SENSORS_READ
];
SSMsg
SendMsg
,
ReplyMsg
;
int
i
;
int
Sensors
[
NUM_SENSORS_READ
];
char
SensorChars
[
NUM_SENSORS_DISPLAYED
];
int
SensorNums
[
NUM_SENSORS_DISPLAYED
];
SSMsg
SendMsg
,
ReplyMsg
;
char
SensorServerName
[]
=
"SensorServer"
;
int
SensorServerID
=
WhoIs
(
SensorServerName
);
// Getc(COM1); // to get rid of the first byte TC sends
for
(
i
=
0
;
i
<
NUM_SENSORS_DISPLAYED
;
i
++
)
{
SensorChars
[
i
]
=
'\0'
;
SensorNums
[
i
]
=
0
;
}
FOREVER
{
Putc
(
COM1
,
SENSOR_RESET
);
Putc
(
COM1
,
SENSOR_REQUEST
);
// 128 + 5 modules
for
(
i
=
0
;
i
<
NUM_SENSORS_READ
;
i
++
)
{
Sensor
Input
[
i
]
=
Getc
(
COM1
);
Sensor
s
[
i
]
=
Getc
(
COM1
);
}
//SensorGetStr(COM1, 10);
//Printf(COM2,"SNotif %s\n\r",SensorInput);
ProcessData
(
Sensors
,
SensorChars
,
SensorNums
);
SendMsg
.
Type
=
SENSOR_NOTIFIER
;
SendMsg
.
SensorInput
=
SensorInput
;
SendMsg
.
SensorChars
=
SensorChars
;
SendMsg
.
SensorNums
=
SensorNums
;
Send
(
SensorServerID
,
(
void
*
)
&
SendMsg
,
sizeof
(
SSMsg
),
(
void
*
)
&
ReplyMsg
,
sizeof
(
SSMsg
));
}
}
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