Skip to content

Commit

Permalink
[K32W] Fix logging and README (#2729)
Browse files Browse the repository at this point in the history
* [K32W] Fix logging and README

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

* Restyled by clang-format

* Restyled by prettier-markdown

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
doru91 and restyled-commits authored Sep 22, 2020
1 parent 1fa92b0 commit ebee332
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 62 deletions.
14 changes: 9 additions & 5 deletions examples/lock-app/k32w/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ board.

The K32W lock example application provides a working demonstration of a
connected door lock device, built using CHIP, and the NXP K32W061 SDK. The
functionality at this moment is limited and the demo app can be used for
changing the state of a door lock and also for factoryreset the board. Soon,
functionality for BLE pairing and ZCL control will be added. This will allow a
user to control the door lock using a mobile application (CHIP Tool).
example supports remote access (e.g.: using CHIP Tool from a mobile phone) and
control of a simulated door lock over a low-power, 802.15.4 Thread network. It
is capable of being paired into an existing CHIP network along with other
CHIP-enabled devices.

The example targets the
[NXP K32W061 DK6](https://www.nxp.com/products/wireless/thread/k32w061-41-high-performance-secure-and-ultra-low-power-mcu-for-zigbeethread-and-bluetooth-le-5-0-with-built-in-nfc-option:K32W061_41)
Expand Down Expand Up @@ -81,7 +81,11 @@ position to another.
be used to mimick a user manually operating the lock. The button behaves as a
toggle, swapping the state every time it is pressed.

The remaining two LEDs and buttons (D1/D4 and SW1/SW4) are unused.
**Button SW4** can be used for joining a Thread network advertised by a Border
Router. At this moment, Thread commissioning parameters are hard-coded but a
future PR will add support for transmiting them over BLE.

The remaining two LEDs(D1/D2) and button (SW1) are unused.

<a name="building"></a>

Expand Down
86 changes: 29 additions & 57 deletions src/platform/K32W/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ void FillPrefix(char * buf, uint8_t bufLen, uint8_t chipCategory, uint8_t otLogL
buf[prefixLen++] = ']';
buf[prefixLen++] = ' ';
}

} // unnamed namespace

namespace chip {
Expand All @@ -131,6 +130,32 @@ void __attribute__((weak)) OnLogOutput(void) {}
} // namespace DeviceLayer
} // namespace chip

void GenericLog(const char * format, va_list arg)
{

#if K32W_LOG_ENABLED

char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE - 1] = { 0 };
size_t prefixLen, writtenLen;

/* Prefix is composed of [Debug String][MOdule Name String] */
FillPrefix(formattedMsg, CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE - 1, kLogCategory_None, kLogCategory_Detail,
(uint8_t) kLogModule_NotSpecified);
prefixLen = strlen(formattedMsg);

// Append the log message.
writtenLen = vsnprintf(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen - EOL_CHARS_LEN, format, arg);
VerifyOrDie(writtenLen > 0);
memcpy(formattedMsg + prefixLen + writtenLen, EOL_CHARS, EOL_CHARS_LEN);

K32WWriteBlocking((const uint8_t *) formattedMsg, strlen(formattedMsg));

// Let the application know that a log message has been emitted.
DeviceLayer::OnLogOutput();

#endif // K32W_LOG_ENABLED
}

namespace chip {
namespace Logging {

Expand All @@ -147,19 +172,7 @@ void LogV(uint8_t module, uint8_t category, const char * msg, va_list v)
if (IsCategoryEnabled(category))
{
{
char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE - 1] = { 0 };
size_t prefixLen, writtenLen;

/* Prefix is composed of [Debug String][MOdule Name String] */
FillPrefix(formattedMsg, CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE - 1, category, OT_LOG_LEVEL_NONE, module);
prefixLen = strlen(formattedMsg);

// Append the log message.
writtenLen = vsnprintf(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen - EOL_CHARS_LEN, msg, v);
VerifyOrDie(writtenLen > 0);
memcpy(formattedMsg + prefixLen + writtenLen, EOL_CHARS, EOL_CHARS_LEN);

K32WWriteBlocking((const uint8_t *) formattedMsg, strlen(formattedMsg));
GenericLog(msg, v);
}
}

Expand All @@ -183,28 +196,7 @@ extern "C" void LwIPLog(const char * msg, ...)
va_list v;

va_start(v, msg);

#if K32W_LOG_ENABLED
{
char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE - 1];

// Append the log message.
size_t len = vsnprintf(formattedMsg, sizeof(formattedMsg), msg, v);

while (len > 0 && isspace(formattedMsg[len - 1]))
{
len--;
formattedMsg[len] = 0;
}

K32WWriteBlocking((const uint8_t *) formattedMsg, strlen(formattedMsg));
}

// Let the application know that a log message has been emitted.
DeviceLayer::OnLogOutput();

#endif // K32W_LOG_ENABLED

GenericLog(msg, v);
va_end(v);
}

Expand All @@ -221,27 +213,7 @@ extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const ch
(void) aLogRegion;

va_start(v, aFormat);

#if K32W_LOG_ENABLED
char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE - 1] = { 0 };
size_t prefixLen, writtenLen;

/* Prefix is composed of [Debug String][MOdule Name String] */
FillPrefix(formattedMsg, CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE - 1, kLogCategory_None, aLogLevel,
(uint8_t) kLogModule_NotSpecified);
prefixLen = strlen(formattedMsg);

// Append the log message.
writtenLen = vsnprintf(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen - EOL_CHARS_LEN, aFormat, v);
VerifyOrDie(writtenLen > 0);
memcpy(formattedMsg + prefixLen + writtenLen, EOL_CHARS, EOL_CHARS_LEN);

K32WWriteBlocking((const uint8_t *) formattedMsg, strlen(formattedMsg));

// Let the application know that a log message has been emitted.
DeviceLayer::OnLogOutput();
#endif // K32W_LOG_ENABLED

GenericLog(aFormat, v);
va_end(v);
}

Expand Down

0 comments on commit ebee332

Please sign in to comment.