Skip to content
Snippets Groups Projects
Commit 5ae9e3a2 authored by schneider's avatar schneider
Browse files

hack: write hci layer log file

parent 9ae70996
No related branches found
No related tags found
No related merge requests found
Pipeline #4584 failed
......@@ -12,6 +12,7 @@
#include "FreeRTOS.h"
#include "timers.h"
#include <machine/endian.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
......@@ -44,6 +45,8 @@ static StaticTimer_t x;
static TimerHandle_t timerWakeup = NULL;
static int lasttick = 0;
static int log_fd;
/*! \brief Stack initialization for app. */
extern void StackInit(void);
extern void AppInit(void);
......@@ -70,6 +73,57 @@ static bool_t myTrace(const uint8_t *pBuf, uint32_t len)
return FALSE;
}
struct packet_header {
uint32_t original_length;
uint32_t included_length;
uint32_t packet_flags;
uint32_t cumulative_drops;
uint32_t timestamp_us_h;
uint32_t timestamp_us_l;
};
void WsfPDump(wsfPDumpType_t pdType, uint16_t length, uint8_t *pBuffer)
{
uint32_t direction;
uint8_t type;
switch(pdType) {
case WSF_PDUMP_TYPE_HCI_CMD:
direction = 0;
type = 0x01;
break;
case WSF_PDUMP_TYPE_HCI_EVT:
direction = 1;
type = 0x04;
break;
case WSF_PDUMP_TYPE_HCI_TX_ACL:
direction = 0;
type = 0x02;
break;
case WSF_PDUMP_TYPE_HCI_RX_ACL:
direction = 1;
type = 0x02;
break;
default:
break;
}
int tick = xTaskGetTickCount();
uint64_t timestamp_us = tick * 1000;
struct packet_header header = {
.original_length = __htonl(length+1),
.included_length = __htonl(length+1),
.packet_flags = __htonl(direction),
.cumulative_drops = __htonl(0),
.timestamp_us_h = __htonl(timestamp_us >> 32),
.timestamp_us_l = __htonl(timestamp_us & 0xFFFFFFFF)
};
epic_file_write(log_fd, &header, sizeof(header));
epic_file_write(log_fd, &type, sizeof(type));
epic_file_write(log_fd, pBuffer, length);
}
/*************************************************************************************************/
static void WsfInit(void)
{
......@@ -238,6 +292,13 @@ static void scheduleTimer(void)
APP_TRACE_INFO0("No timer running");
}
}
static const uint8_t log_header[] = {'b', 't', 's', 'n', 'o', 'o', 'p', 0, 0, 0, 0, 1, 0, 0, 0x03, 0xea};
void ble_log_flush(void)
{
epic_file_flush(log_fd);
}
/*************************************************************************************************/
void vBleTask(void *pvParameters)
{
......@@ -248,6 +309,8 @@ void vBleTask(void *pvParameters)
*/
vTaskDelay(pdMS_TO_TICKS(500));
log_fd = epic_file_open("ble.log", "w");
epic_file_write(log_fd, log_header, sizeof(log_header));
/* We are going to execute FreeRTOS functions from callbacks
* coming from this interrupt. Its priority needs to be
* reduced to allow this. */
......
......@@ -369,6 +369,7 @@ static void bleSetup(bleMsg_t *pMsg)
* \return None.
*/
/*************************************************************************************************/
void ble_log_flush(void);
static void bleProcMsg(bleMsg_t *pMsg)
{
uint8_t uiEvent = APP_UI_NONE;
......@@ -397,6 +398,8 @@ static void bleProcMsg(bleMsg_t *pMsg)
case DM_ADV_START_IND:
LOG_INFO("ble", "Advertisement started");
uiEvent = APP_UI_ADV_START;
ble_log_flush();
break;
case DM_ADV_STOP_IND:
......
......@@ -293,14 +293,10 @@ bool_t WsfTokenService(void);
/*! \brief 3 argument HCI error trace. */
#define HCI_TRACE_ERR3(msg, var1, var2, var3) WSF_TRACE3("HCI", "ERR", msg, var1, var2, var3)
/*! \brief HCI PDUMP on command. */
#define HCI_PDUMP_CMD(len, pBuf)
/*! \brief HCI PDUMP on event. */
#define HCI_PDUMP_EVT(len, pBuf)
/*! \brief HCI PDUMP on transmitted ACL message. */
#define HCI_PDUMP_TX_ACL(len, pBuf)
/*! \brief HCI PDUMP on Received ACL message. */
#define HCI_PDUMP_RX_ACL(len, pBuf)
#define HCI_PDUMP_CMD(len, pBuf) WsfPDump(WSF_PDUMP_TYPE_HCI_CMD, len, pBuf)
#define HCI_PDUMP_EVT(len, pBuf) WsfPDump(WSF_PDUMP_TYPE_HCI_EVT, len, pBuf)
#define HCI_PDUMP_TX_ACL(len, pBuf) WsfPDump(WSF_PDUMP_TYPE_HCI_TX_ACL, len, pBuf)
#define HCI_PDUMP_RX_ACL(len, pBuf) WsfPDump(WSF_PDUMP_TYPE_HCI_RX_ACL, len, pBuf)
/*! \brief 0 argument DM info trace. */
#define DM_TRACE_INFO0(msg) WSF_TRACE0("DM", "INFO", msg)
......@@ -622,6 +618,25 @@ bool_t WsfTokenService(void);
#define LL_TRACE_ENABLE(ena)
#endif
/*! Protocol types */
typedef enum
{
WSF_PDUMP_TYPE_HCI_CMD = (1 << 0),
WSF_PDUMP_TYPE_HCI_EVT = (1 << 1),
WSF_PDUMP_TYPE_HCI_TX_ACL = (1 << 2),
WSF_PDUMP_TYPE_HCI_RX_ACL = (1 << 3),
WSF_PDUMP_TYPE_HCI_TX_ISO = (1 << 4),
WSF_PDUMP_TYPE_HCI_RX_ISO = (1 << 5),
WSF_PDUMP_TYPE_NONE = 0,
WSF_PDUMP_TYPE_ALL = 0xFFFF
} wsfPDumpType_t;
/**************************************************************************************************
Function Prototypes
**************************************************************************************************/
void WsfPDump(wsfPDumpType_t pdType, uint16_t length, uint8_t *pBuffer);
/*! \} */ /* WSF_TRACE_API */
#ifdef __cplusplus
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment