Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
Lightsensor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Devices
Lightsensor
Commits
7d08a53f
Commit
7d08a53f
authored
Sep 17, 2015
by
aw613
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SmartSensor reads value from real temperature device
parent
16737d50
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
2 deletions
+146
-2
src/org/ws4d/smartsensor/device/GetTemperatureAction.java
src/org/ws4d/smartsensor/device/GetTemperatureAction.java
+7
-1
src/org/ws4d/smartsensor/device/PhySensor.java
src/org/ws4d/smartsensor/device/PhySensor.java
+68
-0
src/org/ws4d/smartsensor/device/TempReadingThread.java
src/org/ws4d/smartsensor/device/TempReadingThread.java
+65
-0
src/org/ws4d/smartsensor/device/mainclass.java
src/org/ws4d/smartsensor/device/mainclass.java
+6
-1
No files found.
src/org/ws4d/smartsensor/device/GetTemperatureAction.java
View file @
7d08a53f
...
...
@@ -36,8 +36,14 @@ public class GetTemperatureAction extends Operation
public
static
final
String
PARAM_HW_OUTPUT
=
"temperature"
;
//public static final String PARAM_HW_OUTPUT2 = "light";
public
PhySensor
sensor
;
public
GetTemperatureAction
()
{
super
(
ACT_HW_NAME
,
HelloWorldService
.
QN_PORTTYPE
);
sensor
=
new
PhySensor
(
"28-0000045157c3"
);
//Sensor Thread is started in background
Element
temperatureOutput
=
new
Element
(
PARAM_HW_OUTPUT
,
HelloWorldDevice
.
NAMESPACE
,
SchemaUtil
.
TYPE_INT
);
//Parameter lightOutput = new Parameter(PARAM_HW_OUTPUT2, HelloWorldDevice.NAMESPACE, ParameterType.PARAMETER_TYPE_INT);
...
...
@@ -56,7 +62,7 @@ public class GetTemperatureAction extends Operation
ParameterValue
temperatureOutput
=
createOutputValue
();
ParameterValueManagement
.
setString
(
temperatureOutput
,
PARAM_HW_OUTPUT
,
"20"
);
ParameterValueManagement
.
setString
(
temperatureOutput
,
PARAM_HW_OUTPUT
,
Integer
.
toString
(
sensor
.
readSensor
())
);
return
temperatureOutput
;
...
...
src/org/ws4d/smartsensor/device/PhySensor.java
0 → 100644
View file @
7d08a53f
package
org.ws4d.smartsensor.device
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.Reader
;
import
java.util.concurrent.Semaphore
;
public
class
PhySensor
{
private
String
pathtoData
;
int
temperature
;
Semaphore
tempSem
;
public
PhySensor
(
String
SensorID
){
//28-0000045157c3
initSensor
(
SensorID
);
}
private
void
initSensor
(
String
SensorID
){
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"/sys/bus/w1/devices"
).
append
(
"/"
+
SensorID
).
append
(
"/w1_slave"
);
this
.
pathtoData
=
sb
.
toString
();
tempSem
=
new
Semaphore
(
1
);
Thread
tempreadingThread
=
new
Thread
(
new
TempReadingThread
(
tempSem
,
pathtoData
,
this
));
tempreadingThread
.
start
();
}
public
int
readSensor
(){
int
returnTemp
;
try
{
tempSem
.
acquire
();
}
catch
(
InterruptedException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
returnTemp
=
this
.
temperature
;
tempSem
.
release
();
return
returnTemp
;
}
public
void
writetemperature
(
int
temp
){
try
{
tempSem
.
acquire
();
}
catch
(
InterruptedException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
this
.
temperature
=
temp
;
tempSem
.
release
();
}
}
src/org/ws4d/smartsensor/device/TempReadingThread.java
0 → 100644
View file @
7d08a53f
package
org.ws4d.smartsensor.device
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.concurrent.Semaphore
;
public
class
TempReadingThread
implements
Runnable
{
private
String
pathtoData
;
private
int
temperature
;
private
Semaphore
tempSem
;
private
PhySensor
phySensor
;
private
static
int
REFRESHINTERVAL
=
2000
;
//ms
public
TempReadingThread
(
Semaphore
tempSemext
,
String
pathtoDataext
,
PhySensor
phySensor
)
{
this
.
pathtoData
=
pathtoDataext
;
this
.
tempSem
=
tempSemext
;
this
.
phySensor
=
phySensor
;
}
@Override
public
void
run
()
{
File
f
=
new
File
(
pathtoData
);
while
(
true
){
try
{
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
f
));
String
line
=
reader
.
readLine
();
if
(
line
.
substring
(
line
.
length
()-
3
,
line
.
length
()).
equals
(
"YES"
)){
line
=
reader
.
readLine
();
this
.
temperature
=
Integer
.
parseInt
(
line
.
substring
(
line
.
length
()-
5
,
line
.
length
()));
System
.
out
.
println
(
temperature
);
this
.
temperature
/=
1000
;
reader
.
close
();
phySensor
.
writetemperature
(
temperature
);
}
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
try
{
Thread
.
sleep
(
REFRESHINTERVAL
);
}
catch
(
InterruptedException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
}
}
src/org/ws4d/smartsensor/device/mainclass.java
View file @
7d08a53f
package
org.ws4d.smartsensor.device
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
org.ws4d.java.CoreFramework
;
...
...
@@ -9,10 +13,11 @@ import org.ws4d.java.configuration.Properties;
public
class
mainclass
{
public
static
void
main
(
String
[]
args
)
{
CoreFramework
.
start
(
args
);
HelloWorldDevice
device
=
new
HelloWorldDevice
();
HelloWorldDevice
device
=
new
HelloWorldDevice
();
// create service
HelloWorldService
service
=
new
HelloWorldService
();
// set device properties
...
...
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