Skip to content

Commit

Permalink
FW-867: Log the length of thee ECHO received message
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyClaeys committed Jun 1, 2020
1 parent 249b6ef commit 5bfb53b
Show file tree
Hide file tree
Showing 37 changed files with 566 additions and 943 deletions.
45 changes: 15 additions & 30 deletions drivers/common/openserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

openserial_vars_t openserial_vars;

#define DEBUGPRINT_PERIOD 100 // in ms
#define STATUSPRINT_PERIOD 100 // in ms

//=========================== prototypes ======================================

Expand Down Expand Up @@ -103,27 +103,20 @@ void openserial_init(void) {
openserial_vars.debugPrint_timerId = opentimers_create(TIMER_GENERAL_PURPOSE, TASKPRIO_OPENSERIAL);
opentimers_scheduleIn(
openserial_vars.debugPrint_timerId,
DEBUGPRINT_PERIOD,
STATUSPRINT_PERIOD,
TIME_MS,
TIMER_PERIODIC,
openserial_debugPrint_timer_cb
);

// UART
uart_setCallbacks(
isr_openserial_tx,
isr_openserial_rx
);
uart_setCallbacks(isr_openserial_tx, isr_openserial_rx);
uart_enableInterrupts();
}

//===== transmitting

owerror_t openserial_printStatus(
uint8_t statusElement,
uint8_t *buffer,
uint8_t length
) {
owerror_t openserial_printStatus(uint8_t statusElement, uint8_t *buffer, uint8_t length) {
uint8_t i;

outputHdlcOpen();
Expand Down Expand Up @@ -153,22 +146,22 @@ owerror_t openserial_printLog(
char severity;

switch (log_level) {
case LOG_VERBOSE:
case VERBOSE:
severity = SERFRAME_MOTE2PC_VERBOSE;
break;
case LOG_INFO:
case INFO:
severity = SERFRAME_MOTE2PC_INFO;
break;
case LOG_WARNING:
case WARNING:
severity = SERFRAME_MOTE2PC_WARNING;
break;
case LOG_SUCCESS:
case SUCCESS:
severity = SERFRAME_MOTE2PC_SUCCESS;
break;
case LOG_ERROR:
case ERROR:
severity = SERFRAME_MOTE2PC_ERROR;
break;
case LOG_CRITICAL:
case CRITICAL:
severity = SERFRAME_MOTE2PC_CRITICAL;
// blink error LED, this is serious
leds_error_blink();
Expand Down Expand Up @@ -428,13 +421,9 @@ uint8_t openserial_getInputBuffer(uint8_t *bufferToWrite, uint8_t maxNumBytes) {
//>>>>>>>>>>>>>>>>>>>>>>>

if (maxNumBytes < inputBufFillLevel - 1) {
openserial_printLog(
LOG_ERROR,
COMPONENT_OPENSERIAL,
ERR_GETDATA_ASKS_TOO_FEW_BYTES,
(errorparameter_t) maxNumBytes,
(errorparameter_t) inputBufFillLevel - 1
);
LOG_ERROR(COMPONENT_OPENSERIAL, ERR_GETDATA_ASKS_TOO_FEW_BYTES,
(errorparameter_t) maxNumBytes,
(errorparameter_t) inputBufFillLevel - 1);
numBytesWritten = 0;
} else {
numBytesWritten = inputBufFillLevel - 1;
Expand Down Expand Up @@ -757,16 +746,12 @@ port_INLINE void inputHdlcClose(void) {

void task_printInputBufferOverflow(void) {
// input buffer overflow
openserial_printLog(LOG_ERROR, COMPONENT_OPENSERIAL, ERR_INPUT_BUFFER_OVERFLOW,
(errorparameter_t) 0,
(errorparameter_t) 0);
LOG_ERROR(COMPONENT_OPENSERIAL, ERR_INPUT_BUFFER_OVERFLOW, (errorparameter_t) 0, (errorparameter_t) 0);
}

void task_printWrongCRCInput(void) {
// invalid HDLC frame
openserial_printLog(LOG_ERROR, COMPONENT_OPENSERIAL, ERR_WRONG_CRC_INPUT,
(errorparameter_t) 0,
(errorparameter_t) 0);
LOG_ERROR(COMPONENT_OPENSERIAL, ERR_WRONG_CRC_INPUT, (errorparameter_t) 0, (errorparameter_t) 0);
}

//=========================== interrupt handlers ==============================
Expand Down
53 changes: 47 additions & 6 deletions drivers/common/openserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,56 @@
#define SERFRAME_PC2MOTE_DATA ((uint8_t)'D')
#define SERFRAME_PC2MOTE_TRIGGERSERIALECHO ((uint8_t)'S')

//=========================== macros =========================================

#ifndef OPENWSN_DEBUG_LEVEL
#define OPENWSN_DEBUG_LEVEL 4
#endif

#if (OPENWSN_DEBUG_LEVEL >= 6)
#define LOG_VERBOSE(component, message, p1, p2) openserial_printLog(VERBOSE, (component), (message), (p1), (p2))
#else
#define LOG_VERBOSE(component, message, p1, p2)
#endif

#if (OPENWSN_DEBUG_LEVEL >= 5)
#define LOG_INFO(component, message, p1, p2) openserial_printLog(INFO, (component), (message), (p1), (p2))
#else
#define LOG_INFO(component, message, p1, p2)
#endif

#if (OPENWSN_DEBUG_LEVEL >= 4)
#define LOG_WARNING(component, message, p1, p2) openserial_printLog(WARNING, (component), (message), (p1), (p2))
#else
#define LOG_WARNING(component, message, p1, p2)
#endif

#if (OPENWSN_DEBUG_LEVEL >= 3)
#define LOG_SUCCESS(component, message, p1, p2) openserial_printLog(SUCCESS, (component), (message), (p1), (p2))
#else
#define LOG_SUCCESS(component, message, p1, p2)
#endif

#if (OPENWSN_DEBUG_LEVEL >= 2)
#define LOG_ERROR(component, message, p1, p2) openserial_printLog(ERROR, (component), (message), (p1), (p2))
#else
#define LOG_ERROR(component, message, p1, p2)
#endif

#if (OPENWSN_DEBUG_LEVEL >= 1)
#define LOG_CRITICAL(component, message, p1, p2) openserial_printLog(CRITICAL, (component), (message), (p1), (p2))
#else
#define LOG_CRITICAL(component, message, p1, p2)
#endif
//=========================== typedef =========================================

enum {
LOG_VERBOSE,
LOG_INFO,
LOG_WARNING,
LOG_SUCCESS,
LOG_ERROR,
LOG_CRITICAL
CRITICAL = 1,
ERROR = 2,
SUCCESS = 3,
WARNING = 4,
INFO = 5,
VERBOSE = 6
};

//=========================== variables =======================================
Expand Down
29 changes: 28 additions & 1 deletion inc/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
#ifndef OPENWSN_CONFIG_H
#define OPENWSN_CONFIG_H

// =========================== Debugging ============================

/**
* \def OPENWSN_DEBUG_LEVEL
*
* Specifies the debugging level used in the OpenWSN stack.
* - level 0: no debugging
* - level 1: only critical logs
* - level 2: critical and error logs
* - level 3: critical, error, and success
* - level 4: critical, error, success, and warning
* - level 5: critical, error, success, warning, and info
* - level 6: critical, error, success, warning, info, and verbose
*
*/

#define OPENWSN_DEBUG_LEVEL 6

// ========================== Applications ==========================

/**
Expand Down Expand Up @@ -255,14 +273,23 @@


/**
* \def OPENWSN_IEEE802154E_SINGLE_CHANNEL
* \def IEEE802154E_SINGLE_CHANNEL
*
* Sets channel to a fixed value (acceptable values are [11 - 26] and [0])
* When the channel is set to 0, frequency hopping is enabled, otherwise a single channel is used.
*
*/
#define IEEE802154E_SINGLE_CHANNEL 11

/**
* \def PACKETQUEUE_LENGTH
*
* Specifies the size of the packet queue. Large queue sizes are required to support fragmentation but significantly
* increase RAM usage.
*
*/
#define PACKETQUEUE_LENGTH 10

// ======================== Board configuration ========================

/**
Expand Down
8 changes: 4 additions & 4 deletions inc/opendefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
\author Luigi Alfredo Grieco <alfredo.grieco@poliba.it>
*/

#ifndef __OPENDEFS_H
#define __OPENDEFS_H
#ifndef OPENWSN_OPENDEFS_H
#define OPENWSN_OPENDEFS_H

// general
#include <stdint.h> // needed for uin8_t, uint16_t
Expand Down Expand Up @@ -207,7 +207,7 @@ enum {
ERR_UNSUPPORTED_PORT_NUMBER = 0x09, // unsupported port number {0} (code location {1})
ERR_INVALID_CHECKSUM = 0x0a, // invalid checksum, expected 0x{:04x}, found 0x{:04x}
// l3
ERR_RCVD_ECHO_REQUEST = 0x0b, // received an echo request
ERR_RCVD_ECHO_REQUEST = 0x0b, // received an echo request (length: {0})
ERR_RCVD_ECHO_REPLY = 0x0c, // received an echo reply
ERR_6LORH_DEADLINE_EXPIRED = 0x0d, // the received packet has expired
ERR_6LORH_DEADLINE_DROPPED = 0x0e, // packet expiry time reached, dropped
Expand Down Expand Up @@ -432,4 +432,4 @@ END_PACK

//=========================== prototypes ======================================

#endif
#endif /* OPENWSN_OPENDEFS_H */
8 changes: 1 addition & 7 deletions openapps/cexample/cexample.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,7 @@ void cexample_task_cb(void) {
// create a CoAP RD packet
pkt = openqueue_getFreePacketBuffer(COMPONENT_CEXAMPLE);
if (pkt == NULL) {
openserial_printLog(
LOG_ERROR,
COMPONENT_CEXAMPLE,
ERR_NO_FREE_PACKET_BUFFER,
(errorparameter_t) 0,
(errorparameter_t) 0
);
LOG_ERROR(COMPONENT_CEXAMPLE, ERR_NO_FREE_PACKET_BUFFER, (errorparameter_t) 0, (errorparameter_t) 0);
return;
}
// take ownership over that packet
Expand Down
1 change: 0 additions & 1 deletion openapps/cinfo/cinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "coap.h"
#include "openqueue.h"
#include "packetfunctions.h"
#include "openserial.h"
#include "openrandom.h"
#include "board.h"
#include "idmanager.h"
Expand Down
20 changes: 4 additions & 16 deletions openapps/cjoin/cjoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,7 @@ void cjoin_retransmission_task_cb(void) {
joinProxy = neighbors_getJoinProxy();
if (joinProxy == NULL) {
// keep the retransmission timer, in case it synchronized at next time
openserial_printLog(
LOG_WARNING,
COMPONENT_CJOIN,
ERR_ABORT_JOIN_PROCESS,
(errorparameter_t) 0,
(errorparameter_t) 0
);
LOG_WARNING(COMPONENT_CJOIN, ERR_ABORT_JOIN_PROCESS, (errorparameter_t) 0, (errorparameter_t) 0);
return;
}

Expand Down Expand Up @@ -264,13 +258,7 @@ owerror_t cjoin_sendJoinRequest(open_addr_t *joinProxy) {
// create a CoAP RD packet
pkt = openqueue_getFreePacketBuffer(COMPONENT_CJOIN);
if (pkt == NULL) {
openserial_printLog(
LOG_ERROR,
COMPONENT_CJOIN,
ERR_NO_FREE_PACKET_BUFFER,
(errorparameter_t) 0,
(errorparameter_t) 0
);
LOG_ERROR(COMPONENT_CJOIN, ERR_NO_FREE_PACKET_BUFFER, (errorparameter_t) 0, (errorparameter_t) 0);
return E_FAIL;
}

Expand Down Expand Up @@ -313,7 +301,7 @@ owerror_t cjoin_sendJoinRequest(open_addr_t *joinProxy) {
memcpy(pkt->payload, tmp, payload_len);
// send

openserial_printLog(LOG_VERBOSE, COMPONENT_CJOIN, ERR_JOIN_REQUEST, (errorparameter_t) 0, (errorparameter_t) 0);
LOG_VERBOSE(COMPONENT_CJOIN, ERR_JOIN_REQUEST, (errorparameter_t) 0, (errorparameter_t) 0);

outcome = coap_send(
pkt,
Expand Down Expand Up @@ -365,7 +353,7 @@ void cjoin_setIsJoined(bool newValue) {

if (newValue == TRUE) {
// log the info
openserial_printLog(LOG_SUCCESS, COMPONENT_CJOIN, ERR_JOINED, (errorparameter_t) 0, (errorparameter_t) 0);
LOG_SUCCESS(COMPONENT_CJOIN, ERR_JOINED, (errorparameter_t) 0, (errorparameter_t) 0);
}
}

8 changes: 1 addition & 7 deletions openapps/csensors/csensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,7 @@ void csensors_task_cb(void) {
// create a CoAP RD packet
pkt = openqueue_getFreePacketBuffer(COMPONENT_CSENSORS);
if (pkt == NULL) {
openserial_printLog(
LOG_ERROR,
COMPONENT_CSENSORS,
ERR_NO_FREE_PACKET_BUFFER,
(errorparameter_t) 0,
(errorparameter_t) 0
);
LOG_ERROR(COMPONENT_CSENSORS, ERR_NO_FREE_PACKET_BUFFER, (errorparameter_t) 0, (errorparameter_t) 0);
return;
}

Expand Down
4 changes: 1 addition & 3 deletions openapps/cstorm/cstorm.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ void cstorm_task_cb(void) {
// get a packet
pkt = openqueue_getFreePacketBuffer(COMPONENT_CSTORM);
if (pkt == NULL) {
openserial_printLog(LOG_ERROR, COMPONENT_CSTORM, ERR_NO_FREE_PACKET_BUFFER,
(errorparameter_t) 0,
(errorparameter_t) 0);
LOG_ERROR(COMPONENT_CSTORM, ERR_NO_FREE_PACKET_BUFFER, (errorparameter_t) 0, (errorparameter_t) 0);
return;
}

Expand Down
1 change: 0 additions & 1 deletion openapps/cwellknown/cwellknown.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "coap.h"
#include "openqueue.h"
#include "packetfunctions.h"
#include "openserial.h"
#include "idmanager.h"

//=========================== variables =======================================
Expand Down
4 changes: 1 addition & 3 deletions openapps/rrt/rrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ void rrt_sendCoAPMsg(char actionMsg, uint8_t *ipv6mote) {

pkt = openqueue_getFreePacketBuffer(COMPONENT_RRT);
if (pkt == NULL) {
openserial_printLog(LOG_ERROR, COMPONENT_RRT, ERR_BUSY_SENDING,
(errorparameter_t) 0,
(errorparameter_t) 0);
LOG_ERROR(COMPONENT_RRT, ERR_BUSY_SENDING, (errorparameter_t) 0, (errorparameter_t) 0);
return;
}

Expand Down
8 changes: 1 addition & 7 deletions openapps/uecho/uecho.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ void uecho_receive(OpenQueueEntry_t *request) {
reply = openqueue_getFreeBigPacketBuffer(COMPONENT_UECHO);

if (reply == NULL) {
openserial_printLog(
LOG_ERROR,
COMPONENT_UECHO,
ERR_NO_FREE_PACKET_BUFFER,
(errorparameter_t) 0,
(errorparameter_t) 0
);
LOG_ERROR(COMPONENT_UECHO, ERR_NO_FREE_PACKET_BUFFER, (errorparameter_t) 0, (errorparameter_t) 0);
openqueue_freePacketBuffer(request); //clear the request packet as well
return;
}
Expand Down
8 changes: 1 addition & 7 deletions openapps/uexpiration/uexpiration.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,7 @@ void uexpiration_task_cb(void) {

reply = openqueue_getFreePacketBuffer(COMPONENT_UEXPIRATION);
if (reply == NULL) {
openserial_printLog(
LOG_ERROR,
COMPONENT_UEXPIRATION,
ERR_NO_FREE_PACKET_BUFFER,
(errorparameter_t) 0,
(errorparameter_t) 0
);
LOG_ERROR(COMPONENT_UEXPIRATION, ERR_NO_FREE_PACKET_BUFFER, (errorparameter_t) 0, (errorparameter_t) 0);
return;
}

Expand Down
Loading

0 comments on commit 5bfb53b

Please sign in to comment.