Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
cm-projects
RIOT
Commits
f3b4e44a
Commit
f3b4e44a
authored
6 years ago
by
Koen Zandberg
Browse files
Options
Downloads
Patches
Plain Diff
examples/nanocoap: add blockwise block2 example
parent
551b3513
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
examples/nanocoap_server/Makefile
+1
-1
1 addition, 1 deletion
examples/nanocoap_server/Makefile
examples/nanocoap_server/coap_handler.c
+39
-0
39 additions, 0 deletions
examples/nanocoap_server/coap_handler.c
with
40 additions
and
1 deletion
examples/nanocoap_server/Makefile
+
1
−
1
View file @
f3b4e44a
...
...
@@ -11,7 +11,7 @@ BOARD_INSUFFICIENT_MEMORY := arduino-duemilanove arduino-mega2560 arduino-uno \
chronos msb-430 msb-430h nucleo-f031k6
\
nucleo-f042k6 nucleo-l031k6 nucleo-f030r8
\
nucleo-f303k8 nucleo-l053r8 stm32f0discovery
\
telosb waspmote-pro z1
telosb waspmote-pro
wsn430-v1_3b wsn430-v1_4
z1
# Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
...
...
This diff is collapsed.
Click to expand it.
examples/nanocoap_server/coap_handler.c
+
39
−
0
View file @
f3b4e44a
...
...
@@ -17,6 +17,10 @@
/* internal value that can be read/written via CoAP */
static
uint8_t
internal_value
=
0
;
static
const
uint8_t
block2_intro
[]
=
"This is RIOT (Version: "
;
static
const
uint8_t
block2_board
[]
=
" running on a "
;
static
const
uint8_t
block2_mcu
[]
=
" board with a "
;
static
ssize_t
_riot_board_handler
(
coap_pkt_t
*
pkt
,
uint8_t
*
buf
,
size_t
len
,
void
*
context
)
{
(
void
)
context
;
...
...
@@ -24,6 +28,40 @@ static ssize_t _riot_board_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, vo
COAP_FORMAT_TEXT
,
(
uint8_t
*
)
RIOT_BOARD
,
strlen
(
RIOT_BOARD
));
}
static
ssize_t
_riot_block2_handler
(
coap_pkt_t
*
pkt
,
uint8_t
*
buf
,
size_t
len
,
void
*
context
)
{
(
void
)
context
;
coap_block_slicer_t
slicer
;
coap_block2_init
(
pkt
,
&
slicer
);
uint8_t
*
payload
=
buf
+
coap_get_total_hdr_len
(
pkt
);
uint8_t
*
bufpos
=
payload
;
bufpos
+=
coap_put_option_ct
(
bufpos
,
0
,
COAP_FORMAT_TEXT
);
bufpos
+=
coap_opt_put_block2
(
bufpos
,
COAP_OPT_CONTENT_FORMAT
,
&
slicer
,
1
);
*
bufpos
++
=
0xff
;
/* Add actual content */
bufpos
+=
coap_blockwise_put_bytes
(
&
slicer
,
bufpos
,
block2_intro
,
sizeof
(
block2_intro
));
bufpos
+=
coap_blockwise_put_bytes
(
&
slicer
,
bufpos
,
(
uint8_t
*
)
RIOT_VERSION
,
sizeof
(
RIOT_VERSION
));
bufpos
+=
coap_blockwise_put_char
(
&
slicer
,
bufpos
,
')'
);
bufpos
+=
coap_blockwise_put_bytes
(
&
slicer
,
bufpos
,
block2_board
,
sizeof
(
block2_board
));
bufpos
+=
coap_blockwise_put_bytes
(
&
slicer
,
bufpos
,
(
uint8_t
*
)
RIOT_BOARD
,
sizeof
(
RIOT_BOARD
));
bufpos
+=
coap_blockwise_put_bytes
(
&
slicer
,
bufpos
,
block2_mcu
,
sizeof
(
block2_mcu
));
bufpos
+=
coap_blockwise_put_bytes
(
&
slicer
,
bufpos
,
(
uint8_t
*
)
RIOT_MCU
,
sizeof
(
RIOT_MCU
));
/* To demonstrate individual chars */
bufpos
+=
coap_blockwise_put_char
(
&
slicer
,
bufpos
,
' '
);
bufpos
+=
coap_blockwise_put_char
(
&
slicer
,
bufpos
,
'M'
);
bufpos
+=
coap_blockwise_put_char
(
&
slicer
,
bufpos
,
'C'
);
bufpos
+=
coap_blockwise_put_char
(
&
slicer
,
bufpos
,
'U'
);
bufpos
+=
coap_blockwise_put_char
(
&
slicer
,
bufpos
,
'.'
);
unsigned
payload_len
=
bufpos
-
payload
;
return
coap_block2_build_reply
(
pkt
,
COAP_CODE_205
,
buf
,
len
,
payload_len
,
&
slicer
);
}
static
ssize_t
_riot_value_handler
(
coap_pkt_t
*
pkt
,
uint8_t
*
buf
,
size_t
len
,
void
*
context
)
{
(
void
)
context
;
...
...
@@ -109,6 +147,7 @@ const coap_resource_t coap_resources[] = {
COAP_WELL_KNOWN_CORE_DEFAULT_HANDLER
,
{
"/riot/board"
,
COAP_GET
,
_riot_board_handler
,
NULL
},
{
"/riot/value"
,
COAP_GET
|
COAP_PUT
|
COAP_POST
,
_riot_value_handler
,
NULL
},
{
"/riot/ver"
,
COAP_GET
,
_riot_block2_handler
,
NULL
},
{
"/sha256"
,
COAP_POST
,
_sha256_handler
,
NULL
},
};
...
...
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