Skip to content

Commit

Permalink
connect sensors to the cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
mbialon committed Jun 20, 2015
1 parent 3cf97f9 commit 61c1d44
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 260 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all:
gcc -Wall -o coap endpoints.c main-posix.c coap.c -DDEBUG
gcc -Wall -o coap main-posix.c coap.c -DDEBUG

clean:
rm -f coap
32 changes: 28 additions & 4 deletions coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <stddef.h>
#include "coap.h"

extern void endpoint_setup(void);
extern const coap_endpoint_t endpoints[];
//extern void endpoint_setup(void);
//extern const coap_endpoint_t endpoints[];

#ifdef DEBUG
void coap_dumpHeader(coap_header_t *hdr)
Expand Down Expand Up @@ -360,6 +360,18 @@ void coap_option_nibble(uint8_t value, uint8_t *nibble)
}
}

int coap_add_option(coap_packet_t *pkt, uint8_t num, const uint8_t *p, size_t len)
{
if (pkt->numopts == MAXOPT) {
return 1;
}
coap_option_t *opt = &pkt->opts[pkt->numopts++];
opt->num = num;
opt->buf.p = p;
opt->buf.len = len;
return 0;
}

int coap_make_response(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const uint8_t *content, size_t content_len, uint8_t msgid_hi, uint8_t msgid_lo, const coap_buffer_t* tok, coap_responsecode_t rspcode, coap_content_type_t content_type)
{
pkt->hdr.ver = 0x01;
Expand Down Expand Up @@ -389,14 +401,26 @@ int coap_make_response(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const uint
return 0;
}

int coap_make_request(coap_packet_t *pkt)
{
pkt->hdr.ver = 0x01;
pkt->hdr.t = COAP_TYPE_CON;
pkt->hdr.tkl = 0;
pkt->hdr.code = 2;
pkt->hdr.id[0] = 0;
pkt->hdr.id[1] = 0;
pkt->numopts = 0;
pkt->payload.len = 0;
return 0;
}

// FIXME, if this looked in the table at the path before the method then
// it could more easily return 405 errors
int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt)
int coap_handle_req(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt)
{
const coap_option_t *opt;
uint8_t count;
int i;
const coap_endpoint_t *ep = endpoints;

while(NULL != ep->handler)
{
Expand Down
9 changes: 7 additions & 2 deletions coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ typedef enum
COAP_CONTENTTYPE_NONE = -1, // bodge to allow us not to send option block
COAP_CONTENTTYPE_TEXT_PLAIN = 0,
COAP_CONTENTTYPE_APPLICATION_LINKFORMAT = 40,
COAP_CONTENTTYPE_OCTET_STREAM = 42
} coap_content_type_t;

///////////////////////
Expand Down Expand Up @@ -152,10 +153,14 @@ const coap_option_t *coap_findOptions(const coap_packet_t *pkt, uint8_t num, uin
int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt);
void coap_dump(const uint8_t *buf, size_t buflen, bool bare);
int coap_make_response(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const uint8_t *content, size_t content_len, uint8_t msgid_hi, uint8_t msgid_lo, const coap_buffer_t* tok, coap_responsecode_t rspcode, coap_content_type_t content_type);
int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt);
int coap_handle_req(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt);
void coap_option_nibble(uint8_t value, uint8_t *nibble);
void coap_setup(void);
void endpoint_setup(void);

//void endpoint_setup(void);

int coap_make_request(coap_packet_t *pkt);
int coap_add_option(coap_packet_t *pkt, uint8_t num, const uint8_t *p, size_t len);

#ifdef __cplusplus
}
Expand Down
113 changes: 0 additions & 113 deletions endpoints.c

This file was deleted.

71 changes: 0 additions & 71 deletions main-posix.c

This file was deleted.

Loading

0 comments on commit 61c1d44

Please sign in to comment.