Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: IoT_LED_demo ServoTest uWater_Project hackathon ... more
Revision 5:a929d65eb385, committed 2015-01-28
- Comitter:
- ansond
- Date:
- Wed Jan 28 14:43:46 2015 +0000
- Parent:
- 4:84159d67d32d
- Child:
- 6:516a88842a2b
- Commit message:
- updates should be close to final
Changed in this revision
--- a/api/DynamicResource.cpp Wed Jan 28 12:11:22 2015 +0000
+++ b/api/DynamicResource.cpp Wed Jan 28 14:43:46 2015 +0000
@@ -67,7 +67,6 @@
{
if (p != NULL) {
sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s *)p;
- std::printf("DynamicResource: name[%s] type:[%s] mask: 0x%.2x\r\n",this->getName().c_str(),this->m_res_type.c_str(),this->m_res_mask);
const uint8_t *name = (const uint8_t *)(this->getName().c_str());
const uint8_t *res_type = (const uint8_t *)this->m_res_type.c_str();
int name_length = this->getName().size();
@@ -77,9 +76,9 @@
const string *key = new string(this->getName());
ipt_helper_add_instance_pointer(key,this);
nsdl_create_dynamic_resource(resource_ptr,name_length,(uint8_t *)name,res_type_length,(uint8_t *)res_type,is_observable,&ipt_helper_nsdl_callback_stub,this->m_res_mask);
- std::printf("DynamicResource[%s(%d)] type: %s(%d) bound mask: 0x%.2x\r\n",name,name_length,res_type,res_type_length,this->m_res_mask);
+ this->logger()->log("DynamicResource: [%s] type: [%s] bound",name,res_type);
} else {
- std::printf("DynamicResource: NULL parameter in bind()\r\n");
+ this->logger()->log("DynamicResource: NULL parameter in bind()");
}
}
@@ -92,17 +91,16 @@
string key = this->coapDataToString(received_coap_ptr->uri_path_ptr,received_coap_ptr->uri_path_len);
if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) {
- std::printf("GET requested for [%s]...\r\n",key.c_str());
coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
// process the GET if we have registered a callback for it...
if ((this->m_res_mask&SN_GRS_GET_ALLOWED) != 0) {
// call the resource get() to get the resource value
- std::printf("Calling resource(GET) for [%s]...\r\n",key.c_str());
+ this->logger()->log("Calling resource(GET) for [%s]...",key.c_str());
string value = this->get();
// convert the string from the GET to something suitable for CoAP payloads
- std::printf("Building payload for [%s]=[%s]...\r\n",key.c_str(),value.c_str());
+ this->logger()->log("Building payload for [%s]=[%s]...",key.c_str(),value.c_str());
int length = value.size();
char value_buffer[MAX_VALUE_BUFFER_LENGTH+1];
if (length > MAX_VALUE_BUFFER_LENGTH) length = MAX_VALUE_BUFFER_LENGTH;
@@ -116,10 +114,9 @@
// build out the response and send...
sn_nsdl_send_coap_message(address, coap_res_ptr);
} else {
- std::printf("ERROR: resource(GET) mask is munged (mask: 0x%x)\r\n",this->m_res_mask);
+ this->logger()->log("ERROR: resource(GET) mask is munged (mask: 0x%x)",this->m_res_mask);
}
} else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) {
- std::printf("PUT requested for [%s]...\r\n",key.c_str());
if(received_coap_ptr->payload_len > 0) {
// process the PUT if we have registered a callback for it...
if ((this->m_res_mask&SN_GRS_PUT_ALLOWED) != 0) {
@@ -127,18 +124,18 @@
string value = this->coapDataToString(received_coap_ptr->payload_ptr,received_coap_ptr->payload_len);
// call the resource put() to set the resource value
- std::printf("Calling resource(PUT) with [%s]=[%s]...\r\n",key.c_str(),value.c_str());
+ this->logger()->log("Calling resource(PUT) with [%s]=[%s]...",key.c_str(),value.c_str());
this->put(value);
// build out the response and send...
- std::printf("resource(PUT) completed for [%s]...\r\n",key.c_str());
+ this->logger()->log("resource(PUT) completed for [%s]...",key.c_str());
coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
sn_nsdl_send_coap_message(address, coap_res_ptr);
} else {
- std::printf("ERROR: resource(PUT) mask is munged (mask: 0x%x)\r\n",this->m_res_mask);
+ this->logger()->log("ERROR: resource(PUT) mask is munged (mask: 0x%x)",this->m_res_mask);
}
} else {
- std::printf("ERROR: Binder(PUT) payload is NULL...\r\n");
+ this->logger()->log("ERROR: Binder(PUT) payload is NULL...");
}
}
--- a/api/Endpoint.cpp Wed Jan 28 12:11:22 2015 +0000
+++ b/api/Endpoint.cpp Wed Jan 28 14:43:46 2015 +0000
@@ -25,6 +25,9 @@
// support for temporary mbedEndpointLib calls...
#include "mbedEndpointLib.h"
+// Tasklet ID
+int main_tasklet_id = -1;
+
// Connector namespace
namespace Connector {
@@ -47,10 +50,9 @@
{
}
-// plumb network
-void Endpoint::plumbNetwork(bool canActAsRouterNode)
-{
- // call into mbedEndpointLib for now...
+// Plumb the network
+void Endpoint::plumbNetwork(bool canActAsRouterNode) {
+ // call into mbedEndpointLib directly for now... (TODO: wont be able to (re)set MAC address in OptionsBuilder as its already been plumbed here...)
init_network(canActAsRouterNode);
}
@@ -58,7 +60,7 @@
void Endpoint::initialize()
{
// Create the NSDL Resource Pointer...
- std::printf("Endpoint::initialize(): initializing NSP resource pointer...\r\n");
+ this->logger()->log("Endpoint::initialize(): initializing NSP resource pointer...");
sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s));
if(!resource_ptr) return;
memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s));
@@ -71,18 +73,18 @@
memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
// Loop through Static Resources and bind each of them...
- std::printf("Endpoint::initialize(): adding static resources...\r\n");
+ this->logger()->log("Endpoint::initialize(): adding static resources...");
const StaticResourcesList *static_resources = this->m_options->getStaticResourceList();
for(int i=0; i<static_resources->size(); ++i) {
- std::printf("Endpoint::initialize(): binding static resource: [%s]...\r\n",static_resources->at(i)->getName().c_str());
+ this->logger()->log("Endpoint::initialize(): binding static resource: [%s]...",static_resources->at(i)->getName().c_str());
static_resources->at(i)->bind(resource_ptr);
}
// Loop through Dynamic Resources and bind each of them...
- std::printf("Endpoint::initialize(): adding dynamic resources...\r\n");
+ this->logger()->log("Endpoint::initialize(): adding dynamic resources...");
const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList();
for(int i=0; i<dynamic_resources->size(); ++i) {
- std::printf("Endpoint::initialize(): binding dynamic resource: [%s]...\r\n",dynamic_resources->at(i)->getName().c_str());
+ this->logger()->log("Endpoint::initialize(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getName().c_str());
dynamic_resources->at(i)->bind(resource_ptr);
}
@@ -98,26 +100,32 @@
void Endpoint::initNetwork()
{
// register with NSP
- DBG("Calling NSP_registration()...\r\n");
+ this->logger()->log("Calling NSP_registration()...");
NSP_registration();
- DBG("NSP_registration() completed\r\n");
+ this->logger()->log("NSP_registration() completed");
}
-// Finalize the endpoint's configuration and begin the endpoint's main even loop
+// Finalize the endpoint's configuration and begin the endpoint's main even loop (static, not tied into Logger)
void Endpoint::start()
-{
+{
// mbedEndpointLib tasklet creation...
- int main_tasklet_id = arm_ns_tasklet_create(&tasklet_main);
+ main_tasklet_id = arm_ns_tasklet_create(&tasklet_main);
if(main_tasklet_id < 0) {
//Tasklet cerate fail
- DBG("startTasklet: Tasklet creation failed...\r\n");
+ std::printf("startTasklet: Tasklet creation failed...\r\n");
return;
}
// mbedEndpointLib event dispatching
- DBG("startTasklet: Beginning event dispatch...\r\n");
+ std::printf("startTasklet: Beginning event dispatch...\r\n");
event_dispatch();
return;
}
+// our logger
+Logger *Endpoint::logger()
+{
+ return this->m_logger;
+}
+
} // namespace Connector
--- a/api/Endpoint.h Wed Jan 28 12:11:22 2015 +0000
+++ b/api/Endpoint.h Wed Jan 28 14:43:46 2015 +0000
@@ -55,27 +55,25 @@
virtual ~Endpoint();
/**
- Plumb the underlying network
- @param canActAsRouterNode input boolean indicating whether this node can act as a router node or not.
- */
- static void plumbNetwork(bool canActAsRouterNode = false);
-
- /**
- Initialize the endpoint
+ Initialize the endpoint configuration
*/
void initialize();
/**
- Finalize the endpoint's configuration and begin the endpoint's main even loop
+ Plumb the lower RF network stack
+ @param canActAsRouterNode input boolean indicating whether this node can act as a router node or not.
+ */
+ static void plumbNetwork(bool canActAsRouterNode = false);
+
+ /**
+ Initialize the endpoint's configuration and begin the endpoint's main even loop
*/
static void start();
-protected:
-
private:
Logger *m_logger;
Options *m_options;
-
+
// initialize the NSDL network
void initNetwork();
--- a/api/InstancePointerTable.cpp Wed Jan 28 12:11:22 2015 +0000
+++ b/api/InstancePointerTable.cpp Wed Jan 28 14:43:46 2015 +0000
@@ -40,7 +40,6 @@
int index = this->indexFromKey(key);
if (index >= 0) {
// overwrite the existing reference we have...
- std::printf("InstancePointerTable: ADD(overwrite) instance: key[%s] index=%d\r\n",key.c_str(),index);
this->m_instance_pointer_table[index].instance = instance;
} else {
// get the next empty slot
@@ -49,10 +48,9 @@
// set the table entry
this->m_instance_pointer_table[index].key = key;
this->m_instance_pointer_table[index].instance = instance;
- std::printf("InstancePointerTable: ADD instance: key[%s] index=%d\r\n",key.c_str(),index);
} else {
// table is FULL! Error...
- std::printf("ERROR: InstancePointerTable is FULL... please expand table\r\n");
+ this->logger()->log("ERROR: InstancePointerTable is FULL... please expand table");
}
}
}
@@ -63,7 +61,6 @@
// get our index
int index = this->indexFromKey(key);
if (index >= 0) {
- std::printf("InstancePointerTable: GET instance: key[%s] index=%d\r\n",key.c_str(),index);
return this->m_instance_pointer_table[index].instance;
}
return NULL;
--- a/api/Logger.cpp Wed Jan 28 12:11:22 2015 +0000
+++ b/api/Logger.cpp Wed Jan 28 14:43:46 2015 +0000
@@ -39,19 +39,22 @@
{
}
-// Log output
-void Logger::log(const char *format,...)
-{
+// Log the ouput to the attached serial console
+void Logger::logIt(const char *format,...)
+{
+ // build the variable args into a string
va_list args;
- va_start(args,format);
- if (this->m_pc != NULL) {
- //this->m_pc->printf(format,args);
- //this->m_pc->printf("\r\n");
- std::printf(format,args);
- std::printf("\r\n");
- } else {
- std::printf(format,args);
- std::printf("\r\n");
- }
+ char buffer[LOGGER_BUFFER_LENGTH+1];
+ memset(buffer,0,LOGGER_BUFFER_LENGTH+1);
+ va_start(args, format);
+ vsnprintf(buffer,LOGGER_BUFFER_LENGTH,format,args);
+
+ // clean up...
va_end(args);
+
+ // print it...
+ if (this->m_pc != NULL)
+ this->m_pc->printf("%s",buffer);
+ else
+ std::printf("%s",buffer);
}
--- a/api/Logger.h Wed Jan 28 12:11:22 2015 +0000
+++ b/api/Logger.h Wed Jan 28 14:43:46 2015 +0000
@@ -32,6 +32,12 @@
// Depends on use of BufferedSerial
#include "BufferedSerial.h"
+// Configuration
+#include "mbedConnectorInterface.h"
+
+// logging macro
+#define log(x, ...) logIt(x"\r\n",##__VA_ARGS__)
+
/** Logger class
*/
class Logger
@@ -55,11 +61,11 @@
virtual ~Logger();
/**
- Log output
+ Log output to the given serial console
@param format input format for the logging
@param ... input (variable arguments to display)
*/
- void log(const char *format, ...);
+ void logIt(const char *format, ...);
protected:
private:
--- a/api/StaticResource.cpp Wed Jan 28 12:11:22 2015 +0000
+++ b/api/StaticResource.cpp Wed Jan 28 14:43:46 2015 +0000
@@ -55,14 +55,13 @@
{
if (p != NULL) {
sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s *)p;
- std::printf("StaticResource: name[%s] value:[%s]\r\n",this->getName().c_str(),this->getValue().c_str());
const uint8_t *name = (const uint8_t *)(this->getName().c_str());
const uint8_t *value = (const uint8_t *)(this->getValue().c_str());
int name_length = this->getName().size();
int value_length = this->getValue().size();
nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,(uint8_t *)value,value_length);
- std::printf("StaticResource[%s(%d)] value: %s(%d) bound\r\n",name,name_length,value,value_length);
+ this->logger()->log("StaticResource: [%s] value: [%s] bound",name,value);
} else {
- std::printf("StaticResource: NULL parameter in bind()\r\n");
+ this->logger()->log("StaticResource: NULL parameter in bind()");
}
}
--- a/api/Utils.cpp Wed Jan 28 12:11:22 2015 +0000
+++ b/api/Utils.cpp Wed Jan 28 14:43:46 2015 +0000
@@ -56,7 +56,7 @@
config.setRadioChannelList(NODE_CHANNEL_LIST);
config.setReadUpdatePeriod(NSP_RD_UPDATE_PERIOD);
config.setEndpointNodename(NODE_NAME);
- config.setMACAddress(app_MAC_address);
+ config.setMACAddress(app_MAC_address); // TODO: arm_ns_tasklet_create() should call Endpoint::plumbNetwork()... currently its called before this MAC address can be (re)set
// main.cpp can override or change any of the above defaults...
logger.log("configure_endpoint: enabling default configuration overrides...");
@@ -68,7 +68,7 @@
memcpy(endpoint_name,options->getEndpointNodename().c_str(),NODE_NAME_LENGTH);
memcpy(ep_type,options->getEndpointType().c_str(),NSP_ENDPOINT_TYPE_LENGTH);
memcpy(lifetime_ptr,options->getLifetime(),NSP_LIFE_TIME_LENGTH);
- memcpy(app_MAC_address,options->getMACAddress(),NODE_MAC_ADDRESS_LENGTH);
+ memcpy(app_MAC_address,options->getMACAddress(),NODE_MAC_ADDRESS_LENGTH); // TODO: arm_ns_tasklet_create() should call Endpoint::plumbNetwork()... currently its called before this MAC address can be (re)set
channel_list = options->getRadioChannelList();
// alloc Endpoint
--- a/mbedConnectorInterface.h Wed Jan 28 12:11:22 2015 +0000 +++ b/mbedConnectorInterface.h Wed Jan 28 14:43:46 2015 +0000 @@ -49,6 +49,9 @@ // Instance Pointer Table Configuration #define IPT_MAX_ENTRIES 256 // maximum number of unique pointers managed by the IPT (i.e. number of ind dynamic resources) +// Logger buffer size +#define LOGGER_BUFFER_LENGTH 256 // largest single print of a given debug line + /************** DEFAULT CONFIGURATION PARAMETERS ************************/ #endif // __MBED_CONNECTOR_INTERFACE___ \ No newline at end of file
