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.
Fork of Nucleo_CaitSith_Firmware by
main.cpp@4:039a7d1ce3e9, 2015-01-24 (annotated)
- Committer:
- YosukeK
- Date:
- Sat Jan 24 17:41:21 2015 +0000
- Revision:
- 4:039a7d1ce3e9
- Parent:
- 3:9ac9fdf1856e
- Child:
- 5:4c87a8401f7c
????????????????
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| YosukeK | 0:a9b204e27472 | 1 | #include <mbed.h> | 
| YosukeK | 0:a9b204e27472 | 2 | #include <PwmServo.h> | 
| YosukeK | 1:5f6dd444850a | 3 | #include <ExtendedServo.h> | 
| YosukeK | 3:9ac9fdf1856e | 4 | #include <DelayServo.h> | 
| YosukeK | 3:9ac9fdf1856e | 5 | //#include <RobotArm.h> | 
| YosukeK | 0:a9b204e27472 | 6 | #include <def_resources.h> | 
| YosukeK | 0:a9b204e27472 | 7 | #include <Serial.h> | 
| YosukeK | 4:039a7d1ce3e9 | 8 | #include "Roomba.h" | 
| YosukeK | 4:039a7d1ce3e9 | 9 | #include "EventArg.h" | 
| YosukeK | 4:039a7d1ce3e9 | 10 | |
| YosukeK | 0:a9b204e27472 | 11 | |
| YosukeK | 0:a9b204e27472 | 12 | /* | 
| YosukeK | 0:a9b204e27472 | 13 | |
| YosukeK | 0:a9b204e27472 | 14 | Controller firmware for CaitSithDanger | 
| YosukeK | 0:a9b204e27472 | 15 | |
| YosukeK | 0:a9b204e27472 | 16 | Kyoto-Densou-An 2014 | 
| YosukeK | 0:a9b204e27472 | 17 | |
| YosukeK | 0:a9b204e27472 | 18 | Author : yishii | 
| YosukeK | 0:a9b204e27472 | 19 | */ | 
| YosukeK | 0:a9b204e27472 | 20 | |
| YosukeK | 0:a9b204e27472 | 21 | #define DEBUG | 
| YosukeK | 0:a9b204e27472 | 22 | #define BUFFER_SIZE 11 | 
| YosukeK | 3:9ac9fdf1856e | 23 | //#define COMMAND_TOTAL 3 | 
| YosukeK | 2:91135f19ac12 | 24 | |
| YosukeK | 0:a9b204e27472 | 25 | |
| YosukeK | 0:a9b204e27472 | 26 | char receive[BUFFER_SIZE]; | 
| YosukeK | 0:a9b204e27472 | 27 | //char* p_receive; | 
| YosukeK | 3:9ac9fdf1856e | 28 | //int recvPnt = 0; | 
| YosukeK | 0:a9b204e27472 | 29 | |
| YosukeK | 2:91135f19ac12 | 30 | int oyatsuCnt = 0; | 
| YosukeK | 2:91135f19ac12 | 31 | |
| YosukeK | 4:039a7d1ce3e9 | 32 | EventArg e; | 
| YosukeK | 4:039a7d1ce3e9 | 33 | |
| YosukeK | 3:9ac9fdf1856e | 34 | int serial_gets(char *buffer, int size); | 
| YosukeK | 0:a9b204e27472 | 35 | |
| YosukeK | 4:039a7d1ce3e9 | 36 | void initialize(); | 
| YosukeK | 4:039a7d1ce3e9 | 37 | |
| YosukeK | 4:039a7d1ce3e9 | 38 | //void moveServo() | 
| YosukeK | 4:039a7d1ce3e9 | 39 | //{ | 
| YosukeK | 4:039a7d1ce3e9 | 40 | // shakeHead.moveServo(); | 
| YosukeK | 4:039a7d1ce3e9 | 41 | // nodHead.moveServo(); | 
| YosukeK | 4:039a7d1ce3e9 | 42 | // leftArm.moveServo(); | 
| YosukeK | 4:039a7d1ce3e9 | 43 | // leftShoulder.moveServo(); | 
| YosukeK | 4:039a7d1ce3e9 | 44 | // rightArm.moveServo(); | 
| YosukeK | 4:039a7d1ce3e9 | 45 | // rightShoulder.moveServo(); | 
| YosukeK | 4:039a7d1ce3e9 | 46 | //} | 
| YosukeK | 4:039a7d1ce3e9 | 47 | |
| YosukeK | 4:039a7d1ce3e9 | 48 | Ticker mTick; | 
| YosukeK | 4:039a7d1ce3e9 | 49 | |
| YosukeK | 4:039a7d1ce3e9 | 50 | Roomba nyandaBase(SERIAL_TX, SERIAL_RX, PA_14); | 
| YosukeK | 0:a9b204e27472 | 51 | |
| YosukeK | 0:a9b204e27472 | 52 | int main() { | 
| YosukeK | 4:039a7d1ce3e9 | 53 | pc.baud(115200); | 
| YosukeK | 4:039a7d1ce3e9 | 54 | initialize(); | 
| YosukeK | 4:039a7d1ce3e9 | 55 | debugled = 1; | 
| YosukeK | 4:039a7d1ce3e9 | 56 | //mTick.attach_us(&moveServo, 10000); | 
| YosukeK | 3:9ac9fdf1856e | 57 | |
| YosukeK | 4:039a7d1ce3e9 | 58 | |
| YosukeK | 4:039a7d1ce3e9 | 59 | Roomba* cp = new Roomba(SERIAL_TX, SERIAL_RX, LED1);//Class pointor | 
| YosukeK | 4:039a7d1ce3e9 | 60 | void (Roomba::*fp)(void) = &Roomba::serialReceiveCallback; | 
| YosukeK | 4:039a7d1ce3e9 | 61 | |
| YosukeK | 4:039a7d1ce3e9 | 62 | //<戻り値の型> (<クラス名>::*<変数名>(<引数リスト>); | 
| YosukeK | 4:039a7d1ce3e9 | 63 | |
| YosukeK | 4:039a7d1ce3e9 | 64 | //fp = cp->serialReceiveCallback(); | 
| YosukeK | 4:039a7d1ce3e9 | 65 | |
| YosukeK | 4:039a7d1ce3e9 | 66 | //ticker.attach(&cp, cp->serialReceiveCallback, 0.1); | 
| YosukeK | 4:039a7d1ce3e9 | 67 | |
| YosukeK | 4:039a7d1ce3e9 | 68 | |
| YosukeK | 4:039a7d1ce3e9 | 69 | //(cp->*fp)();//クラスポインタとメンバポインタ両方を使うメソッド呼び出し?なにに使うの? | 
| YosukeK | 4:039a7d1ce3e9 | 70 | |
| YosukeK | 4:039a7d1ce3e9 | 71 | //ticker.attach(&cp, (cp->*fp)(), 0.1); | 
| YosukeK | 4:039a7d1ce3e9 | 72 | //Roomba* cp = new Roomba(SERIAL_TX, SERIAL_RX, LED1);//Class pointor | 
| YosukeK | 4:039a7d1ce3e9 | 73 | //void (Roomba::*fp)(void) = &Roomba::serialReceiveCallback; | 
| YosukeK | 4:039a7d1ce3e9 | 74 | |
| YosukeK | 4:039a7d1ce3e9 | 75 | //<戻り値の型> (<クラス名>::*<変数名>(<引数リスト>); | 
| YosukeK | 4:039a7d1ce3e9 | 76 | |
| YosukeK | 4:039a7d1ce3e9 | 77 | //fp = cp->serialReceiveCallback(); | 
| YosukeK | 4:039a7d1ce3e9 | 78 | |
| YosukeK | 4:039a7d1ce3e9 | 79 | //ticker.attach(&cp, cp->serialReceiveCallback, 0.1); | 
| YosukeK | 4:039a7d1ce3e9 | 80 | |
| YosukeK | 4:039a7d1ce3e9 | 81 | |
| YosukeK | 4:039a7d1ce3e9 | 82 | //(cp->*fp)();//クラスポインタとメンバポインタ両方を使うメソッド呼び出し?なにに使うの? | 
| YosukeK | 4:039a7d1ce3e9 | 83 | |
| YosukeK | 4:039a7d1ce3e9 | 84 | //ticker.attach(&cp, (cp->*fp)(), 0.1); | 
| YosukeK | 4:039a7d1ce3e9 | 85 | |
| YosukeK | 4:039a7d1ce3e9 | 86 | //mTick.attach(Roomba, &nyandaBase.periodicCallback, 0.1); | 
| YosukeK | 4:039a7d1ce3e9 | 87 | |
| YosukeK | 1:5f6dd444850a | 88 | |
| YosukeK | 0:a9b204e27472 | 89 | while(1) { | 
| YosukeK | 0:a9b204e27472 | 90 | char buffer[BUFFER_SIZE]; | 
| YosukeK | 4:039a7d1ce3e9 | 91 | // コマンド受信 | 
| YosukeK | 0:a9b204e27472 | 92 | int size = serial_gets(buffer, BUFFER_SIZE); | 
| YosukeK | 4:039a7d1ce3e9 | 93 | |
| YosukeK | 0:a9b204e27472 | 94 | if (size > 0) { | 
| YosukeK | 3:9ac9fdf1856e | 95 | |
| YosukeK | 4:039a7d1ce3e9 | 96 | #ifdef DEBUG | 
| YosukeK | 4:039a7d1ce3e9 | 97 | pc.printf("%s", buffer); | 
| YosukeK | 4:039a7d1ce3e9 | 98 | #endif | 
| YosukeK | 3:9ac9fdf1856e | 99 | // コマンド判定 | 
| YosukeK | 0:a9b204e27472 | 100 | if (strncmp(buffer, "CT", 2) == 0) { | 
| YosukeK | 0:a9b204e27472 | 101 | |
| YosukeK | 0:a9b204e27472 | 102 | myled = !myled; | 
| YosukeK | 1:5f6dd444850a | 103 | |
| YosukeK | 1:5f6dd444850a | 104 | bool ret = false; | 
| YosukeK | 0:a9b204e27472 | 105 | |
| YosukeK | 0:a9b204e27472 | 106 | if (size == 2) { | 
| YosukeK | 1:5f6dd444850a | 107 | ret = true; | 
| YosukeK | 0:a9b204e27472 | 108 | } else if (size >= 3) { | 
| YosukeK | 3:9ac9fdf1856e | 109 | |
| YosukeK | 4:039a7d1ce3e9 | 110 | |
| YosukeK | 4:039a7d1ce3e9 | 111 | switch (buffer[2]) { | 
| YosukeK | 3:9ac9fdf1856e | 112 | case 'Z': | 
| YosukeK | 3:9ac9fdf1856e | 113 | |
| YosukeK | 3:9ac9fdf1856e | 114 | initialize(); | 
| YosukeK | 3:9ac9fdf1856e | 115 | |
| YosukeK | 3:9ac9fdf1856e | 116 | ret = true; | 
| YosukeK | 3:9ac9fdf1856e | 117 | break; | 
| YosukeK | 3:9ac9fdf1856e | 118 | |
| YosukeK | 2:91135f19ac12 | 119 | case 'N': | 
| YosukeK | 3:9ac9fdf1856e | 120 | |
| YosukeK | 2:91135f19ac12 | 121 | ret = true; | 
| YosukeK | 2:91135f19ac12 | 122 | if (buffer[3] == '0') { | 
| YosukeK | 2:91135f19ac12 | 123 | nyandaLight = 0; | 
| YosukeK | 2:91135f19ac12 | 124 | } else if (buffer[3] == '1') { | 
| YosukeK | 2:91135f19ac12 | 125 | nyandaLight = 1; | 
| YosukeK | 2:91135f19ac12 | 126 | } else { | 
| YosukeK | 2:91135f19ac12 | 127 | ret = false; | 
| YosukeK | 2:91135f19ac12 | 128 | } | 
| YosukeK | 2:91135f19ac12 | 129 | |
| YosukeK | 2:91135f19ac12 | 130 | break; | 
| YosukeK | 4:039a7d1ce3e9 | 131 | |
| YosukeK | 4:039a7d1ce3e9 | 132 | case 'M': | 
| YosukeK | 4:039a7d1ce3e9 | 133 | |
| YosukeK | 4:039a7d1ce3e9 | 134 | ret = true; | 
| YosukeK | 4:039a7d1ce3e9 | 135 | |
| YosukeK | 4:039a7d1ce3e9 | 136 | //CTM+500-500 | 
| YosukeK | 4:039a7d1ce3e9 | 137 | |
| YosukeK | 4:039a7d1ce3e9 | 138 | char buff[4+1]; | 
| YosukeK | 4:039a7d1ce3e9 | 139 | int temp; | 
| YosukeK | 4:039a7d1ce3e9 | 140 | |
| YosukeK | 4:039a7d1ce3e9 | 141 | //printf("Param:%s\n", before); | 
| YosukeK | 4:039a7d1ce3e9 | 142 | strncpy(buff, buffer + 3, 4); | 
| YosukeK | 4:039a7d1ce3e9 | 143 | buff[4] = '\0'; | 
| YosukeK | 4:039a7d1ce3e9 | 144 | //printf("ASC:%s\n", buff); | 
| YosukeK | 4:039a7d1ce3e9 | 145 | temp = atoi(buff); | 
| YosukeK | 4:039a7d1ce3e9 | 146 | e.leftWheetVelocity = temp; | 
| YosukeK | 4:039a7d1ce3e9 | 147 | |
| YosukeK | 4:039a7d1ce3e9 | 148 | //printf("Param:%s\n", before); | 
| YosukeK | 4:039a7d1ce3e9 | 149 | strncpy(buff, (char*)buffer[3+4], 4); | 
| YosukeK | 4:039a7d1ce3e9 | 150 | buff[4] = '\0'; | 
| YosukeK | 4:039a7d1ce3e9 | 151 | //printf("ASC:%s\n", buff); | 
| YosukeK | 4:039a7d1ce3e9 | 152 | temp = atoi(buff); | 
| YosukeK | 4:039a7d1ce3e9 | 153 | e.rightWheelVelocity = temp; | 
| YosukeK | 4:039a7d1ce3e9 | 154 | |
| YosukeK | 4:039a7d1ce3e9 | 155 | break; | 
| YosukeK | 2:91135f19ac12 | 156 | |
| YosukeK | 0:a9b204e27472 | 157 | case 'O': | 
| YosukeK | 2:91135f19ac12 | 158 | |
| YosukeK | 1:5f6dd444850a | 159 | ret = true; | 
| YosukeK | 2:91135f19ac12 | 160 | if (buffer[3] == '0') { | 
| YosukeK | 2:91135f19ac12 | 161 | oyatsuCnt = 0; | 
| YosukeK | 2:91135f19ac12 | 162 | oyatsuFeeder.setAngle(0); | 
| YosukeK | 2:91135f19ac12 | 163 | } else if (buffer[3] == '1') { | 
| YosukeK | 2:91135f19ac12 | 164 | if (oyatsuCnt <= 3) { | 
| YosukeK | 2:91135f19ac12 | 165 | oyatsuCnt++; | 
| YosukeK | 2:91135f19ac12 | 166 | } | 
| YosukeK | 2:91135f19ac12 | 167 | |
| YosukeK | 2:91135f19ac12 | 168 | switch (oyatsuCnt) { | 
| YosukeK | 2:91135f19ac12 | 169 | //case 0: | 
| YosukeK | 2:91135f19ac12 | 170 | // oyatusFeeder.setAngle(0); | 
| YosukeK | 2:91135f19ac12 | 171 | //break; | 
| YosukeK | 2:91135f19ac12 | 172 | case 1: | 
| YosukeK | 2:91135f19ac12 | 173 | oyatsuFeeder.setAngle(60); | 
| YosukeK | 2:91135f19ac12 | 174 | break; | 
| YosukeK | 2:91135f19ac12 | 175 | |
| YosukeK | 2:91135f19ac12 | 176 | case 2: | 
| YosukeK | 2:91135f19ac12 | 177 | oyatsuFeeder.setAngle(90); | 
| YosukeK | 2:91135f19ac12 | 178 | break; | 
| YosukeK | 2:91135f19ac12 | 179 | |
| YosukeK | 2:91135f19ac12 | 180 | case 3: | 
| YosukeK | 2:91135f19ac12 | 181 | oyatsuFeeder.setAngle(120); | 
| YosukeK | 2:91135f19ac12 | 182 | break; | 
| YosukeK | 2:91135f19ac12 | 183 | |
| YosukeK | 2:91135f19ac12 | 184 | default: | 
| YosukeK | 2:91135f19ac12 | 185 | break; | 
| YosukeK | 2:91135f19ac12 | 186 | } | 
| YosukeK | 2:91135f19ac12 | 187 | } else { | 
| YosukeK | 2:91135f19ac12 | 188 | ret = false; | 
| YosukeK | 2:91135f19ac12 | 189 | } | 
| YosukeK | 2:91135f19ac12 | 190 | |
| YosukeK | 0:a9b204e27472 | 191 | break; | 
| YosukeK | 0:a9b204e27472 | 192 | case 'H': | 
| YosukeK | 0:a9b204e27472 | 193 | |
| YosukeK | 0:a9b204e27472 | 194 | int servoAngle = -1; | 
| YosukeK | 0:a9b204e27472 | 195 | servoAngle = atoi((buffer+4)); | 
| YosukeK | 1:5f6dd444850a | 196 | |
| YosukeK | 1:5f6dd444850a | 197 | ret = true; | 
| YosukeK | 1:5f6dd444850a | 198 | if (buffer[3] == '1') { | 
| YosukeK | 1:5f6dd444850a | 199 | shakeHead.setAngle(servoAngle); | 
| YosukeK | 1:5f6dd444850a | 200 | } else if (buffer[3] == '2') { | 
| YosukeK | 1:5f6dd444850a | 201 | nodHead.setAngle(servoAngle); | 
| YosukeK | 1:5f6dd444850a | 202 | } else { | 
| YosukeK | 1:5f6dd444850a | 203 | ret = false; | 
| YosukeK | 1:5f6dd444850a | 204 | } | 
| YosukeK | 1:5f6dd444850a | 205 | break; | 
| YosukeK | 0:a9b204e27472 | 206 | |
| YosukeK | 1:5f6dd444850a | 207 | case 'L': | 
| YosukeK | 1:5f6dd444850a | 208 | servoAngle = atoi((buffer+4)); | 
| YosukeK | 1:5f6dd444850a | 209 | |
| YosukeK | 1:5f6dd444850a | 210 | ret = true; | 
| YosukeK | 1:5f6dd444850a | 211 | if (buffer[3] == '1') { | 
| YosukeK | 3:9ac9fdf1856e | 212 | leftShoulder.setAngle(servoAngle); | 
| YosukeK | 1:5f6dd444850a | 213 | } else if (buffer[3] == '2') { | 
| YosukeK | 3:9ac9fdf1856e | 214 | leftArm.setAngle(servoAngle); | 
| YosukeK | 1:5f6dd444850a | 215 | } else { | 
| YosukeK | 1:5f6dd444850a | 216 | ret = false; | 
| YosukeK | 0:a9b204e27472 | 217 | } | 
| YosukeK | 1:5f6dd444850a | 218 | break; | 
| YosukeK | 1:5f6dd444850a | 219 | |
| YosukeK | 1:5f6dd444850a | 220 | case 'R': | 
| YosukeK | 1:5f6dd444850a | 221 | servoAngle = atoi((buffer+4)); | 
| YosukeK | 0:a9b204e27472 | 222 | |
| YosukeK | 1:5f6dd444850a | 223 | ret = true; | 
| YosukeK | 0:a9b204e27472 | 224 | if (buffer[3] == '1') { | 
| YosukeK | 3:9ac9fdf1856e | 225 | rightShoulder.setAngle(servoAngle); | 
| YosukeK | 0:a9b204e27472 | 226 | } else if (buffer[3] == '2') { | 
| YosukeK | 3:9ac9fdf1856e | 227 | rightArm.setAngle(servoAngle); | 
| YosukeK | 0:a9b204e27472 | 228 | } else { | 
| YosukeK | 1:5f6dd444850a | 229 | ret = false; | 
| YosukeK | 0:a9b204e27472 | 230 | } | 
| YosukeK | 1:5f6dd444850a | 231 | break; | 
| YosukeK | 1:5f6dd444850a | 232 | |
| YosukeK | 1:5f6dd444850a | 233 | default: | 
| YosukeK | 1:5f6dd444850a | 234 | ret = false; | 
| YosukeK | 0:a9b204e27472 | 235 | break; | 
| YosukeK | 0:a9b204e27472 | 236 | } | 
| YosukeK | 0:a9b204e27472 | 237 | } | 
| YosukeK | 0:a9b204e27472 | 238 | |
| YosukeK | 1:5f6dd444850a | 239 | if (ret) { | 
| YosukeK | 1:5f6dd444850a | 240 | pc.printf("\r\nOK\r\n"); | 
| YosukeK | 1:5f6dd444850a | 241 | } else { | 
| YosukeK | 1:5f6dd444850a | 242 | pc.printf("\r\nNG\r\n"); | 
| YosukeK | 1:5f6dd444850a | 243 | } | 
| YosukeK | 0:a9b204e27472 | 244 | } | 
| YosukeK | 0:a9b204e27472 | 245 | } | 
| YosukeK | 4:039a7d1ce3e9 | 246 | //シリアル受信待ちをwihelで待っているので、定期送信は不可能 | 
| YosukeK | 4:039a7d1ce3e9 | 247 | // nyandaBase.periodicCallback(e); | 
| YosukeK | 4:039a7d1ce3e9 | 248 | // debugled != debugled; | 
| YosukeK | 4:039a7d1ce3e9 | 249 | // //そもそもTickerで書ける?引数付きのメソッドをattachできるのか | 
| YosukeK | 4:039a7d1ce3e9 | 250 | // //attach第2引数のインスタンスメソッドのポインタは引数付きとか書けるのか | 
| YosukeK | 4:039a7d1ce3e9 | 251 | // wait_ms(100); | 
| YosukeK | 0:a9b204e27472 | 252 | } | 
| YosukeK | 0:a9b204e27472 | 253 | } | 
| YosukeK | 0:a9b204e27472 | 254 | |
| YosukeK | 0:a9b204e27472 | 255 | |
| YosukeK | 4:039a7d1ce3e9 | 256 | void initialize() { | 
| YosukeK | 3:9ac9fdf1856e | 257 | nyandaLight = 0; | 
| YosukeK | 3:9ac9fdf1856e | 258 | |
| YosukeK | 3:9ac9fdf1856e | 259 | shakeHead.setAngle(0); | 
| YosukeK | 3:9ac9fdf1856e | 260 | nodHead.setAngle(0); | 
| YosukeK | 3:9ac9fdf1856e | 261 | leftArm.setAngle(0); | 
| YosukeK | 3:9ac9fdf1856e | 262 | leftShoulder.setAngle(0); | 
| YosukeK | 3:9ac9fdf1856e | 263 | rightArm.setAngle(0); | 
| YosukeK | 3:9ac9fdf1856e | 264 | rightShoulder.setAngle(0); | 
| YosukeK | 4:039a7d1ce3e9 | 265 | |
| YosukeK | 3:9ac9fdf1856e | 266 | } | 
| YosukeK | 0:a9b204e27472 | 267 | |
| YosukeK | 3:9ac9fdf1856e | 268 | |
| YosukeK | 3:9ac9fdf1856e | 269 | /* | 
| YosukeK | 3:9ac9fdf1856e | 270 | * | 
| YosukeK | 3:9ac9fdf1856e | 271 | */ | 
| YosukeK | 3:9ac9fdf1856e | 272 | int serial_gets(char *buffer, int size) { | 
| YosukeK | 0:a9b204e27472 | 273 | /*if (!pc.readable()) { | 
| YosukeK | 0:a9b204e27472 | 274 | return 0; | 
| YosukeK | 0:a9b204e27472 | 275 | }*/ | 
| YosukeK | 0:a9b204e27472 | 276 | |
| YosukeK | 0:a9b204e27472 | 277 | int i = 0; | 
| YosukeK | 0:a9b204e27472 | 278 | while (i < size - 1) { | 
| YosukeK | 0:a9b204e27472 | 279 | if (pc.readable()) { | 
| YosukeK | 0:a9b204e27472 | 280 | buffer[i] = pc.getc(); | 
| YosukeK | 0:a9b204e27472 | 281 | //pc.printf("%c", buffer[i]); | 
| YosukeK | 0:a9b204e27472 | 282 | |
| YosukeK | 0:a9b204e27472 | 283 | if (buffer[i] == '\r') { | 
| YosukeK | 0:a9b204e27472 | 284 | --i; | 
| YosukeK | 0:a9b204e27472 | 285 | } | 
| YosukeK | 0:a9b204e27472 | 286 | if (buffer[i] == '\n') { | 
| YosukeK | 4:039a7d1ce3e9 | 287 | |
| YosukeK | 0:a9b204e27472 | 288 | break; | 
| YosukeK | 0:a9b204e27472 | 289 | } | 
| YosukeK | 0:a9b204e27472 | 290 | ++i; | 
| YosukeK | 0:a9b204e27472 | 291 | }/* else { | 
| YosukeK | 0:a9b204e27472 | 292 | wait_ms(1); | 
| YosukeK | 0:a9b204e27472 | 293 | }*/ | 
| YosukeK | 0:a9b204e27472 | 294 | } | 
| YosukeK | 0:a9b204e27472 | 295 | buffer[i] = '\0'; | 
| YosukeK | 0:a9b204e27472 | 296 | //pc.printf("%s", buffer); | 
| YosukeK | 0:a9b204e27472 | 297 | return i; | 
| YosukeK | 0:a9b204e27472 | 298 | } | 
| YosukeK | 4:039a7d1ce3e9 | 299 | |
| YosukeK | 4:039a7d1ce3e9 | 300 | |
| YosukeK | 4:039a7d1ce3e9 | 301 | |
| YosukeK | 4:039a7d1ce3e9 | 302 | ///*/* | 
| YosukeK | 4:039a7d1ce3e9 | 303 | // * | 
| YosukeK | 4:039a7d1ce3e9 | 304 | // */ | 
| YosukeK | 4:039a7d1ce3e9 | 305 | //int getMoveCommand(char opcode, char* before, char* converted) | 
| YosukeK | 4:039a7d1ce3e9 | 306 | //{ | 
| YosukeK | 4:039a7d1ce3e9 | 307 | // char buff[10]; | 
| YosukeK | 4:039a7d1ce3e9 | 308 | // int temp; | 
| YosukeK | 4:039a7d1ce3e9 | 309 | // int cont = 0; | 
| YosukeK | 4:039a7d1ce3e9 | 310 | // | 
| YosukeK | 4:039a7d1ce3e9 | 311 | // converted[cont] = opcode; | 
| YosukeK | 4:039a7d1ce3e9 | 312 | // ++cont; | 
| YosukeK | 4:039a7d1ce3e9 | 313 | // cont = cont + convertHexToAscString(before, 4, converted + cont); | 
| YosukeK | 4:039a7d1ce3e9 | 314 | // cont = cont + convertHexToAscString(before + 4, 4, converted + cont); | 
| YosukeK | 4:039a7d1ce3e9 | 315 | // converted[cont] = '\0'; | 
| YosukeK | 4:039a7d1ce3e9 | 316 | // | 
| YosukeK | 4:039a7d1ce3e9 | 317 | //#ifdef DEBUG | 
| YosukeK | 4:039a7d1ce3e9 | 318 | // int i = 0; | 
| YosukeK | 4:039a7d1ce3e9 | 319 | // for (i = 0; i < cont; i++) { | 
| YosukeK | 4:039a7d1ce3e9 | 320 | // printf("%x\n", *(converted + i)); | 
| YosukeK | 4:039a7d1ce3e9 | 321 | // } | 
| YosukeK | 4:039a7d1ce3e9 | 322 | //#endif | 
| YosukeK | 4:039a7d1ce3e9 | 323 | // | 
| YosukeK | 4:039a7d1ce3e9 | 324 | // return strlen(converted); | 
| YosukeK | 4:039a7d1ce3e9 | 325 | //}*/ | 
| YosukeK | 4:039a7d1ce3e9 | 326 | // | 
| YosukeK | 4:039a7d1ce3e9 | 327 | ////TBD:Create Utility Class. And move under method add static | 
| YosukeK | 4:039a7d1ce3e9 | 328 | //int convertDecToAsc(char* target, int length, int* converted) { | 
| YosukeK | 4:039a7d1ce3e9 | 329 | // char buff[length + 1]; | 
| YosukeK | 4:039a7d1ce3e9 | 330 | // int temp; | 
| YosukeK | 4:039a7d1ce3e9 | 331 | // | 
| YosukeK | 4:039a7d1ce3e9 | 332 | // //strncpy(buff, before, length); | 
| YosukeK | 4:039a7d1ce3e9 | 333 | // buff[length] = '\0'; | 
| YosukeK | 4:039a7d1ce3e9 | 334 | // //printf("ASC:%s\n", buff); | 
| YosukeK | 4:039a7d1ce3e9 | 335 | // | 
| YosukeK | 4:039a7d1ce3e9 | 336 | // temp = atoi(buff); | 
| YosukeK | 4:039a7d1ce3e9 | 337 | // //printf("DEC:%d\n", temp); | 
| YosukeK | 4:039a7d1ce3e9 | 338 | // | 
| YosukeK | 4:039a7d1ce3e9 | 339 | // //converted = temp; | 
| YosukeK | 4:039a7d1ce3e9 | 340 | // | 
| YosukeK | 4:039a7d1ce3e9 | 341 | // return 0;//strlen(converted); | 
| YosukeK | 4:039a7d1ce3e9 | 342 | //} | 
| YosukeK | 4:039a7d1ce3e9 | 343 | |
| YosukeK | 4:039a7d1ce3e9 | 344 | // | 
| YosukeK | 4:039a7d1ce3e9 | 345 | ///* | 
| YosukeK | 4:039a7d1ce3e9 | 346 | // * | 
| YosukeK | 4:039a7d1ce3e9 | 347 | // */ | 
| YosukeK | 4:039a7d1ce3e9 | 348 | //int convertHexToAscString(char* before, int length, char* converted) | 
| YosukeK | 4:039a7d1ce3e9 | 349 | //{ | 
| YosukeK | 4:039a7d1ce3e9 | 350 | // char buff[length + 1]; | 
| YosukeK | 4:039a7d1ce3e9 | 351 | // int temp; | 
| YosukeK | 4:039a7d1ce3e9 | 352 | // | 
| YosukeK | 4:039a7d1ce3e9 | 353 | // printf("Param:%s\n", before); | 
| YosukeK | 4:039a7d1ce3e9 | 354 | // | 
| YosukeK | 4:039a7d1ce3e9 | 355 | // strncpy(buff, before, length); | 
| YosukeK | 4:039a7d1ce3e9 | 356 | // buff[length] = '\0'; | 
| YosukeK | 4:039a7d1ce3e9 | 357 | // printf("ASC:%s\n", buff); | 
| YosukeK | 4:039a7d1ce3e9 | 358 | // | 
| YosukeK | 4:039a7d1ce3e9 | 359 | // temp = atoi(buff); | 
| YosukeK | 4:039a7d1ce3e9 | 360 | // printf("DEC:%d\n", temp); | 
| YosukeK | 4:039a7d1ce3e9 | 361 | // | 
| YosukeK | 4:039a7d1ce3e9 | 362 | // converted[0] = ((temp & 0xFF00) >> 8); | 
| YosukeK | 4:039a7d1ce3e9 | 363 | // converted[1] = (temp & 0xFF); | 
| YosukeK | 4:039a7d1ce3e9 | 364 | // converted[2] = '\0'; | 
| YosukeK | 4:039a7d1ce3e9 | 365 | // printf("HEX(MSB):%x\n", converted[0]); | 
| YosukeK | 4:039a7d1ce3e9 | 366 | // printf("HEX(LSB):%x\n", converted[1]); | 
| YosukeK | 4:039a7d1ce3e9 | 367 | // | 
| YosukeK | 4:039a7d1ce3e9 | 368 | // return strlen(converted); | 
| YosukeK | 4:039a7d1ce3e9 | 369 | //} | 
| YosukeK | 4:039a7d1ce3e9 | 370 | // | 
