Yaroslav Barabanov
/
turret_2017
для управления турелью
uart.cpp
- Committer:
- Yar
- Date:
- 2017-01-15
- Revision:
- 0:690effcc5be0
- Child:
- 2:a9d63ae515ad
File content as of revision 0:690effcc5be0:
#include "uart.hpp" #include "mbed.h" #include "rtos.h" #include <string> #include <stdlib.h> #include "servo.hpp" #include "gun.hpp" using namespace std; // скорость UART const int baudRate = 115200; // время обновления UART const int uartDelay = 10; const int servoDigit = 10; Serial pc(SERIAL_TX, SERIAL_RX, baudRate); void uartThread(void const *argument) { while (true) { Thread::wait(uartDelay); string inputData = ""; if (pc.readable() > 0) { while(true) { char p = pc.getc(); inputData = inputData + p; if(p == '\n' || p == '\r') { pc.printf("\n"); pc.printf(inputData.c_str()); pc.printf("\n"); break; } // if } // while if (inputData.substr(0, 3) == "get") { pc.printf("servo 0 %f\n", getServoAngle(0)); pc.printf("servo 1 %d\n", getServoAngle(1)); } else if (inputData.substr(0, 3) == "set") { char* pEnd; double servoOne, servoTwo; // строка с командой string setdata = inputData.substr(0, 13); // строка с числом string numer = inputData.substr(14, inputData.length()); if (setdata == "set all angle") { servoOne = strtod(numer.c_str(), &pEnd); servoTwo = strtod(pEnd, NULL); setServoAngle(servoOne, 0); setServoAngle(servoTwo, 1); } else if (setdata == "set all speed") { servoOne = strtod(numer.c_str(), &pEnd); servoTwo = strtod(pEnd, NULL); setServoSpeed(servoOne, 0); setServoSpeed(servoTwo, 1); } else if (setdata == "set one speed") { servoOne = strtod(numer.c_str(), NULL); setServoSpeed(servoOne, 0); } else if (setdata == "set two speed") { servoTwo = strtod(numer.c_str(), NULL); setServoSpeed(servoTwo, 1); } else if (setdata == "set one angle") { servoOne = strtod(numer.c_str(), NULL); setServoAngle(servoOne, 0); } else if (setdata == "set two angle") { servoTwo = strtod(numer.c_str(), NULL); setServoAngle(servoTwo, 1); } } else if (inputData.substr(0, 4) == "shot") { shotGun(); } else if (inputData.substr(0, 6) == "gun on") { enabledGun(); } else if (inputData.substr(0, 7) == "gun off") { disabledGun(); } } // if while(pc.readable() > 0) { char p = pc.getc(); } } }