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.
Diff: source/port_helper.cpp
- Revision:
- 1:cb8989598a0f
- Parent:
- 0:9dd7c6129683
- Child:
- 3:5bea13b77b97
--- a/source/port_helper.cpp Mon May 30 07:36:47 2011 +0000
+++ b/source/port_helper.cpp Mon May 30 08:26:26 2011 +0000
@@ -12,102 +12,136 @@
void initHelper()
{
- Debug.baud(57600);
- printf(" CANopen port of CANfestival master node \n");
+ Debug.baud(57600);
+ printf(" CANopen port of CANfestival master node \n");
}
void serviceHelper()
{
- static uint32_t cnt = 0;
- // indicate that the stack is running
- if (cnt++ > 100){
- cnt = 0;
- running_status = !running_status;
- }
+ static uint32_t cnt = 0;
+ // indicate that the stack is running
+ if (cnt++ > 100){
+ cnt = 0;
+ running_status = !running_status;
+ }
}
void printMsg(Message& msg)
{
- CANMessage m(msg.cob_id, (char*)msg.data, msg.len, static_cast<CANType>(msg.rtr), CANStandard);
- // call the CANMessage formatted method
- printMsg(m);
+ CANMessage m(msg.cob_id, (char*)msg.data, msg.len, static_cast<CANType>(msg.rtr), CANStandard);
+ // call the CANMessage formatted method
+ printMsg(m);
}
void printMsg(CANMessage& msg)
{
- printf("ID: 0x%04X DLC: %d Data(0->7): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
- msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2],
- msg.data[3], msg.data[4], msg.data[5], msg.data[6],msg.data[7]);
+ switch(msg.len){
+ case 1:
+ printf("ID: 0x%04X DLC: %d Data(0): 0x%02X\n", msg.id, msg.len, msg.data[0]);
+ break;
+ case 2:
+ printf("ID: 0x%04X DLC: %d Data(0->1): 0x%02X 0x%02X\n", msg.id, msg.len, msg.data[0], msg.data[1]);
+ break;
+ case 3:
+ printf("ID: 0x%04X DLC: %d Data(0->2): 0x%02X 0x%02X 0x%02X\n",
+ msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2]);
+ break;
+ case 4:
+ printf("ID: 0x%04X DLC: %d Data(0->3): 0x%02X 0x%02X 0x%02X 0x%02X\n",
+ msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3]);
+ break;
+ case 5:
+ printf("ID: 0x%04X DLC: %d Data(0->4): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+ msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4]);
+ break;
+ case 6:
+ printf("ID: 0x%04X DLC: %d Data(0->5): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+ msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5]);
+ break;
+ case 7:
+ printf("ID: 0x%04X DLC: %d Data(0->6): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+ msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5], msg.data[6]);
+ break;
+ case 8:
+ printf("ID: 0x%04X DLC: %d Data(0->7): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+ msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5], msg.data[6], msg.data[7]);
+ break;
+ default:
+ break;
+ }
+ //printf("ID: 0x%04X DLC: %d Data(0->7): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+ // msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2],
+ // msg.data[3], msg.data[4], msg.data[5], msg.data[6],msg.data[7]);
}
void serviceCOMCommands()
{
- static char msg[64];
- static char w_loc=0;
- if (Debug.readable()){
- // store the data
- if (w_loc < 64){
- msg[w_loc++] = Debug.getc();
- }
- // clear the buffer and try again
- else{
- // clear the buffer
- memset(msg, 0, 64);
- w_loc = 0;
- return;
- }
- // parse the message and act on it
- if ((msg[w_loc-1] == '\r') || (msg[w_loc-1] == '\n') ){
- // format the message
- // process the message and look for something familiar
- if (strncmp(msg, "help", strlen("help")) == 0){
- // print the help menu
- printf("\t HELP OPTIONS (case sesnitive):\n");
- printf("\t help - display the available options\n");
- printf("\t id=xxx - change the node id\n");
- printf("\t about - get info about the node\n");
- printf("\t state=xxxx - start, stop, reset\n");
- }
- else if (strncmp(msg, "id=", strlen("id=")) == 0){
- // change the node ID
- int res = atoi(msg+strlen("id="));
- if ( (res > 0) && (res < 128) ){
- nodeID = res;
- printf("the new node_id = %d\n", nodeID);
- change_node_id = 1;
- }
- else{
- printf("invalid parameter");
- }
- }
- else if (strncmp(msg, "about", strlen("about")) == 0){
- // our call tag
- printf(" CANopen port of CANfestival master node \n");
- }
- else if (strncmp(msg, "state=", strlen("state=")) == 0){
- // ohh what to do
- if (strncmp(msg+strlen("state="), "start", strlen("start")) == 0){
- printf("stack state = start");
- // signal back
- stack_state = start;
- }
- else if (strncmp(msg+strlen("state="), "stop", strlen("stop")) == 0){
- printf("stack state = stop");
- // signal back
- stack_state = stop;
- }
- else if (strncmp(msg+strlen("state="), "reset", strlen("reset")) == 0){
- printf("stack state = reset");
- // signal back
- stack_state = reset;
- }
- }
- // clear the buffer
- memset(msg, 0, 64);
- w_loc = 0;
- }
- }
+ static char msg[64];
+ static char w_loc=0;
+ if (Debug.readable()){
+ // store the data
+ if (w_loc < 64){
+ msg[w_loc++] = Debug.getc();
+ }
+ // clear the buffer and try again
+ else{
+ // clear the buffer
+ memset(msg, 0, 64);
+ w_loc = 0;
+ return;
+ }
+ // parse the message and act on it
+ if ((msg[w_loc-1] == '\r') || (msg[w_loc-1] == '\n') ){
+ // format the message
+ // process the message and look for something familiar
+ if (strncmp(msg, "help", strlen("help")) == 0){
+ // print the help menu
+ printf("\t HELP OPTIONS (case sesnitive):\n");
+ printf("\t help - display the available options\n");
+ printf("\t id=xxx - change the node id\n");
+ printf("\t about - get info about the node\n");
+ printf("\t state=xxxx - start, stop, reset\n");
+ }
+ else if (strncmp(msg, "id=", strlen("id=")) == 0){
+ // change the node ID
+ int res = atoi(msg+strlen("id="));
+ if ( (res > 0) && (res < 128) ){
+ nodeID = res;
+ printf("the new node_id = %d\n", nodeID);
+ change_node_id = 1;
+ }
+ else{
+ printf("invalid parameter\n");
+ }
+ }
+ else if (strncmp(msg, "about", strlen("about")) == 0){
+ // our call tag
+ printf(" CANopen port of CANfestival master node \n");
+ }
+ else if (strncmp(msg, "state=", strlen("state=")) == 0){
+ // ohh what to do
+ if (strncmp(msg+strlen("state="), "start", strlen("start")) == 0){
+ printf("stack state = start\n");
+ // signal back
+ stack_state = start;
+ }
+ else if (strncmp(msg+strlen("state="), "stop", strlen("stop")) == 0){
+ printf("stack state = stop\n");
+ // signal back
+ stack_state = stop;
+ }
+ else if (strncmp(msg+strlen("state="), "reset", strlen("reset")) == 0){
+ printf("stack state = reset\n");
+ // signal back
+ stack_state = reset;
+ }
+ }
+ // clear the buffer
+ memset(msg, 0, 64);
+ w_loc = 0;
+ }
+ }
}
/*