Better debugging output

This commit is contained in:
ktownsend 2013-12-18 06:22:35 +00:00
parent a9a8fcf7fb
commit 80f18dad9e

View file

@ -92,14 +92,15 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
uint8_t *buffer;
#if NRF51822_DEBUG_MODE
printf("Configuring Advertising ... ");
printf("%-40s", "Configuring Advertising");
#endif
/* Make sure we support the advertising type */
if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED)
{
#if NRF51822_DEBUG_MODE
printf("ADV_CONNECTABLE_DIRECTED not supported (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_NOT_IMPLEMENTED);
printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_NOT_IMPLEMENTED);
printf("--> ADV_CONNECTABLE_DIRECTED not supported\r\n");
#endif
return BLE_ERROR_NOT_IMPLEMENTED;
}
@ -109,7 +110,8 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
(params.getInterval() > GAP_ADV_PARAMS_INTERVAL_MAX))
{
#if NRF51822_DEBUG_MODE
printf("Advertising interval out of range (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
printf("--> Advertising interval out of range\r\n");
#endif
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
@ -119,7 +121,8 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
(params.getTimeout() != 0))
{
#if NRF51822_DEBUG_MODE
printf("Timeout must be 0 with ADV_CONNECTABLE_DIRECTED (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
printf("--> Timeout must be 0 with ADV_CONNECTABLE_DIRECTED\r\n");
#endif
/* Timeout must be 0 with this type, although we'll never get here */
/* since this isn't implemented yet anyway */
@ -131,7 +134,8 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
(params.getTimeout() > GAP_ADV_PARAMS_TIMEOUT_MAX))
{
#if NRF51822_DEBUG_MODE
printf("Timeout out of range (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
printf("--> Timeout out of range\r\n");
#endif
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
@ -140,7 +144,8 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD)
{
#if NRF51822_DEBUG_MODE
printf("Advertising payload > 31 bytes (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_BUFFER_OVERFLOW);
printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_BUFFER_OVERFLOW);
printf("--> Advertising payload > 31 bytes\r\n");
#endif
return BLE_ERROR_BUFFER_OVERFLOW;
}
@ -151,7 +156,8 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD)
{
#if NRF51822_DEBUG_MODE
printf("Scan response payload > 31 bytes (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_BUFFER_OVERFLOW);
printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_BUFFER_OVERFLOW);
printf("--> Scan response payload > 31 bytes\r\n");
#endif
return BLE_ERROR_BUFFER_OVERFLOW;
}
@ -187,7 +193,7 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
for (uint16_t i = 0; i < len; i++)
{
uart.printf(" %02X", buffer[i]);
}
}
uart.printf("\r\n");
/* ToDo: Check response */
@ -210,7 +216,7 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
}
#if NRF51822_DEBUG_MODE
printf("OK!\r\n");
printf("[OK]\r\n");
#endif
return BLE_ERROR_NONE;
}
@ -234,7 +240,7 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
ble_error_t nRF51822::addService(GattService & service)
{
#if NRF51822_DEBUG_MODE
printf("Adding a service ... ");
printf("%-40s", "Adding a service");
#endif
/* ToDo: Make sure we don't overflow the array, etc. */
@ -296,7 +302,7 @@ ble_error_t nRF51822::addService(GattService & service)
serviceCount++;
#if NRF51822_DEBUG_MODE
printf("OK!\r\n");
printf("[OK]\r\n");
#endif
return BLE_ERROR_NONE;
}
@ -331,13 +337,13 @@ ble_error_t nRF51822::addService(GattService & service)
ble_error_t nRF51822::readCharacteristic(GattService &service, GattCharacteristic &characteristic, uint8_t buffer[], uint16_t len)
{
#if NRF51822_DEBUG_MODE
printf("Reading characteristic (handle = %d) ... ", characteristic.handle);
printf("Reading characteristic (handle = %d) ", characteristic.handle);
#endif
/* ToDo */
#if NRF51822_DEBUG_MODE
printf("OK!\r\n");
printf("[OK]\r\n");
#endif
return BLE_ERROR_NONE;
}
@ -372,7 +378,7 @@ ble_error_t nRF51822::readCharacteristic(GattService &service, GattCharacteristi
ble_error_t nRF51822::writeCharacteristic(GattService &service, GattCharacteristic &characteristic, uint8_t buffer[], uint16_t len)
{
#if NRF51822_DEBUG_MODE
printf("Writing characteristic (handle = %d) ... ", characteristic.handle);
printf("Writing characteristic (handle = %d) ", characteristic.handle);
#endif
/* Command ID = 0x0006, Payload = Service ID, Characteristic ID, Value */
@ -387,7 +393,7 @@ ble_error_t nRF51822::writeCharacteristic(GattService &service, GattCharacterist
wait(0.1);
#if NRF51822_DEBUG_MODE
printf("OK!\r\n");
printf("[OK]\r\n");
#endif
return BLE_ERROR_NONE;
}
@ -414,7 +420,7 @@ ble_error_t nRF51822::writeCharacteristic(GattService &service, GattCharacterist
ble_error_t nRF51822::start(void)
{
#if NRF51822_DEBUG_MODE
printf("Initialising the radio ... ");
printf("%-40s", "Starting the radio");
#endif
/* Command ID = 0x0003, No payload */
@ -424,7 +430,7 @@ ble_error_t nRF51822::start(void)
wait(0.5);
#if NRF51822_DEBUG_MODE
printf("OK!\r\n");
printf("[OK]\r\n");
#endif
return BLE_ERROR_NONE;
}
@ -448,7 +454,7 @@ ble_error_t nRF51822::start(void)
ble_error_t nRF51822::stop(void)
{
#if NRF51822_DEBUG_MODE
printf("Stopping the radio ... ");
printf("%-40s", "Stopping the radio");
#endif
/* Command ID = 0x0004, No payload */
@ -458,7 +464,7 @@ ble_error_t nRF51822::stop(void)
wait(0.1);
#if NRF51822_DEBUG_MODE
printf("OK!\r\n");
printf("[OK]\r\n");
#endif
return BLE_ERROR_NONE;
}
@ -483,7 +489,7 @@ ble_error_t nRF51822::stop(void)
ble_error_t nRF51822::reset(void)
{
#if NRF51822_DEBUG_MODE
printf("Resetting the radio ... ");
printf("%-40s", "Resetting the radio");
#endif
/* Command ID = 0x0005, No payload */
@ -496,7 +502,7 @@ ble_error_t nRF51822::reset(void)
wait(1);
#if NRF51822_DEBUG_MODE
printf("OK!\r\n");
printf("[OK]\r\n");
#endif
return BLE_ERROR_NONE;
}