Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SensorNodeESP8266
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor 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
Proof of Concept
SensorNodeESP8266
Commits
6aab6688
Commit
6aab6688
authored
9 years ago
by
PhiBo
Browse files
Options
Downloads
Patches
Plain Diff
Use template for DataString
parent
423ef53a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/rpc.cpp
+23
-42
23 additions, 42 deletions
src/rpc.cpp
src/sensor_node.h
+10
-6
10 additions, 6 deletions
src/sensor_node.h
with
33 additions
and
48 deletions
src/rpc.cpp
+
23
−
42
View file @
6aab6688
#include
"sensor_node.h"
DataString
::
DataString
(
uint16_t
max_length
)
{
this
->
max_length
=
max_length
;
this
->
data
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
)
*
max_length
);
this
->
length
=
0
;
}
void
DataString
::
reset
()
{
this
->
length
=
0
;
}
size_t
DataString
::
write
(
uint8_t
c
)
{
this
->
data
[
this
->
length
]
=
c
;
this
->
length
++
;
}
ArduRPC_SensorNode
::
ArduRPC_SensorNode
(
ArduRPC
&
rpc
,
char
*
name
)
:
ArduRPCHandler
()
{
this
->
type
=
0x9999
;
this
->
registerSelf
(
rpc
,
name
,
(
void
*
)
this
);
this
->
status
=
0
;
this
->
cache
=
new
DataString
(
1024
);
}
uint8_t
ArduRPC_SensorNode
::
call
(
uint8_t
cmd_id
)
...
...
@@ -44,13 +25,13 @@ uint8_t ArduRPC_SensorNode::call(uint8_t cmd_id)
this
->
sensor_uuid
[
SENSOR_NODE_KEY_MAX_LENGTH
]
=
'\0'
;
this
->
status
=
2
;
this
->
cache
->
reset
();
this
->
cache
->
print
(
"["
);
this
->
cache
.
reset
();
this
->
cache
.
print
(
"["
);
return
RPC_RETURN_SUCCESS
;
}
else
if
(
cmd_id
==
0x11
)
{
/* finish() */
if
(
this
->
status
==
2
or
this
->
status
==
3
)
{
this
->
cache
->
print
(
"]"
);
this
->
cache
.
print
(
"]"
);
}
this
->
status
=
4
;
this
->
submitData
();
...
...
@@ -76,52 +57,52 @@ uint8_t ArduRPC_SensorNode::call(uint8_t cmd_id)
if
(
this
->
status
==
2
)
{
this
->
status
=
3
;
}
else
{
this
->
cache
->
print
(
","
);
this
->
cache
.
print
(
","
);
}
this
->
cache
->
print
(
"["
);
this
->
cache
.
print
(
"["
);
// sensor id
u8
=
this
->
_rpc
->
getParam_uint8
();
this
->
cache
->
print
(
u8
);
this
->
cache
->
print
(
","
);
this
->
cache
.
print
(
u8
);
this
->
cache
.
print
(
","
);
// sensor type
u16
=
this
->
_rpc
->
getParam_uint16
();
this
->
cache
->
print
(
u16
);
this
->
cache
->
print
(
","
);
this
->
cache
.
print
(
u16
);
this
->
cache
.
print
(
","
);
// value type
u8
=
this
->
_rpc
->
getParam_uint8
();
this
->
cache
->
print
(
u8
);
this
->
cache
->
print
(
","
);
this
->
cache
.
print
(
u8
);
this
->
cache
.
print
(
","
);
// value
// - read value type
u8
=
this
->
_rpc
->
getParam_uint8
();
// - read value
if
(
u8
==
RPC_INT8
)
{
i8
=
this
->
_rpc
->
getParam_int8
();
this
->
cache
->
print
(
i8
);
this
->
cache
.
print
(
i8
);
}
else
if
(
u8
==
RPC_UINT8
)
{
u8
=
this
->
_rpc
->
getParam_uint8
();
this
->
cache
->
print
(
u8
);
this
->
cache
.
print
(
u8
);
}
else
if
(
u8
==
RPC_INT16
)
{
i16
=
this
->
_rpc
->
getParam_int16
();
this
->
cache
->
print
(
i16
);
this
->
cache
.
print
(
i16
);
}
else
if
(
u8
==
RPC_UINT16
)
{
u16
=
this
->
_rpc
->
getParam_uint16
();
this
->
cache
->
print
(
u16
);
this
->
cache
.
print
(
u16
);
}
else
if
(
u8
==
RPC_INT32
)
{
i32
=
this
->
_rpc
->
getParam_int32
();
this
->
cache
->
print
(
i32
);
this
->
cache
.
print
(
i32
);
}
else
if
(
u8
==
RPC_UINT32
)
{
u32
=
this
->
_rpc
->
getParam_uint32
();
this
->
cache
->
print
(
u32
);
this
->
cache
.
print
(
u32
);
}
else
if
(
u8
==
RPC_FLOAT
)
{
f
=
this
->
_rpc
->
getParam_float
();
this
->
cache
->
print
(
f
);
this
->
cache
.
print
(
f
);
}
else
{
// value type not supported
this
->
cache
->
print
(
"
\"
n/a
\"
"
);
this
->
cache
.
print
(
"
\"
n/a
\"
"
);
}
this
->
cache
->
print
(
"]"
);
this
->
cache
.
print
(
"]"
);
return
RPC_RETURN_SUCCESS
;
}
return
RPC_RETURN_COMMAND_NOT_FOUND
;
...
...
@@ -153,10 +134,10 @@ void ArduRPC_SensorNode::submitData()
client
->
println
(
this
->
sensor_key
);
client
->
print
(
"X-Sensor-Version: 1
\r\n
"
);
client
->
print
(
"Content-Length: "
);
client
->
println
(
this
->
cache
->
length
);
client
->
println
(
this
->
cache
.
length
);
client
->
println
();
for
(
i
=
0
;
i
<
this
->
cache
->
length
;
i
++
)
{
Serial
.
print
((
char
)
this
->
cache
->
data
[
i
]);
for
(
i
=
0
;
i
<
this
->
cache
.
length
;
i
++
)
{
Serial
.
print
((
char
)
this
->
cache
.
data
[
i
]);
}
this
->
status
=
0
;
client
->
stop
();
...
...
This diff is collapsed.
Click to expand it.
src/sensor_node.h
+
10
−
6
View file @
6aab6688
...
...
@@ -34,16 +34,20 @@
#define SENSOR_NODE_UUID_MAX_LENGTH 64
#define SENSOR_NODE_KEY_MAX_LENGTH 64
template
<
uint16_t
SIZE
>
class
DataString
:
public
Print
{
public:
DataString
(
uint16_t
);
void
reset
();
virtual
size_t
write
(
uint8_t
);
DataString
()
{
this
->
length
=
0
;
};
void
reset
()
{
this
->
length
=
0
;
};
virtual
size_t
write
(
uint8_t
c
)
{
this
->
data
[
this
->
length
]
=
c
;
this
->
length
++
;
};
uint16_t
length
;
uint8_t
*
data
;
uint8_t
data
[
SIZE
]
;
private
:
uint16_t
max_length
;
uint16_t
max_length
=
SIZE
;
};
class
ArduRPC_SensorNode
:
public
ArduRPCHandler
...
...
@@ -55,7 +59,7 @@ class ArduRPC_SensorNode : public ArduRPCHandler
void
ICACHE_FLASH_ATTR
submitData
();
private:
uint8_t
status
;
DataString
*
cache
;
DataString
<
1024
>
cache
;
char
sensor_uuid
[
SENSOR_NODE_UUID_MAX_LENGTH
+
1
];
char
sensor_key
[
SENSOR_NODE_UUID_MAX_LENGTH
+
1
];
};
...
...
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