Can_open_slavenode

Dependencies:   mbed

Committer:
sam_grove
Date:
Mon May 30 07:14:41 2011 +0000
Revision:
0:6219434a0cb5
Child:
1:285c99dcbb25
Initial public release of slave node framework port

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:6219434a0cb5 1
sam_grove 0:6219434a0cb5 2 /* Just for demonstration purposes - consider it a notepad
sam_grove 0:6219434a0cb5 3 *
sam_grove 0:6219434a0cb5 4 * sgrove
sam_grove 0:6219434a0cb5 5 */
sam_grove 0:6219434a0cb5 6
sam_grove 0:6219434a0cb5 7 #include "port_helper.h"
sam_grove 0:6219434a0cb5 8 #include "main.h"
sam_grove 0:6219434a0cb5 9
sam_grove 0:6219434a0cb5 10 Serial Debug(USBTX, USBRX);
sam_grove 0:6219434a0cb5 11 DigitalOut running_status(LED1);
sam_grove 0:6219434a0cb5 12
sam_grove 0:6219434a0cb5 13 extern uint8_t nodeID;
sam_grove 0:6219434a0cb5 14 extern uint8_t change_node_id;
sam_grove 0:6219434a0cb5 15 extern uint8_t digital_input[1];
sam_grove 0:6219434a0cb5 16
sam_grove 0:6219434a0cb5 17 void initHelper()
sam_grove 0:6219434a0cb5 18 {
sam_grove 0:6219434a0cb5 19 Debug.baud(57600);
sam_grove 0:6219434a0cb5 20 printf(" CANopen port of CANfestival slave node (DS-401) \n");
sam_grove 0:6219434a0cb5 21 }
sam_grove 0:6219434a0cb5 22
sam_grove 0:6219434a0cb5 23 void serviceHelper()
sam_grove 0:6219434a0cb5 24 {
sam_grove 0:6219434a0cb5 25 static uint32_t cnt = 0;
sam_grove 0:6219434a0cb5 26 // indicate that the stack is running
sam_grove 0:6219434a0cb5 27 if (cnt++ > 100){
sam_grove 0:6219434a0cb5 28 cnt = 0;
sam_grove 0:6219434a0cb5 29 running_status = !running_status;
sam_grove 0:6219434a0cb5 30 }
sam_grove 0:6219434a0cb5 31 }
sam_grove 0:6219434a0cb5 32
sam_grove 0:6219434a0cb5 33
sam_grove 0:6219434a0cb5 34 void printMsg(Message& msg)
sam_grove 0:6219434a0cb5 35 {
sam_grove 0:6219434a0cb5 36 CANMessage m(msg.cob_id, (char*)msg.data, msg.len, static_cast<CANType>(msg.rtr), CANStandard);
sam_grove 0:6219434a0cb5 37 // call the CANMessage formatted method
sam_grove 0:6219434a0cb5 38 printMsg(m);
sam_grove 0:6219434a0cb5 39 }
sam_grove 0:6219434a0cb5 40
sam_grove 0:6219434a0cb5 41 void printMsg(CANMessage& msg)
sam_grove 0:6219434a0cb5 42 {
sam_grove 0:6219434a0cb5 43 // print the message
sam_grove 0:6219434a0cb5 44 printf("ID: 0x%03X DLC: %d Data(0->7): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
sam_grove 0:6219434a0cb5 45 msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2],
sam_grove 0:6219434a0cb5 46 msg.data[3], msg.data[4], msg.data[5], msg.data[6], msg.data[7]);
sam_grove 0:6219434a0cb5 47
sam_grove 0:6219434a0cb5 48 }
sam_grove 0:6219434a0cb5 49
sam_grove 0:6219434a0cb5 50 void serviceCOMCommands()
sam_grove 0:6219434a0cb5 51 {
sam_grove 0:6219434a0cb5 52 static char msg[64];
sam_grove 0:6219434a0cb5 53 static char w_loc=0;
sam_grove 0:6219434a0cb5 54 if (Debug.readable()){
sam_grove 0:6219434a0cb5 55 // store the data
sam_grove 0:6219434a0cb5 56 if (w_loc < 64){
sam_grove 0:6219434a0cb5 57 msg[w_loc++] = Debug.getc();
sam_grove 0:6219434a0cb5 58 }
sam_grove 0:6219434a0cb5 59 // clear the buffer and try again
sam_grove 0:6219434a0cb5 60 else{
sam_grove 0:6219434a0cb5 61 // clear the buffer
sam_grove 0:6219434a0cb5 62 memset(msg, 0, 64);
sam_grove 0:6219434a0cb5 63 w_loc = 0;
sam_grove 0:6219434a0cb5 64 return;
sam_grove 0:6219434a0cb5 65 }
sam_grove 0:6219434a0cb5 66 // parse the message and act on it
sam_grove 0:6219434a0cb5 67 if ((msg[w_loc-1] == '\r') || (msg[w_loc-1] == '\n') ){
sam_grove 0:6219434a0cb5 68 // process the message and look for something familiar
sam_grove 0:6219434a0cb5 69 if (strncmp(msg, "help", strlen("help")) == 0){
sam_grove 0:6219434a0cb5 70 // print the help menu
sam_grove 0:6219434a0cb5 71 printf("\t HELP OPTIONS (case sesnitive):\n");
sam_grove 0:6219434a0cb5 72 printf("\t help - display the available options\n");
sam_grove 0:6219434a0cb5 73 printf("\t id=xxx - change the node id\n");
sam_grove 0:6219434a0cb5 74 printf("\t about - get info about the node\n");
sam_grove 0:6219434a0cb5 75 printf("\t input=x - a decimal number\n");
sam_grove 0:6219434a0cb5 76 }
sam_grove 0:6219434a0cb5 77 else if (strncmp(msg, "id=", strlen("id=")) == 0){
sam_grove 0:6219434a0cb5 78 // change the node ID
sam_grove 0:6219434a0cb5 79 int res = atoi(msg+strlen("id="));
sam_grove 0:6219434a0cb5 80 if ( (res > 0) && (res < 128) ){
sam_grove 0:6219434a0cb5 81 nodeID = res;
sam_grove 0:6219434a0cb5 82 printf("the new node_id = %d\n", nodeID);
sam_grove 0:6219434a0cb5 83 change_node_id = 1;
sam_grove 0:6219434a0cb5 84 }
sam_grove 0:6219434a0cb5 85 else{
sam_grove 0:6219434a0cb5 86 printf("invalid parameter");
sam_grove 0:6219434a0cb5 87 }
sam_grove 0:6219434a0cb5 88 }
sam_grove 0:6219434a0cb5 89 else if (strncmp(msg, "about", strlen("about")) == 0){
sam_grove 0:6219434a0cb5 90 // our call tag
sam_grove 0:6219434a0cb5 91 printf(" CANopen port of CANfestival slave node (DS-401) \n");
sam_grove 0:6219434a0cb5 92 }
sam_grove 0:6219434a0cb5 93 else if (strncmp(msg, "input=", strlen("input=")) == 0){
sam_grove 0:6219434a0cb5 94 // store the input value
sam_grove 0:6219434a0cb5 95 digital_input[0] = (uint8_t)atoi(msg+strlen("input="));
sam_grove 0:6219434a0cb5 96 printf("you entered %d", digital_input[0]);
sam_grove 0:6219434a0cb5 97 }
sam_grove 0:6219434a0cb5 98 // clear the buffer
sam_grove 0:6219434a0cb5 99 memset(msg, 0, 64);
sam_grove 0:6219434a0cb5 100 w_loc = 0;
sam_grove 0:6219434a0cb5 101 }
sam_grove 0:6219434a0cb5 102 }
sam_grove 0:6219434a0cb5 103 }
sam_grove 0:6219434a0cb5 104
sam_grove 0:6219434a0cb5 105 /*
sam_grove 0:6219434a0cb5 106 WDT_IRQHandler
sam_grove 0:6219434a0cb5 107 TIMER0_IRQHandler
sam_grove 0:6219434a0cb5 108 TIMER1_IRQHandler
sam_grove 0:6219434a0cb5 109 TIMER2_IRQHandler
sam_grove 0:6219434a0cb5 110 TIMER3_IRQHandler
sam_grove 0:6219434a0cb5 111 UART0_IRQHandler
sam_grove 0:6219434a0cb5 112 UART1_IRQHandler
sam_grove 0:6219434a0cb5 113 UART2_IRQHandler
sam_grove 0:6219434a0cb5 114 UART3_IRQHandler
sam_grove 0:6219434a0cb5 115 PWM1_IRQHandler
sam_grove 0:6219434a0cb5 116 I2C0_IRQHandler
sam_grove 0:6219434a0cb5 117 I2C1_IRQHandler
sam_grove 0:6219434a0cb5 118 I2C2_IRQHandler
sam_grove 0:6219434a0cb5 119 SPI_IRQHandler
sam_grove 0:6219434a0cb5 120 SSP0_IRQHandler
sam_grove 0:6219434a0cb5 121 SSP1_IRQHandler
sam_grove 0:6219434a0cb5 122 PLL0_IRQHandler
sam_grove 0:6219434a0cb5 123 RTC_IRQHandler
sam_grove 0:6219434a0cb5 124 EINT0_IRQHandler
sam_grove 0:6219434a0cb5 125 EINT1_IRQHandler
sam_grove 0:6219434a0cb5 126 EINT2_IRQHandler
sam_grove 0:6219434a0cb5 127 EINT3_IRQHandler
sam_grove 0:6219434a0cb5 128 ADC_IRQHandler
sam_grove 0:6219434a0cb5 129 BOD_IRQHandler
sam_grove 0:6219434a0cb5 130 USB_IRQHandler
sam_grove 0:6219434a0cb5 131 CAN_IRQHandler
sam_grove 0:6219434a0cb5 132 DMA_IRQHandler
sam_grove 0:6219434a0cb5 133 I2S_IRQHandler
sam_grove 0:6219434a0cb5 134 ENET_IRQHandler
sam_grove 0:6219434a0cb5 135 RIT_IRQHandler
sam_grove 0:6219434a0cb5 136 MCPWM_IRQHandler
sam_grove 0:6219434a0cb5 137 QEI_IRQHandler
sam_grove 0:6219434a0cb5 138 PLL1_IRQHandler
sam_grove 0:6219434a0cb5 139 USBActivity_IRQHandler
sam_grove 0:6219434a0cb5 140 CANActivity_IRQHandler
sam_grove 0:6219434a0cb5 141 */