Skip to content

Commit

Permalink
adding more type specificity
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertLRead committed Sep 21, 2020
1 parent 11dbb04 commit f2c10ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions pirds_library/PIRDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ as a C file.

/* Fill the byte buffer with a PIRDS-standard bytes from the
Measurement Object */
int fill_byte_buffer_measurement(Measurement* m,uint8_t* buff,unsigned blim) {
int fill_byte_buffer_measurement(Measurement* m,uint8_t* buff,uint16_t blim) {
buff[0] = m->event;
buff[1] = m->type;
buff[2] = m->loc;
Expand All @@ -64,7 +64,7 @@ int fill_byte_buffer_measurement(Measurement* m,uint8_t* buff,unsigned blim) {
return 0;
}

Measurement get_measurement_from_buffer(uint8_t* buff,unsigned blim) {
Measurement get_measurement_from_buffer(uint8_t* buff,uint16_t blim) {
Measurement m;
m.event = buff[0];
m.type = buff[1];
Expand All @@ -75,7 +75,7 @@ Measurement get_measurement_from_buffer(uint8_t* buff,unsigned blim) {
return m;
}

int fill_JSON_buffer_measurement(Measurement* m,char* buff,unsigned blim) {
int fill_JSON_buffer_measurement(Measurement* m,char* buff,uint16_t blim) {
int rval = sprintf(buff,
"{ \"event\": \"M\", \"type\": \"%c\", \"ms\": %lu, \"loc\": \"%c\", \"num\": %u, \"val\": %ld }",
m->type,
Expand Down Expand Up @@ -155,7 +155,7 @@ int assign_value_measurement(Measurement *m,char* k, char*v) {

// Note: This is a VERY weak and specialized JSON parser
// This will fail if a string contains a colon!!!
Measurement get_measurement_from_JSON(char* buff,unsigned blim) {
Measurement get_measurement_from_JSON(char* buff,uint16_t blim) {
int i = 0;
Measurement m;
// char *scratch = strtok(buff, "{,:}");
Expand All @@ -177,7 +177,7 @@ Measurement get_measurement_from_JSON(char* buff,unsigned blim) {



int fill_byte_buffer_message(Message* m,uint8_t* buff,unsigned blim) {
int fill_byte_buffer_message(Message* m,uint8_t* buff,uint16_t blim) {
buff[0] = m->event;
buff[1] = m->type;
*((uint32_t *) &buff[2]) = htonl(m->ms);
Expand All @@ -188,7 +188,7 @@ int fill_byte_buffer_message(Message* m,uint8_t* buff,unsigned blim) {
return 0;
}

Message get_message_from_buffer(uint8_t* buff,unsigned blim) {
Message get_message_from_buffer(uint8_t* buff,uint16_t blim) {
Message m;
m.event = buff[0];
m.type = buff[1];
Expand All @@ -202,7 +202,7 @@ Message get_message_from_buffer(uint8_t* buff,unsigned blim) {
}

// Need to work out the limit math better...
int fill_JSON_buffer_message(Message* m,char* buff,unsigned blim) {
int fill_JSON_buffer_message(Message* m,char* buff,uint16_t blim) {
char str_buff[257];

strcpy(str_buff,m->buff);
Expand Down Expand Up @@ -252,7 +252,7 @@ int assign_value_message(Message *m,char* k, char*v) {
return 1;
}

Message get_message_from_JSON(char* buff,unsigned blim) {
Message get_message_from_JSON(char* buff,uint16_t blim) {

int i = 0;
Message m;
Expand Down
16 changes: 8 additions & 8 deletions pirds_library/PIRDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,23 @@ typedef struct Message

/* Fill the byte buffer with a PIRDS-standard bytes from the
Measurement Object */
int fill_byte_buffer_measurement(Measurement* m,uint8_t* buff,unsigned blim);
int fill_byte_buffer_measurement(Measurement* m,uint8_t* buff,uint16_t blim);

Measurement get_measurement_from_buffer(uint8_t* buff,unsigned blim);
Measurement get_measurement_from_buffer(uint8_t* buff,uint16_t blim);

int fill_JSON_buffer_measurement(Measurement* m,char* buff,unsigned blim);
int fill_JSON_buffer_measurement(Measurement* m,char* buff,uint16_t blim);

Measurement get_measurement_from_JSON(char* buff,unsigned blim);
Measurement get_measurement_from_JSON(char* buff,uint16_t blim);



int fill_byte_buffer_message(Message* m,uint8_t* buff,unsigned blim);
int fill_byte_buffer_message(Message* m,uint8_t* buff,uint16_t blim);

Message get_message_from_buffer(uint8_t* buff,unsigned blim);
Message get_message_from_buffer(uint8_t* buff,uint16_t blim);

int fill_JSON_buffer_message(Message* m,char* buff,unsigned blim);
int fill_JSON_buffer_message(Message* m,char* buff,uint16_t blim);

Message get_message_from_JSON(char* buff,unsigned blim);
Message get_message_from_JSON(char* buff,uint16_t blim);


/* PLACEHOLDERS
Expand Down
8 changes: 4 additions & 4 deletions pirds_library/test_PIRDS.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static char *test_can_create_Measurement_and_read_back_as_byte_buffer() {
Measurement m = {
'M','T',101,'B',3,-10115
};
const unsigned BUFF_SIZE = 13;
const uint16_t BUFF_SIZE = 13;
uint8_t buff[BUFF_SIZE];
int err = fill_byte_buffer_measurement(&m,buff,BUFF_SIZE);
Measurement mp = get_measurement_from_buffer(buff,BUFF_SIZE);
Expand All @@ -32,7 +32,7 @@ static char *test_can_create_Measurement_and_read_back_as_JSON() {
Measurement m = {
'M','T',101,'B',3,-10115
};
const unsigned BUFF_SIZE = 256;
const uint16_t BUFF_SIZE = 256;
char buff[BUFF_SIZE];
int err = fill_JSON_buffer_measurement(&m,buff,BUFF_SIZE);
mu_assert("buffer problem", err > 0);
Expand Down Expand Up @@ -74,7 +74,7 @@ static char *test_can_create_Message_and_read_back_as_byte_buffer() {
Message m = {
'E','M',4000,18,"Buckminster Fuller"
};
const unsigned BUFF_SIZE = 18+7;
const uint16_t BUFF_SIZE = 18+7;
uint8_t buff[BUFF_SIZE];
int err = fill_byte_buffer_message(&m,buff,BUFF_SIZE);
Message mp = get_message_from_buffer(buff,BUFF_SIZE);
Expand All @@ -91,7 +91,7 @@ static char *test_can_create_Message_and_read_back_as_JSON() {
Message m = {
'E','M',4000,18,"Buckminster Fuller"
};
const unsigned BUFF_SIZE = 256+7;
const uint16_t BUFF_SIZE = 256+7;
char buff[BUFF_SIZE];
int err = fill_JSON_buffer_message(&m,buff,BUFF_SIZE);
mu_assert("buffer problem", err > 0);
Expand Down

0 comments on commit f2c10ef

Please sign in to comment.