J L
/
ringBuffer26
ringBuffer26
main.cpp@0:333434a8611b, 2020-03-20 (annotated)
- Committer:
- Picmon
- Date:
- Fri Mar 20 10:54:58 2020 +0000
- Revision:
- 0:333434a8611b
- Child:
- 1:0cb065f9d55a
motor controller 200320A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Picmon | 0:333434a8611b | 1 | |
Picmon | 0:333434a8611b | 2 | /* |
Picmon | 0:333434a8611b | 3 | |
Picmon | 0:333434a8611b | 4 | ED Motor Controller API |
Picmon | 0:333434a8611b | 5 | |
Picmon | 0:333434a8611b | 6 | |
Picmon | 0:333434a8611b | 7 | Notes: |
Picmon | 0:333434a8611b | 8 | A robust protocal has been called for, the motor command sent out is to be echoed back with and <ACK> or <NACK> |
Picmon | 0:333434a8611b | 9 | |
Picmon | 0:333434a8611b | 10 | In order to compare what was sent to what is echoed back two buffers are required, a TX buffer and an RX buffer, they can then be compared |
Picmon | 0:333434a8611b | 11 | using memcmp() function |
Picmon | 0:333434a8611b | 12 | |
Picmon | 0:333434a8611b | 13 | 19/03/20 Compare of tx and rx buffers can be done |
Picmon | 0:333434a8611b | 14 | 20/03/20 Migrate code to mbed studio |
Picmon | 0:333434a8611b | 15 | |
Picmon | 0:333434a8611b | 16 | |
Picmon | 0:333434a8611b | 17 | |
Picmon | 0:333434a8611b | 18 | */ |
Picmon | 0:333434a8611b | 19 | |
Picmon | 0:333434a8611b | 20 | #include "mbed.h" |
Picmon | 0:333434a8611b | 21 | #include <string> |
Picmon | 0:333434a8611b | 22 | #include "MotorControl.h" |
Picmon | 0:333434a8611b | 23 | |
Picmon | 0:333434a8611b | 24 | DigitalOut led1(LED1); |
Picmon | 0:333434a8611b | 25 | |
Picmon | 0:333434a8611b | 26 | |
Picmon | 0:333434a8611b | 27 | |
Picmon | 0:333434a8611b | 28 | int main(){ |
Picmon | 0:333434a8611b | 29 | |
Picmon | 0:333434a8611b | 30 | led1=0; |
Picmon | 0:333434a8611b | 31 | |
Picmon | 0:333434a8611b | 32 | mc_usart.attach(&motMsg_RX_ISR);//start the serial receiver interrupt |
Picmon | 0:333434a8611b | 33 | mc_usart.printf("ED Motor Controller Commands\r\n"); |
Picmon | 0:333434a8611b | 34 | |
Picmon | 0:333434a8611b | 35 | clrRxMsg(rxMsgStore); |
Picmon | 0:333434a8611b | 36 | |
Picmon | 0:333434a8611b | 37 | moveMot(1, 1000); |
Picmon | 0:333434a8611b | 38 | |
Picmon | 0:333434a8611b | 39 | mc_usart.printf("TX Buffer Contents\r\n"); |
Picmon | 0:333434a8611b | 40 | |
Picmon | 0:333434a8611b | 41 | for(unsigned char i=0 ; i <BUFFER_SIZE ; i++) |
Picmon | 0:333434a8611b | 42 | mc_usart.printf("%c\r\n",mc_Tx_Buffer[i]); |
Picmon | 0:333434a8611b | 43 | |
Picmon | 0:333434a8611b | 44 | while(1){ |
Picmon | 0:333434a8611b | 45 | |
Picmon | 0:333434a8611b | 46 | if(getMotMsg(rxMsgStore)){//get the message from the receive buffer and store it in local message store |
Picmon | 0:333434a8611b | 47 | |
Picmon | 0:333434a8611b | 48 | msgRecFlag = false;//clear the message received flag |
Picmon | 0:333434a8611b | 49 | |
Picmon | 0:333434a8611b | 50 | if(memcmp(rxMsgStore,mc_Tx_Buffer,strlen(rxMsgStore)) == 0){ |
Picmon | 0:333434a8611b | 51 | led1=1; |
Picmon | 0:333434a8611b | 52 | } |
Picmon | 0:333434a8611b | 53 | } |
Picmon | 0:333434a8611b | 54 | } |
Picmon | 0:333434a8611b | 55 | } |