![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Cubiscan Emulator
Dependencies: PinDetect TimeZone mbed
main.cpp@0:8c9252649f4f, 2016-07-28 (annotated)
- Committer:
- arturojat
- Date:
- Thu Jul 28 15:28:37 2016 +0000
- Revision:
- 0:8c9252649f4f
Cubiscan Emulator
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
arturojat | 0:8c9252649f4f | 1 | /************************************************** |
arturojat | 0:8c9252649f4f | 2 | * Cubiscan Emulator * |
arturojat | 0:8c9252649f4f | 3 | * Montra * |
arturojat | 0:8c9252649f4f | 4 | * Author: Arturo Alvarado Troncoso * |
arturojat | 0:8c9252649f4f | 5 | * junio del 2016 * |
arturojat | 0:8c9252649f4f | 6 | **************************************************/ |
arturojat | 0:8c9252649f4f | 7 | |
arturojat | 0:8c9252649f4f | 8 | #include "mbed.h" |
arturojat | 0:8c9252649f4f | 9 | #include "PinDetect.h" |
arturojat | 0:8c9252649f4f | 10 | #include "Time.h" |
arturojat | 0:8c9252649f4f | 11 | //Constants definition |
arturojat | 0:8c9252649f4f | 12 | #define STX 2 |
arturojat | 0:8c9252649f4f | 13 | #define ETX 3 |
arturojat | 0:8c9252649f4f | 14 | #define CR 13 |
arturojat | 0:8c9252649f4f | 15 | #define LF 10 |
arturojat | 0:8c9252649f4f | 16 | |
arturojat | 0:8c9252649f4f | 17 | //Pc serial connection |
arturojat | 0:8c9252649f4f | 18 | Serial pc(USBTX,USBRX); |
arturojat | 0:8c9252649f4f | 19 | PinDetect measureBtn(PTD4); |
arturojat | 0:8c9252649f4f | 20 | PinDetect dimBtn(PTA12); |
arturojat | 0:8c9252649f4f | 21 | PinDetect wBtn(PTA4); |
arturojat | 0:8c9252649f4f | 22 | PinDetect ErrorBtn(PTA5); |
arturojat | 0:8c9252649f4f | 23 | //DIP SWITCH |
arturojat | 0:8c9252649f4f | 24 | DigitalIn Dip1(PTC13);//CubiScan 100L |
arturojat | 0:8c9252649f4f | 25 | DigitalIn Dip2(PTC12);//CubiScan 125 |
arturojat | 0:8c9252649f4f | 26 | DigitalIn Dip3(PTC11);//CubiScan 150 |
arturojat | 0:8c9252649f4f | 27 | DigitalIn Dip4(PTC10);//CubiScan 200TS protocol 1 |
arturojat | 0:8c9252649f4f | 28 | DigitalIn Dip5(PTC6);//CubiScan 200TS protocol 2 |
arturojat | 0:8c9252649f4f | 29 | DigitalIn Dip6(PTC5); |
arturojat | 0:8c9252649f4f | 30 | DigitalIn Dip7(PTC4); |
arturojat | 0:8c9252649f4f | 31 | DigitalIn Dip8(PTC3); |
arturojat | 0:8c9252649f4f | 32 | |
arturojat | 0:8c9252649f4f | 33 | char dimUnitsValue = 'M'; |
arturojat | 0:8c9252649f4f | 34 | char wUnitsValue = 'M'; |
arturojat | 0:8c9252649f4f | 35 | char factor = 'D';//dom 166 int 139 lb 6000 iny 5000 kg |
arturojat | 0:8c9252649f4f | 36 | char id[7]=" "; |
arturojat | 0:8c9252649f4f | 37 | int MeasureNumber=0; |
arturojat | 0:8c9252649f4f | 38 | int ErrorNum =0; |
arturojat | 0:8c9252649f4f | 39 | //Funtions prototypes |
arturojat | 0:8c9252649f4f | 40 | int Cycle=0; |
arturojat | 0:8c9252649f4f | 41 | Ticker tick; |
arturojat | 0:8c9252649f4f | 42 | void dimensionCalibration(char* command); |
arturojat | 0:8c9252649f4f | 43 | char dimensionUnits(char* command); |
arturojat | 0:8c9252649f4f | 44 | char factorToggle(char* command); |
arturojat | 0:8c9252649f4f | 45 | void locationId(char* command); |
arturojat | 0:8c9252649f4f | 46 | void measure(char* command); |
arturojat | 0:8c9252649f4f | 47 | void scaleCalibration(char* command); |
arturojat | 0:8c9252649f4f | 48 | void test(char* command); |
arturojat | 0:8c9252649f4f | 49 | void units(char* command); |
arturojat | 0:8c9252649f4f | 50 | void values(char* command); |
arturojat | 0:8c9252649f4f | 51 | char weightUnits(char* command); |
arturojat | 0:8c9252649f4f | 52 | void zero(char* commmand); |
arturojat | 0:8c9252649f4f | 53 | void measureCom(void); |
arturojat | 0:8c9252649f4f | 54 | void measureCom2(void); |
arturojat | 0:8c9252649f4f | 55 | void measureCom2TS(void); |
arturojat | 0:8c9252649f4f | 56 | void itoa(int n,char s[]); |
arturojat | 0:8c9252649f4f | 57 | void printString(char * str); |
arturojat | 0:8c9252649f4f | 58 | void changeWUnits(void); |
arturojat | 0:8c9252649f4f | 59 | void changeDUnits(void); |
arturojat | 0:8c9252649f4f | 60 | void ErrorGen(void); |
arturojat | 0:8c9252649f4f | 61 | void measureCom2Cycle(void){ |
arturojat | 0:8c9252649f4f | 62 | if(Cycle == 0){ |
arturojat | 0:8c9252649f4f | 63 | Cycle=1; |
arturojat | 0:8c9252649f4f | 64 | tick.attach(&measureCom2, 3.0); |
arturojat | 0:8c9252649f4f | 65 | } |
arturojat | 0:8c9252649f4f | 66 | else{ |
arturojat | 0:8c9252649f4f | 67 | Cycle=0; |
arturojat | 0:8c9252649f4f | 68 | tick.detach(); |
arturojat | 0:8c9252649f4f | 69 | } |
arturojat | 0:8c9252649f4f | 70 | |
arturojat | 0:8c9252649f4f | 71 | } |
arturojat | 0:8c9252649f4f | 72 | int main() |
arturojat | 0:8c9252649f4f | 73 | { |
arturojat | 0:8c9252649f4f | 74 | |
arturojat | 0:8c9252649f4f | 75 | time_t t; |
arturojat | 0:8c9252649f4f | 76 | srand((unsigned) time(&t)); |
arturojat | 0:8c9252649f4f | 77 | char command[12]; |
arturojat | 0:8c9252649f4f | 78 | measureBtn.setSampleFrequency(); |
arturojat | 0:8c9252649f4f | 79 | dimBtn.setSampleFrequency(); |
arturojat | 0:8c9252649f4f | 80 | wBtn.setSampleFrequency(); |
arturojat | 0:8c9252649f4f | 81 | ErrorBtn.setSampleFrequency(); |
arturojat | 0:8c9252649f4f | 82 | |
arturojat | 0:8c9252649f4f | 83 | while(1) { |
arturojat | 0:8c9252649f4f | 84 | if((!Dip1)||(!Dip2)||(!Dip3)) { |
arturojat | 0:8c9252649f4f | 85 | measureBtn.attach_asserted(&measureCom); |
arturojat | 0:8c9252649f4f | 86 | wBtn.attach_asserted(&changeWUnits); |
arturojat | 0:8c9252649f4f | 87 | dimBtn.attach_asserted(&changeDUnits); |
arturojat | 0:8c9252649f4f | 88 | strcpy(command,""); |
arturojat | 0:8c9252649f4f | 89 | fgets(command,12,stdin); |
arturojat | 0:8c9252649f4f | 90 | if(command[0]==STX) { |
arturojat | 0:8c9252649f4f | 91 | |
arturojat | 0:8c9252649f4f | 92 | if(command[1]=='D') { |
arturojat | 0:8c9252649f4f | 93 | dimensionCalibration(command); |
arturojat | 0:8c9252649f4f | 94 | }//end if |
arturojat | 0:8c9252649f4f | 95 | else if(command[1]=='"') { |
arturojat | 0:8c9252649f4f | 96 | dimUnitsValue=dimensionUnits(command); |
arturojat | 0:8c9252649f4f | 97 | }//end else if |
arturojat | 0:8c9252649f4f | 98 | else if(command[1]=='F') { |
arturojat | 0:8c9252649f4f | 99 | factor = factorToggle(command); |
arturojat | 0:8c9252649f4f | 100 | }//end else if |
arturojat | 0:8c9252649f4f | 101 | else if(command[1]=='L') { |
arturojat | 0:8c9252649f4f | 102 | locationId(command); |
arturojat | 0:8c9252649f4f | 103 | }//end else if |
arturojat | 0:8c9252649f4f | 104 | else if(command[1]=='M') { |
arturojat | 0:8c9252649f4f | 105 | measure(command); |
arturojat | 0:8c9252649f4f | 106 | }//end else if |
arturojat | 0:8c9252649f4f | 107 | else if(command[1]=='S') { |
arturojat | 0:8c9252649f4f | 108 | scaleCalibration(command); |
arturojat | 0:8c9252649f4f | 109 | }//end else if |
arturojat | 0:8c9252649f4f | 110 | else if(command[1]=='T') { |
arturojat | 0:8c9252649f4f | 111 | test(command); |
arturojat | 0:8c9252649f4f | 112 | |
arturojat | 0:8c9252649f4f | 113 | } else if(command[1]=='U') { |
arturojat | 0:8c9252649f4f | 114 | units(command); |
arturojat | 0:8c9252649f4f | 115 | |
arturojat | 0:8c9252649f4f | 116 | }//end if |
arturojat | 0:8c9252649f4f | 117 | else if(command[1]=='V') { |
arturojat | 0:8c9252649f4f | 118 | values(command); |
arturojat | 0:8c9252649f4f | 119 | |
arturojat | 0:8c9252649f4f | 120 | }//end if |
arturojat | 0:8c9252649f4f | 121 | else if(command[1]=='#') { |
arturojat | 0:8c9252649f4f | 122 | wUnitsValue= weightUnits(command); |
arturojat | 0:8c9252649f4f | 123 | |
arturojat | 0:8c9252649f4f | 124 | }//end if |
arturojat | 0:8c9252649f4f | 125 | else if(command[1]=='Z') { |
arturojat | 0:8c9252649f4f | 126 | zero(command); |
arturojat | 0:8c9252649f4f | 127 | |
arturojat | 0:8c9252649f4f | 128 | }///end if |
arturojat | 0:8c9252649f4f | 129 | |
arturojat | 0:8c9252649f4f | 130 | }//end if |
arturojat | 0:8c9252649f4f | 131 | |
arturojat | 0:8c9252649f4f | 132 | }//end if |
arturojat | 0:8c9252649f4f | 133 | else if(!Dip4) { |
arturojat | 0:8c9252649f4f | 134 | measureBtn.attach_asserted(&measureCom2Cycle); |
arturojat | 0:8c9252649f4f | 135 | wBtn.attach_asserted(&changeWUnits); |
arturojat | 0:8c9252649f4f | 136 | dimBtn.attach_asserted(&changeDUnits); |
arturojat | 0:8c9252649f4f | 137 | ErrorBtn.attach_asserted(&ErrorGen); |
arturojat | 0:8c9252649f4f | 138 | } else if(!Dip5) { |
arturojat | 0:8c9252649f4f | 139 | measureBtn.attach_asserted(&measureCom2TS); |
arturojat | 0:8c9252649f4f | 140 | wBtn.attach_asserted(&changeWUnits); |
arturojat | 0:8c9252649f4f | 141 | dimBtn.attach_asserted(&changeDUnits); |
arturojat | 0:8c9252649f4f | 142 | ErrorBtn.attach_asserted(&ErrorGen); |
arturojat | 0:8c9252649f4f | 143 | |
arturojat | 0:8c9252649f4f | 144 | } |
arturojat | 0:8c9252649f4f | 145 | }//end while |
arturojat | 0:8c9252649f4f | 146 | }//end main |
arturojat | 0:8c9252649f4f | 147 | |
arturojat | 0:8c9252649f4f | 148 | |
arturojat | 0:8c9252649f4f | 149 | /********************************************************* |
arturojat | 0:8c9252649f4f | 150 | * * |
arturojat | 0:8c9252649f4f | 151 | * Command Functions * |
arturojat | 0:8c9252649f4f | 152 | * * |
arturojat | 0:8c9252649f4f | 153 | **********************************************************/ |
arturojat | 0:8c9252649f4f | 154 | /* |
arturojat | 0:8c9252649f4f | 155 | *Dimension Calibration |
arturojat | 0:8c9252649f4f | 156 | * |
arturojat | 0:8c9252649f4f | 157 | *This function is required when one of the sensors is replaced or |
arturojat | 0:8c9252649f4f | 158 | *moved, when a new controller is intalled , or for routine calibration. |
arturojat | 0:8c9252649f4f | 159 | *This command causes the CubiScan to reply with a dimension calibratopn codea each time it s issued. |
arturojat | 0:8c9252649f4f | 160 | *This command must be issued SIX time to complete sensor calibration. |
arturojat | 0:8c9252649f4f | 161 | */ |
arturojat | 0:8c9252649f4f | 162 | void dimensionCalibration(char* command) |
arturojat | 0:8c9252649f4f | 163 | { |
arturojat | 0:8c9252649f4f | 164 | char respond[9]= {' '}; |
arturojat | 0:8c9252649f4f | 165 | |
arturojat | 0:8c9252649f4f | 166 | if(command[2]== ETX) { |
arturojat | 0:8c9252649f4f | 167 | respond[0]= STX; |
arturojat | 0:8c9252649f4f | 168 | respond[1]= 'D'; |
arturojat | 0:8c9252649f4f | 169 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 170 | respond[3]='0'; |
arturojat | 0:8c9252649f4f | 171 | respond[4]='0'; |
arturojat | 0:8c9252649f4f | 172 | respond[5]= ETX; |
arturojat | 0:8c9252649f4f | 173 | respond[6]=CR; |
arturojat | 0:8c9252649f4f | 174 | respond[7]=LF; |
arturojat | 0:8c9252649f4f | 175 | respond[8]='\0'; |
arturojat | 0:8c9252649f4f | 176 | } else { |
arturojat | 0:8c9252649f4f | 177 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 178 | respond[1]='D'; |
arturojat | 0:8c9252649f4f | 179 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 180 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 181 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 182 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 183 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 184 | } |
arturojat | 0:8c9252649f4f | 185 | printString(respond); |
arturojat | 0:8c9252649f4f | 186 | }//end dimensionCalibration |
arturojat | 0:8c9252649f4f | 187 | |
arturojat | 0:8c9252649f4f | 188 | |
arturojat | 0:8c9252649f4f | 189 | /* |
arturojat | 0:8c9252649f4f | 190 | *Dimension Units |
arturojat | 0:8c9252649f4f | 191 | * |
arturojat | 0:8c9252649f4f | 192 | *This command is used to set the dimension units to either English(inches) |
arturojat | 0:8c9252649f4f | 193 | *or metric (centimeters) mode. |
arturojat | 0:8c9252649f4f | 194 | * |
arturojat | 0:8c9252649f4f | 195 | */ |
arturojat | 0:8c9252649f4f | 196 | char dimensionUnits(char* command) |
arturojat | 0:8c9252649f4f | 197 | { |
arturojat | 0:8c9252649f4f | 198 | char respond[7]; |
arturojat | 0:8c9252649f4f | 199 | char newUnits; |
arturojat | 0:8c9252649f4f | 200 | if((command[3]== ETX)&&(command[4]== CR)&&(command[5]== LF)&&((command[2]=='M')||(command[2]=='E'))) { |
arturojat | 0:8c9252649f4f | 201 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 202 | respond[1]='"'; |
arturojat | 0:8c9252649f4f | 203 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 204 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 205 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 206 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 207 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 208 | newUnits = command[2]; |
arturojat | 0:8c9252649f4f | 209 | }//end if |
arturojat | 0:8c9252649f4f | 210 | else { |
arturojat | 0:8c9252649f4f | 211 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 212 | respond[1]='"'; |
arturojat | 0:8c9252649f4f | 213 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 214 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 215 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 216 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 217 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 218 | newUnits = dimUnitsValue; |
arturojat | 0:8c9252649f4f | 219 | }//end else |
arturojat | 0:8c9252649f4f | 220 | |
arturojat | 0:8c9252649f4f | 221 | printString(respond); |
arturojat | 0:8c9252649f4f | 222 | return newUnits; |
arturojat | 0:8c9252649f4f | 223 | }//end dimensionUnits |
arturojat | 0:8c9252649f4f | 224 | |
arturojat | 0:8c9252649f4f | 225 | |
arturojat | 0:8c9252649f4f | 226 | /* |
arturojat | 0:8c9252649f4f | 227 | *Factor Toggle |
arturojat | 0:8c9252649f4f | 228 | * |
arturojat | 0:8c9252649f4f | 229 | *This command is used to set the dimensional factor to either |
arturojat | 0:8c9252649f4f | 230 | *domestic or international. |
arturojat | 0:8c9252649f4f | 231 | */ |
arturojat | 0:8c9252649f4f | 232 | char factorToggle(char* command) |
arturojat | 0:8c9252649f4f | 233 | { |
arturojat | 0:8c9252649f4f | 234 | char respond[7]; |
arturojat | 0:8c9252649f4f | 235 | int newFactor; |
arturojat | 0:8c9252649f4f | 236 | if((command[3]== ETX)&&(command[4]== CR)&&(command[5]== LF)&&((command[2]=='I')||(command[2]=='D'))) { |
arturojat | 0:8c9252649f4f | 237 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 238 | respond[1]='F'; |
arturojat | 0:8c9252649f4f | 239 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 240 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 241 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 242 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 243 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 244 | |
arturojat | 0:8c9252649f4f | 245 | newFactor=command[2]; |
arturojat | 0:8c9252649f4f | 246 | |
arturojat | 0:8c9252649f4f | 247 | }//end if |
arturojat | 0:8c9252649f4f | 248 | else { |
arturojat | 0:8c9252649f4f | 249 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 250 | respond[1]='F'; |
arturojat | 0:8c9252649f4f | 251 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 252 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 253 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 254 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 255 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 256 | |
arturojat | 0:8c9252649f4f | 257 | newFactor = factor; |
arturojat | 0:8c9252649f4f | 258 | }//end else |
arturojat | 0:8c9252649f4f | 259 | pc.puts(respond); |
arturojat | 0:8c9252649f4f | 260 | return newFactor; |
arturojat | 0:8c9252649f4f | 261 | |
arturojat | 0:8c9252649f4f | 262 | }//end factorToggle |
arturojat | 0:8c9252649f4f | 263 | |
arturojat | 0:8c9252649f4f | 264 | /* |
arturojat | 0:8c9252649f4f | 265 | *Location Id/City Code |
arturojat | 0:8c9252649f4f | 266 | * |
arturojat | 0:8c9252649f4f | 267 | *This command is used to set the CubiScan location identification. |
arturojat | 0:8c9252649f4f | 268 | *This data is stored in permanent memory and need only be set once |
arturojat | 0:8c9252649f4f | 269 | *for each Cubiscan |
arturojat | 0:8c9252649f4f | 270 | */ |
arturojat | 0:8c9252649f4f | 271 | void locationId(char* command) |
arturojat | 0:8c9252649f4f | 272 | { |
arturojat | 0:8c9252649f4f | 273 | char respond[7]; |
arturojat | 0:8c9252649f4f | 274 | if((command[8]== ETX)&&(command[9]== CR)&&(command[10]== LF)) { |
arturojat | 0:8c9252649f4f | 275 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 276 | respond[1]='L'; |
arturojat | 0:8c9252649f4f | 277 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 278 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 279 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 280 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 281 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 282 | |
arturojat | 0:8c9252649f4f | 283 | id[0]=command[2]; |
arturojat | 0:8c9252649f4f | 284 | id[1]=command[3]; |
arturojat | 0:8c9252649f4f | 285 | id[2]=command[4]; |
arturojat | 0:8c9252649f4f | 286 | id[3]=command[5]; |
arturojat | 0:8c9252649f4f | 287 | id[4]=command[6]; |
arturojat | 0:8c9252649f4f | 288 | id[5]=command[7]; |
arturojat | 0:8c9252649f4f | 289 | |
arturojat | 0:8c9252649f4f | 290 | }//end if |
arturojat | 0:8c9252649f4f | 291 | else { |
arturojat | 0:8c9252649f4f | 292 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 293 | respond[1]='L'; |
arturojat | 0:8c9252649f4f | 294 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 295 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 296 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 297 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 298 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 299 | |
arturojat | 0:8c9252649f4f | 300 | |
arturojat | 0:8c9252649f4f | 301 | }//end else |
arturojat | 0:8c9252649f4f | 302 | printString(respond); |
arturojat | 0:8c9252649f4f | 303 | |
arturojat | 0:8c9252649f4f | 304 | }//end locationId |
arturojat | 0:8c9252649f4f | 305 | |
arturojat | 0:8c9252649f4f | 306 | void measure(char* command) |
arturojat | 0:8c9252649f4f | 307 | { |
arturojat | 0:8c9252649f4f | 308 | char medidasCm[5][4]= {{'1','0','0','0'},{' ','9','8','2'}, |
arturojat | 0:8c9252649f4f | 309 | {' ',' ','8','3'},{' ','3','4','8'}, |
arturojat | 0:8c9252649f4f | 310 | {' ','7','6','4'} |
arturojat | 0:8c9252649f4f | 311 | }; |
arturojat | 0:8c9252649f4f | 312 | char medidasIn[5][4]= {{' ','3','9','3'},{' ','3','8','6'}, |
arturojat | 0:8c9252649f4f | 313 | {' ',' ','3','3'},{' ','1','3','7'}, |
arturojat | 0:8c9252649f4f | 314 | {' ','3','0','0'} |
arturojat | 0:8c9252649f4f | 315 | }; |
arturojat | 0:8c9252649f4f | 316 | char pesoLb[6][5]= {{'1','5','0','0','0'},{' ','7','9','1','5'}, |
arturojat | 0:8c9252649f4f | 317 | {' ','6','3','2','5'} |
arturojat | 0:8c9252649f4f | 318 | }; |
arturojat | 0:8c9252649f4f | 319 | |
arturojat | 0:8c9252649f4f | 320 | char pesoKg[3][5]= {{' ','6','8','0','3'},{' ','3','5','9','0'}, |
arturojat | 0:8c9252649f4f | 321 | {' ','2','8','6','8'} |
arturojat | 0:8c9252649f4f | 322 | }; |
arturojat | 0:8c9252649f4f | 323 | |
arturojat | 0:8c9252649f4f | 324 | char dimLbD[3][5]= {{' ','2','9','7','6'},{' ','1','0','4','0'},{' ',' ','8','0','9'}}; |
arturojat | 0:8c9252649f4f | 325 | char dimLbI[3][5]= {{' ','3','6','3','7'},{' ','1','3','2','2'},{' ',' ','9','9','2'}}; |
arturojat | 0:8c9252649f4f | 326 | |
arturojat | 0:8c9252649f4f | 327 | char dimKgD[3][5]= {{' ','1','3','5','0'},{' ',' ','4','7','2'},{' ',' ','3','6','7'}}; |
arturojat | 0:8c9252649f4f | 328 | char dimKgI[3][5]= {{' ','1','6','5','0'},{' ',' ','6','0','0'},{' ',' ','4','5','0'}}; |
arturojat | 0:8c9252649f4f | 329 | int token = rand()%2; |
arturojat | 0:8c9252649f4f | 330 | char respond[63]= {' '}; |
arturojat | 0:8c9252649f4f | 331 | if(command[2]==ETX) { |
arturojat | 0:8c9252649f4f | 332 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 333 | respond[1]='M'; |
arturojat | 0:8c9252649f4f | 334 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 335 | respond[3]='H'; |
arturojat | 0:8c9252649f4f | 336 | respond[4]=id[0]; |
arturojat | 0:8c9252649f4f | 337 | respond[5]=id[1]; |
arturojat | 0:8c9252649f4f | 338 | respond[6]=id[2]; |
arturojat | 0:8c9252649f4f | 339 | respond[7]=id[3]; |
arturojat | 0:8c9252649f4f | 340 | respond[8]=id[4]; |
arturojat | 0:8c9252649f4f | 341 | respond[9]=id[5]; |
arturojat | 0:8c9252649f4f | 342 | respond[10]=','; |
arturojat | 0:8c9252649f4f | 343 | if(dimUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 344 | respond[11]='L'; |
arturojat | 0:8c9252649f4f | 345 | respond[12]=medidasIn[token][0]; |
arturojat | 0:8c9252649f4f | 346 | respond[13]=medidasIn[token][1]; |
arturojat | 0:8c9252649f4f | 347 | respond[14]=medidasIn[token][2]; |
arturojat | 0:8c9252649f4f | 348 | respond[15]='.'; |
arturojat | 0:8c9252649f4f | 349 | respond[16]=medidasIn[token][3]; |
arturojat | 0:8c9252649f4f | 350 | respond[17]=','; |
arturojat | 0:8c9252649f4f | 351 | respond[18]='W'; |
arturojat | 0:8c9252649f4f | 352 | respond[19]=medidasIn[token+1][0]; |
arturojat | 0:8c9252649f4f | 353 | respond[20]=medidasIn[token+1][1]; |
arturojat | 0:8c9252649f4f | 354 | respond[21]=medidasIn[token+1][2]; |
arturojat | 0:8c9252649f4f | 355 | respond[22]='.'; |
arturojat | 0:8c9252649f4f | 356 | respond[23]=medidasIn[token+1][3]; |
arturojat | 0:8c9252649f4f | 357 | respond[24]=','; |
arturojat | 0:8c9252649f4f | 358 | respond[25]='H'; |
arturojat | 0:8c9252649f4f | 359 | respond[26]=medidasIn[token+2][0]; |
arturojat | 0:8c9252649f4f | 360 | respond[27]=medidasIn[token+2][1]; |
arturojat | 0:8c9252649f4f | 361 | respond[28]=medidasIn[token+2][2]; |
arturojat | 0:8c9252649f4f | 362 | respond[29]='.'; |
arturojat | 0:8c9252649f4f | 363 | respond[30]=medidasIn[token+2][3]; |
arturojat | 0:8c9252649f4f | 364 | } else { |
arturojat | 0:8c9252649f4f | 365 | respond[11]='L'; |
arturojat | 0:8c9252649f4f | 366 | respond[12]=medidasCm[token][0]; |
arturojat | 0:8c9252649f4f | 367 | respond[13]=medidasCm[token][1]; |
arturojat | 0:8c9252649f4f | 368 | respond[14]=medidasCm[token][2]; |
arturojat | 0:8c9252649f4f | 369 | respond[15]='.'; |
arturojat | 0:8c9252649f4f | 370 | respond[16]=medidasCm[token][3]; |
arturojat | 0:8c9252649f4f | 371 | respond[17]=','; |
arturojat | 0:8c9252649f4f | 372 | respond[18]='W'; |
arturojat | 0:8c9252649f4f | 373 | respond[19]=medidasCm[token+1][0]; |
arturojat | 0:8c9252649f4f | 374 | respond[20]=medidasCm[token+1][1]; |
arturojat | 0:8c9252649f4f | 375 | respond[21]=medidasCm[token+1][2]; |
arturojat | 0:8c9252649f4f | 376 | respond[22]='.'; |
arturojat | 0:8c9252649f4f | 377 | respond[23]=medidasCm[token+1][3]; |
arturojat | 0:8c9252649f4f | 378 | respond[24]=','; |
arturojat | 0:8c9252649f4f | 379 | respond[25]='H'; |
arturojat | 0:8c9252649f4f | 380 | respond[26]=medidasCm[token+2][0]; |
arturojat | 0:8c9252649f4f | 381 | respond[27]=medidasCm[token+2][1]; |
arturojat | 0:8c9252649f4f | 382 | respond[28]=medidasCm[token+2][2]; |
arturojat | 0:8c9252649f4f | 383 | respond[29]='.'; |
arturojat | 0:8c9252649f4f | 384 | respond[30]=medidasCm[token+2][3]; |
arturojat | 0:8c9252649f4f | 385 | } |
arturojat | 0:8c9252649f4f | 386 | if(wUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 387 | respond[31]=','; |
arturojat | 0:8c9252649f4f | 388 | respond[32]=dimUnitsValue; |
arturojat | 0:8c9252649f4f | 389 | respond[33]=','; |
arturojat | 0:8c9252649f4f | 390 | respond[34]='K'; |
arturojat | 0:8c9252649f4f | 391 | respond[35]=pesoLb[token][0]; |
arturojat | 0:8c9252649f4f | 392 | respond[36]=pesoLb[token][1]; |
arturojat | 0:8c9252649f4f | 393 | respond[37]=pesoLb[token][2]; |
arturojat | 0:8c9252649f4f | 394 | respond[38]='.'; |
arturojat | 0:8c9252649f4f | 395 | respond[39]=pesoLb[token][3]; |
arturojat | 0:8c9252649f4f | 396 | respond[40]=pesoLb[token][4]; |
arturojat | 0:8c9252649f4f | 397 | respond[41]=','; |
arturojat | 0:8c9252649f4f | 398 | if(factor=='D') { |
arturojat | 0:8c9252649f4f | 399 | respond[42]='D'; |
arturojat | 0:8c9252649f4f | 400 | respond[43]=dimLbD[token][0]; |
arturojat | 0:8c9252649f4f | 401 | respond[44]=dimLbD[token][1]; |
arturojat | 0:8c9252649f4f | 402 | respond[45]=dimLbD[token][2]; |
arturojat | 0:8c9252649f4f | 403 | respond[46]='.'; |
arturojat | 0:8c9252649f4f | 404 | respond[47]=dimLbD[token][3]; |
arturojat | 0:8c9252649f4f | 405 | respond[48]=dimLbD[token][4]; |
arturojat | 0:8c9252649f4f | 406 | respond[49]=','; |
arturojat | 0:8c9252649f4f | 407 | respond[50]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 408 | respond[51]=','; |
arturojat | 0:8c9252649f4f | 409 | respond[52]='F'; |
arturojat | 0:8c9252649f4f | 410 | respond[53]=' '; |
arturojat | 0:8c9252649f4f | 411 | respond[54]='1'; |
arturojat | 0:8c9252649f4f | 412 | respond[55]='6'; |
arturojat | 0:8c9252649f4f | 413 | respond[56]='6'; |
arturojat | 0:8c9252649f4f | 414 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 415 | } else { |
arturojat | 0:8c9252649f4f | 416 | respond[42]='D'; |
arturojat | 0:8c9252649f4f | 417 | respond[43]=dimLbI[token][0]; |
arturojat | 0:8c9252649f4f | 418 | respond[44]=dimLbI[token][1]; |
arturojat | 0:8c9252649f4f | 419 | respond[45]=dimLbI[token][2]; |
arturojat | 0:8c9252649f4f | 420 | respond[46]='.'; |
arturojat | 0:8c9252649f4f | 421 | respond[47]=dimLbI[token][3]; |
arturojat | 0:8c9252649f4f | 422 | respond[48]=dimLbI[token][4]; |
arturojat | 0:8c9252649f4f | 423 | respond[49]=','; |
arturojat | 0:8c9252649f4f | 424 | respond[50]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 425 | respond[51]=','; |
arturojat | 0:8c9252649f4f | 426 | respond[52]='F'; |
arturojat | 0:8c9252649f4f | 427 | respond[53]=' '; |
arturojat | 0:8c9252649f4f | 428 | respond[54]='1'; |
arturojat | 0:8c9252649f4f | 429 | respond[55]='3'; |
arturojat | 0:8c9252649f4f | 430 | respond[56]='9'; |
arturojat | 0:8c9252649f4f | 431 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 432 | } |
arturojat | 0:8c9252649f4f | 433 | } else { |
arturojat | 0:8c9252649f4f | 434 | respond[31]=','; |
arturojat | 0:8c9252649f4f | 435 | respond[32]=dimUnitsValue; |
arturojat | 0:8c9252649f4f | 436 | respond[33]=','; |
arturojat | 0:8c9252649f4f | 437 | respond[34]='K'; |
arturojat | 0:8c9252649f4f | 438 | respond[35]=pesoKg[token][0]; |
arturojat | 0:8c9252649f4f | 439 | respond[36]=pesoKg[token][1]; |
arturojat | 0:8c9252649f4f | 440 | respond[37]=pesoKg[token][2]; |
arturojat | 0:8c9252649f4f | 441 | respond[38]='.'; |
arturojat | 0:8c9252649f4f | 442 | respond[39]=pesoKg[token][3]; |
arturojat | 0:8c9252649f4f | 443 | respond[40]=pesoKg[token][4]; |
arturojat | 0:8c9252649f4f | 444 | respond[41]=','; |
arturojat | 0:8c9252649f4f | 445 | if(factor=='D') { |
arturojat | 0:8c9252649f4f | 446 | respond[42]='D'; |
arturojat | 0:8c9252649f4f | 447 | respond[43]=dimKgD[token][0]; |
arturojat | 0:8c9252649f4f | 448 | respond[44]=dimKgD[token][1]; |
arturojat | 0:8c9252649f4f | 449 | respond[45]=dimKgD[token][2]; |
arturojat | 0:8c9252649f4f | 450 | respond[46]='.'; |
arturojat | 0:8c9252649f4f | 451 | respond[47]=dimKgD[token][3]; |
arturojat | 0:8c9252649f4f | 452 | respond[48]=dimKgD[token][4]; |
arturojat | 0:8c9252649f4f | 453 | respond[49]=','; |
arturojat | 0:8c9252649f4f | 454 | respond[50]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 455 | respond[51]=','; |
arturojat | 0:8c9252649f4f | 456 | respond[52]='F'; |
arturojat | 0:8c9252649f4f | 457 | respond[53]='6'; |
arturojat | 0:8c9252649f4f | 458 | respond[54]='0'; |
arturojat | 0:8c9252649f4f | 459 | respond[55]='0'; |
arturojat | 0:8c9252649f4f | 460 | respond[56]='0'; |
arturojat | 0:8c9252649f4f | 461 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 462 | } else { |
arturojat | 0:8c9252649f4f | 463 | respond[42]='D'; |
arturojat | 0:8c9252649f4f | 464 | respond[43]=dimKgI[token][0]; |
arturojat | 0:8c9252649f4f | 465 | respond[44]=dimKgI[token][1]; |
arturojat | 0:8c9252649f4f | 466 | respond[45]=dimKgI[token][2]; |
arturojat | 0:8c9252649f4f | 467 | respond[46]='.'; |
arturojat | 0:8c9252649f4f | 468 | respond[47]=dimKgI[token][3]; |
arturojat | 0:8c9252649f4f | 469 | respond[48]=dimKgI[token][4]; |
arturojat | 0:8c9252649f4f | 470 | respond[49]=','; |
arturojat | 0:8c9252649f4f | 471 | respond[50]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 472 | respond[51]=','; |
arturojat | 0:8c9252649f4f | 473 | respond[52]='F'; |
arturojat | 0:8c9252649f4f | 474 | respond[53]='5'; |
arturojat | 0:8c9252649f4f | 475 | respond[54]='0'; |
arturojat | 0:8c9252649f4f | 476 | respond[55]='0'; |
arturojat | 0:8c9252649f4f | 477 | respond[56]='0'; |
arturojat | 0:8c9252649f4f | 478 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 479 | } |
arturojat | 0:8c9252649f4f | 480 | } |
arturojat | 0:8c9252649f4f | 481 | respond[58]=factor; |
arturojat | 0:8c9252649f4f | 482 | respond[59]=ETX; |
arturojat | 0:8c9252649f4f | 483 | respond[60]=CR; |
arturojat | 0:8c9252649f4f | 484 | respond[61]=LF; |
arturojat | 0:8c9252649f4f | 485 | respond[62]='\0'; |
arturojat | 0:8c9252649f4f | 486 | }//end if |
arturojat | 0:8c9252649f4f | 487 | else { |
arturojat | 0:8c9252649f4f | 488 | respond[0] = STX; |
arturojat | 0:8c9252649f4f | 489 | respond[1] = 'M'; |
arturojat | 0:8c9252649f4f | 490 | respond[2] = 'N'; |
arturojat | 0:8c9252649f4f | 491 | respond[3] = 'H'; |
arturojat | 0:8c9252649f4f | 492 | respond[4] = 'M'; |
arturojat | 0:8c9252649f4f | 493 | respond[5] = ETX; |
arturojat | 0:8c9252649f4f | 494 | respond[6] = CR; |
arturojat | 0:8c9252649f4f | 495 | respond[7] = LF; |
arturojat | 0:8c9252649f4f | 496 | respond[8] = '\0'; |
arturojat | 0:8c9252649f4f | 497 | }//end else |
arturojat | 0:8c9252649f4f | 498 | printString(respond); |
arturojat | 0:8c9252649f4f | 499 | }//end measure |
arturojat | 0:8c9252649f4f | 500 | |
arturojat | 0:8c9252649f4f | 501 | |
arturojat | 0:8c9252649f4f | 502 | /* |
arturojat | 0:8c9252649f4f | 503 | *Scale Calibration |
arturojat | 0:8c9252649f4f | 504 | * |
arturojat | 0:8c9252649f4f | 505 | *This fuction is requiered when the load cell s replaced, |
arturojat | 0:8c9252649f4f | 506 | *when a new controller is installed, or for routine calibration. |
arturojat | 0:8c9252649f4f | 507 | *This command causes the CubiScan to reply with a scale calibration code. |
arturojat | 0:8c9252649f4f | 508 | *This command must be issued THREE times to complete scale calibration. |
arturojat | 0:8c9252649f4f | 509 | */ |
arturojat | 0:8c9252649f4f | 510 | void scaleCalibration(char* command) |
arturojat | 0:8c9252649f4f | 511 | { |
arturojat | 0:8c9252649f4f | 512 | char respond[8]; |
arturojat | 0:8c9252649f4f | 513 | if((command[2]== ETX)&&(command[3]== CR)&&(command[4]== LF)) { |
arturojat | 0:8c9252649f4f | 514 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 515 | respond[1]='S'; |
arturojat | 0:8c9252649f4f | 516 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 517 | respond[3]='0'; |
arturojat | 0:8c9252649f4f | 518 | respond[4]='0'; |
arturojat | 0:8c9252649f4f | 519 | respond[5]= ETX; |
arturojat | 0:8c9252649f4f | 520 | respond[6]=CR; |
arturojat | 0:8c9252649f4f | 521 | respond[7]=LF; |
arturojat | 0:8c9252649f4f | 522 | } else { |
arturojat | 0:8c9252649f4f | 523 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 524 | respond[1]='S'; |
arturojat | 0:8c9252649f4f | 525 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 526 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 527 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 528 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 529 | } |
arturojat | 0:8c9252649f4f | 530 | printString(respond); |
arturojat | 0:8c9252649f4f | 531 | }//end scaleCalibration |
arturojat | 0:8c9252649f4f | 532 | |
arturojat | 0:8c9252649f4f | 533 | /* |
arturojat | 0:8c9252649f4f | 534 | *Test |
arturojat | 0:8c9252649f4f | 535 | * |
arturojat | 0:8c9252649f4f | 536 | *This command couses the CubiScan to reply with an error code. |
arturojat | 0:8c9252649f4f | 537 | *A response of TA00 means that the CubiScan is ready and responding t transmission from the host. |
arturojat | 0:8c9252649f4f | 538 | *if the host recieves no response from the contro unit after sendingg this command, |
arturojat | 0:8c9252649f4f | 539 | *an error condition exists in the communications etween the host and the controller. |
arturojat | 0:8c9252649f4f | 540 | */ |
arturojat | 0:8c9252649f4f | 541 | void test(char* command) |
arturojat | 0:8c9252649f4f | 542 | { |
arturojat | 0:8c9252649f4f | 543 | char respond[9]; |
arturojat | 0:8c9252649f4f | 544 | if((command[2]== ETX)&&(command[3]== CR)&&(command[4]== LF)) { |
arturojat | 0:8c9252649f4f | 545 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 546 | respond[1]='T'; |
arturojat | 0:8c9252649f4f | 547 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 548 | respond[3]='0'; |
arturojat | 0:8c9252649f4f | 549 | respond[4]='0'; |
arturojat | 0:8c9252649f4f | 550 | respond[5]= ETX; |
arturojat | 0:8c9252649f4f | 551 | respond[6]=CR; |
arturojat | 0:8c9252649f4f | 552 | respond[7]=LF; |
arturojat | 0:8c9252649f4f | 553 | respond[8]='\0'; |
arturojat | 0:8c9252649f4f | 554 | } else { |
arturojat | 0:8c9252649f4f | 555 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 556 | respond[1]='T'; |
arturojat | 0:8c9252649f4f | 557 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 558 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 559 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 560 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 561 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 562 | } |
arturojat | 0:8c9252649f4f | 563 | //pc.puts(respond); |
arturojat | 0:8c9252649f4f | 564 | printString(respond); |
arturojat | 0:8c9252649f4f | 565 | }//end test |
arturojat | 0:8c9252649f4f | 566 | |
arturojat | 0:8c9252649f4f | 567 | |
arturojat | 0:8c9252649f4f | 568 | |
arturojat | 0:8c9252649f4f | 569 | /* |
arturojat | 0:8c9252649f4f | 570 | *Units |
arturojat | 0:8c9252649f4f | 571 | * |
arturojat | 0:8c9252649f4f | 572 | *This command causes the CubiScan to repot its |
arturojat | 0:8c9252649f4f | 573 | *current modes of operation. |
arturojat | 0:8c9252649f4f | 574 | */ |
arturojat | 0:8c9252649f4f | 575 | void units(char* command) |
arturojat | 0:8c9252649f4f | 576 | { |
arturojat | 0:8c9252649f4f | 577 | char respond[20]; |
arturojat | 0:8c9252649f4f | 578 | if((command[2]== ETX)&&(command[3]== CR)&&(command[4]== LF)) { |
arturojat | 0:8c9252649f4f | 579 | if(factor=='D') { |
arturojat | 0:8c9252649f4f | 580 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 581 | respond[1]='U'; |
arturojat | 0:8c9252649f4f | 582 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 583 | respond[3]=dimUnitsValue; |
arturojat | 0:8c9252649f4f | 584 | respond[4]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 585 | respond[5]='D'; |
arturojat | 0:8c9252649f4f | 586 | respond[6]=' '; |
arturojat | 0:8c9252649f4f | 587 | respond[7]='1'; |
arturojat | 0:8c9252649f4f | 588 | respond[8]='6'; |
arturojat | 0:8c9252649f4f | 589 | respond[9]='6'; |
arturojat | 0:8c9252649f4f | 590 | respond[10]=id[0]; |
arturojat | 0:8c9252649f4f | 591 | respond[11]=id[1]; |
arturojat | 0:8c9252649f4f | 592 | respond[12]=id[2]; |
arturojat | 0:8c9252649f4f | 593 | respond[13]=id[3]; |
arturojat | 0:8c9252649f4f | 594 | respond[14]=id[4]; |
arturojat | 0:8c9252649f4f | 595 | respond[15]=id[5]; |
arturojat | 0:8c9252649f4f | 596 | respond[16]=ETX; |
arturojat | 0:8c9252649f4f | 597 | respond[17]=CR; |
arturojat | 0:8c9252649f4f | 598 | respond[18]=LF; |
arturojat | 0:8c9252649f4f | 599 | respond[19]='\0'; |
arturojat | 0:8c9252649f4f | 600 | } else { |
arturojat | 0:8c9252649f4f | 601 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 602 | respond[1]='U'; |
arturojat | 0:8c9252649f4f | 603 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 604 | respond[3]=dimUnitsValue; |
arturojat | 0:8c9252649f4f | 605 | respond[4]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 606 | respond[5]='I'; |
arturojat | 0:8c9252649f4f | 607 | respond[6]=' '; |
arturojat | 0:8c9252649f4f | 608 | respond[7]='1'; |
arturojat | 0:8c9252649f4f | 609 | respond[8]='3'; |
arturojat | 0:8c9252649f4f | 610 | respond[9]='9'; |
arturojat | 0:8c9252649f4f | 611 | respond[10]=id[0]; |
arturojat | 0:8c9252649f4f | 612 | respond[11]=id[1]; |
arturojat | 0:8c9252649f4f | 613 | respond[12]=id[2]; |
arturojat | 0:8c9252649f4f | 614 | respond[13]=id[3]; |
arturojat | 0:8c9252649f4f | 615 | respond[14]=id[4]; |
arturojat | 0:8c9252649f4f | 616 | respond[15]=id[5]; |
arturojat | 0:8c9252649f4f | 617 | respond[16]=ETX; |
arturojat | 0:8c9252649f4f | 618 | respond[17]=CR; |
arturojat | 0:8c9252649f4f | 619 | respond[18]=LF; |
arturojat | 0:8c9252649f4f | 620 | respond[19]='\0'; |
arturojat | 0:8c9252649f4f | 621 | |
arturojat | 0:8c9252649f4f | 622 | } |
arturojat | 0:8c9252649f4f | 623 | } else { |
arturojat | 0:8c9252649f4f | 624 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 625 | respond[1]='U'; |
arturojat | 0:8c9252649f4f | 626 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 627 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 628 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 629 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 630 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 631 | } |
arturojat | 0:8c9252649f4f | 632 | printString(respond); |
arturojat | 0:8c9252649f4f | 633 | }//end units |
arturojat | 0:8c9252649f4f | 634 | |
arturojat | 0:8c9252649f4f | 635 | /** |
arturojat | 0:8c9252649f4f | 636 | *Values |
arturojat | 0:8c9252649f4f | 637 | * |
arturojat | 0:8c9252649f4f | 638 | *This command causes the CubiScan to report all of itrs internal |
arturojat | 0:8c9252649f4f | 639 | *paraneters. This is useful for troubleshooting. |
arturojat | 0:8c9252649f4f | 640 | */ |
arturojat | 0:8c9252649f4f | 641 | void values(char* command) |
arturojat | 0:8c9252649f4f | 642 | { |
arturojat | 0:8c9252649f4f | 643 | char respond[157]; |
arturojat | 0:8c9252649f4f | 644 | if((command[2]== ETX)&&(command[3]== CR)&&(command[4]== LF)) { |
arturojat | 0:8c9252649f4f | 645 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 646 | respond[1]='V'; |
arturojat | 0:8c9252649f4f | 647 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 648 | respond[3]='0'; |
arturojat | 0:8c9252649f4f | 649 | respond[4]='0'; |
arturojat | 0:8c9252649f4f | 650 | respond[5]='.'; |
arturojat | 0:8c9252649f4f | 651 | respond[6]='0'; |
arturojat | 0:8c9252649f4f | 652 | respond[7]=','; |
arturojat | 0:8c9252649f4f | 653 | respond[8]='0'; |
arturojat | 0:8c9252649f4f | 654 | respond[9]='0'; |
arturojat | 0:8c9252649f4f | 655 | respond[10]='.'; |
arturojat | 0:8c9252649f4f | 656 | respond[11]='0'; |
arturojat | 0:8c9252649f4f | 657 | respond[12]=','; |
arturojat | 0:8c9252649f4f | 658 | respond[13]='0'; |
arturojat | 0:8c9252649f4f | 659 | respond[14]='0'; |
arturojat | 0:8c9252649f4f | 660 | respond[15]='.'; |
arturojat | 0:8c9252649f4f | 661 | respond[16]='0'; |
arturojat | 0:8c9252649f4f | 662 | respond[17]=','; |
arturojat | 0:8c9252649f4f | 663 | respond[18]='0'; |
arturojat | 0:8c9252649f4f | 664 | respond[19]='0'; |
arturojat | 0:8c9252649f4f | 665 | respond[20]='.'; |
arturojat | 0:8c9252649f4f | 666 | respond[21]='0'; |
arturojat | 0:8c9252649f4f | 667 | respond[22]=','; |
arturojat | 0:8c9252649f4f | 668 | respond[23]='0'; |
arturojat | 0:8c9252649f4f | 669 | respond[24]='0'; |
arturojat | 0:8c9252649f4f | 670 | respond[25]='0'; |
arturojat | 0:8c9252649f4f | 671 | respond[26]='0'; |
arturojat | 0:8c9252649f4f | 672 | respond[27]=','; |
arturojat | 0:8c9252649f4f | 673 | respond[28]='0'; |
arturojat | 0:8c9252649f4f | 674 | respond[29]='0'; |
arturojat | 0:8c9252649f4f | 675 | respond[30]='0'; |
arturojat | 0:8c9252649f4f | 676 | respond[31]='0'; |
arturojat | 0:8c9252649f4f | 677 | respond[32]=','; |
arturojat | 0:8c9252649f4f | 678 | respond[33]='0'; |
arturojat | 0:8c9252649f4f | 679 | respond[34]='0'; |
arturojat | 0:8c9252649f4f | 680 | respond[35]='0'; |
arturojat | 0:8c9252649f4f | 681 | respond[36]='0'; |
arturojat | 0:8c9252649f4f | 682 | respond[37]=','; |
arturojat | 0:8c9252649f4f | 683 | respond[38]='0'; |
arturojat | 0:8c9252649f4f | 684 | respond[39]='0'; |
arturojat | 0:8c9252649f4f | 685 | respond[40]='0'; |
arturojat | 0:8c9252649f4f | 686 | respond[41]='0'; |
arturojat | 0:8c9252649f4f | 687 | respond[42]=','; |
arturojat | 0:8c9252649f4f | 688 | respond[43]='0'; |
arturojat | 0:8c9252649f4f | 689 | respond[44]='0'; |
arturojat | 0:8c9252649f4f | 690 | respond[45]='.'; |
arturojat | 0:8c9252649f4f | 691 | respond[46]='0'; |
arturojat | 0:8c9252649f4f | 692 | respond[47]=','; |
arturojat | 0:8c9252649f4f | 693 | respond[48]='0'; |
arturojat | 0:8c9252649f4f | 694 | respond[49]='0'; |
arturojat | 0:8c9252649f4f | 695 | respond[50]='.'; |
arturojat | 0:8c9252649f4f | 696 | respond[51]='0'; |
arturojat | 0:8c9252649f4f | 697 | respond[52]=','; |
arturojat | 0:8c9252649f4f | 698 | respond[53]='0'; |
arturojat | 0:8c9252649f4f | 699 | respond[54]='0'; |
arturojat | 0:8c9252649f4f | 700 | respond[55]='.'; |
arturojat | 0:8c9252649f4f | 701 | respond[56]='0'; |
arturojat | 0:8c9252649f4f | 702 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 703 | respond[58]='0'; |
arturojat | 0:8c9252649f4f | 704 | respond[59]='0'; |
arturojat | 0:8c9252649f4f | 705 | respond[60]='.'; |
arturojat | 0:8c9252649f4f | 706 | respond[61]='0'; |
arturojat | 0:8c9252649f4f | 707 | respond[62]=','; |
arturojat | 0:8c9252649f4f | 708 | respond[63]='0'; |
arturojat | 0:8c9252649f4f | 709 | respond[64]='0'; |
arturojat | 0:8c9252649f4f | 710 | respond[65]='.'; |
arturojat | 0:8c9252649f4f | 711 | respond[66]='0'; |
arturojat | 0:8c9252649f4f | 712 | respond[67]=','; |
arturojat | 0:8c9252649f4f | 713 | respond[68]='0'; |
arturojat | 0:8c9252649f4f | 714 | respond[69]='0'; |
arturojat | 0:8c9252649f4f | 715 | respond[70]='.'; |
arturojat | 0:8c9252649f4f | 716 | respond[71]='0'; |
arturojat | 0:8c9252649f4f | 717 | respond[72]=','; |
arturojat | 0:8c9252649f4f | 718 | respond[73]='0'; |
arturojat | 0:8c9252649f4f | 719 | respond[74]='0'; |
arturojat | 0:8c9252649f4f | 720 | respond[75]='.'; |
arturojat | 0:8c9252649f4f | 721 | respond[76]='0'; |
arturojat | 0:8c9252649f4f | 722 | respond[77]=','; |
arturojat | 0:8c9252649f4f | 723 | respond[78]='0'; |
arturojat | 0:8c9252649f4f | 724 | respond[79]='0'; |
arturojat | 0:8c9252649f4f | 725 | respond[80]='.'; |
arturojat | 0:8c9252649f4f | 726 | respond[81]='0'; |
arturojat | 0:8c9252649f4f | 727 | respond[82]=','; |
arturojat | 0:8c9252649f4f | 728 | respond[83]='0'; |
arturojat | 0:8c9252649f4f | 729 | respond[84]='0'; |
arturojat | 0:8c9252649f4f | 730 | respond[85]=','; |
arturojat | 0:8c9252649f4f | 731 | respond[86]='0'; |
arturojat | 0:8c9252649f4f | 732 | respond[87]='0'; |
arturojat | 0:8c9252649f4f | 733 | respond[88]=','; |
arturojat | 0:8c9252649f4f | 734 | respond[89]='0'; |
arturojat | 0:8c9252649f4f | 735 | respond[90]='0'; |
arturojat | 0:8c9252649f4f | 736 | respond[91]=','; |
arturojat | 0:8c9252649f4f | 737 | respond[92]='0'; |
arturojat | 0:8c9252649f4f | 738 | respond[93]='0'; |
arturojat | 0:8c9252649f4f | 739 | respond[94]=','; |
arturojat | 0:8c9252649f4f | 740 | respond[95]='0'; |
arturojat | 0:8c9252649f4f | 741 | respond[96]='0'; |
arturojat | 0:8c9252649f4f | 742 | respond[97]='0'; |
arturojat | 0:8c9252649f4f | 743 | respond[98]=','; |
arturojat | 0:8c9252649f4f | 744 | respond[99]='0'; |
arturojat | 0:8c9252649f4f | 745 | respond[100]='0'; |
arturojat | 0:8c9252649f4f | 746 | respond[101]='0'; |
arturojat | 0:8c9252649f4f | 747 | respond[102]=','; |
arturojat | 0:8c9252649f4f | 748 | respond[103]='0'; |
arturojat | 0:8c9252649f4f | 749 | respond[104]='0'; |
arturojat | 0:8c9252649f4f | 750 | respond[105]='0'; |
arturojat | 0:8c9252649f4f | 751 | respond[106]=','; |
arturojat | 0:8c9252649f4f | 752 | respond[107]='0'; |
arturojat | 0:8c9252649f4f | 753 | respond[108]='0'; |
arturojat | 0:8c9252649f4f | 754 | respond[109]='0'; |
arturojat | 0:8c9252649f4f | 755 | respond[110]=','; |
arturojat | 0:8c9252649f4f | 756 | respond[111]='1'; |
arturojat | 0:8c9252649f4f | 757 | respond[112]='0'; |
arturojat | 0:8c9252649f4f | 758 | respond[113]='0'; |
arturojat | 0:8c9252649f4f | 759 | respond[114]='L'; |
arturojat | 0:8c9252649f4f | 760 | respond[115]=','; |
arturojat | 0:8c9252649f4f | 761 | respond[116]='1'; |
arturojat | 0:8c9252649f4f | 762 | respond[117]='0'; |
arturojat | 0:8c9252649f4f | 763 | respond[118]='0'; |
arturojat | 0:8c9252649f4f | 764 | respond[119]=','; |
arturojat | 0:8c9252649f4f | 765 | respond[120]='1'; |
arturojat | 0:8c9252649f4f | 766 | respond[121]='.'; |
arturojat | 0:8c9252649f4f | 767 | respond[122]='0'; |
arturojat | 0:8c9252649f4f | 768 | respond[123]='0'; |
arturojat | 0:8c9252649f4f | 769 | respond[124]='0'; |
arturojat | 0:8c9252649f4f | 770 | respond[125]=' '; |
arturojat | 0:8c9252649f4f | 771 | respond[126]=' '; |
arturojat | 0:8c9252649f4f | 772 | respond[127]=' '; |
arturojat | 0:8c9252649f4f | 773 | respond[128]=' '; |
arturojat | 0:8c9252649f4f | 774 | respond[129]=' '; |
arturojat | 0:8c9252649f4f | 775 | respond[130]=' '; |
arturojat | 0:8c9252649f4f | 776 | respond[131]=' '; |
arturojat | 0:8c9252649f4f | 777 | respond[132]=' '; |
arturojat | 0:8c9252649f4f | 778 | respond[133]=' '; |
arturojat | 0:8c9252649f4f | 779 | respond[134]=' '; |
arturojat | 0:8c9252649f4f | 780 | respond[135]=' '; |
arturojat | 0:8c9252649f4f | 781 | respond[136]=' '; |
arturojat | 0:8c9252649f4f | 782 | respond[137]=' '; |
arturojat | 0:8c9252649f4f | 783 | respond[138]=' '; |
arturojat | 0:8c9252649f4f | 784 | respond[139]=' '; |
arturojat | 0:8c9252649f4f | 785 | respond[140]=' '; |
arturojat | 0:8c9252649f4f | 786 | respond[141]=' '; |
arturojat | 0:8c9252649f4f | 787 | respond[142]=' '; |
arturojat | 0:8c9252649f4f | 788 | respond[143]=' '; |
arturojat | 0:8c9252649f4f | 789 | respond[144]=' '; |
arturojat | 0:8c9252649f4f | 790 | respond[145]=' '; |
arturojat | 0:8c9252649f4f | 791 | respond[146]=' '; |
arturojat | 0:8c9252649f4f | 792 | respond[147]=' '; |
arturojat | 0:8c9252649f4f | 793 | respond[148]=' '; |
arturojat | 0:8c9252649f4f | 794 | respond[149]=' '; |
arturojat | 0:8c9252649f4f | 795 | respond[150]=' '; |
arturojat | 0:8c9252649f4f | 796 | respond[151]=' '; |
arturojat | 0:8c9252649f4f | 797 | respond[152]=' '; |
arturojat | 0:8c9252649f4f | 798 | respond[153]=ETX; |
arturojat | 0:8c9252649f4f | 799 | respond[154]=CR; |
arturojat | 0:8c9252649f4f | 800 | respond[155]=LF; |
arturojat | 0:8c9252649f4f | 801 | respond[156]='\0'; |
arturojat | 0:8c9252649f4f | 802 | |
arturojat | 0:8c9252649f4f | 803 | } else { |
arturojat | 0:8c9252649f4f | 804 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 805 | respond[1]='V'; |
arturojat | 0:8c9252649f4f | 806 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 807 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 808 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 809 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 810 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 811 | } |
arturojat | 0:8c9252649f4f | 812 | printString(respond); |
arturojat | 0:8c9252649f4f | 813 | |
arturojat | 0:8c9252649f4f | 814 | }//end values |
arturojat | 0:8c9252649f4f | 815 | |
arturojat | 0:8c9252649f4f | 816 | |
arturojat | 0:8c9252649f4f | 817 | /** |
arturojat | 0:8c9252649f4f | 818 | *Weight Units |
arturojat | 0:8c9252649f4f | 819 | * |
arturojat | 0:8c9252649f4f | 820 | *This command is used to set the weight units to either English |
arturojat | 0:8c9252649f4f | 821 | *(pounds) or metric (kilograms) mode. |
arturojat | 0:8c9252649f4f | 822 | * |
arturojat | 0:8c9252649f4f | 823 | */ |
arturojat | 0:8c9252649f4f | 824 | char weightUnits(char* command) |
arturojat | 0:8c9252649f4f | 825 | { |
arturojat | 0:8c9252649f4f | 826 | char respond[7]; |
arturojat | 0:8c9252649f4f | 827 | char newUnits; |
arturojat | 0:8c9252649f4f | 828 | if((command[3]== ETX)&&(command[4]== CR)&&(command[5]== LF)&&((command[2]=='M')||(command[2]=='E'))) { |
arturojat | 0:8c9252649f4f | 829 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 830 | respond[1]='#'; |
arturojat | 0:8c9252649f4f | 831 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 832 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 833 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 834 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 835 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 836 | newUnits = command[2]; |
arturojat | 0:8c9252649f4f | 837 | }//end if |
arturojat | 0:8c9252649f4f | 838 | else { |
arturojat | 0:8c9252649f4f | 839 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 840 | respond[1]='#'; |
arturojat | 0:8c9252649f4f | 841 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 842 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 843 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 844 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 845 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 846 | newUnits = wUnitsValue; |
arturojat | 0:8c9252649f4f | 847 | }//end else |
arturojat | 0:8c9252649f4f | 848 | printString(respond); |
arturojat | 0:8c9252649f4f | 849 | return newUnits; |
arturojat | 0:8c9252649f4f | 850 | }//end weightUnits |
arturojat | 0:8c9252649f4f | 851 | |
arturojat | 0:8c9252649f4f | 852 | |
arturojat | 0:8c9252649f4f | 853 | /* |
arturojat | 0:8c9252649f4f | 854 | *Zero |
arturojat | 0:8c9252649f4f | 855 | * |
arturojat | 0:8c9252649f4f | 856 | *This command should be issued periodically to force the CubiScan |
arturojat | 0:8c9252649f4f | 857 | *to perform interal compensations to adjust to changes in temperature |
arturojat | 0:8c9252649f4f | 858 | *and humidity. This command should onlu be issued when the measuring field is free of packages. |
arturojat | 0:8c9252649f4f | 859 | *Never issue this command when a pacage is present in the measuring field. |
arturojat | 0:8c9252649f4f | 860 | * |
arturojat | 0:8c9252649f4f | 861 | */ |
arturojat | 0:8c9252649f4f | 862 | |
arturojat | 0:8c9252649f4f | 863 | void zero(char* command) |
arturojat | 0:8c9252649f4f | 864 | { |
arturojat | 0:8c9252649f4f | 865 | char respond[7]; |
arturojat | 0:8c9252649f4f | 866 | if((command[2]== ETX)&&(command[3]== CR)&&(command[4]== LF)) { |
arturojat | 0:8c9252649f4f | 867 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 868 | respond[1]='Z'; |
arturojat | 0:8c9252649f4f | 869 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 870 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 871 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 872 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 873 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 874 | }//end if |
arturojat | 0:8c9252649f4f | 875 | else { |
arturojat | 0:8c9252649f4f | 876 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 877 | respond[1]='Z'; |
arturojat | 0:8c9252649f4f | 878 | respond[2]='N'; |
arturojat | 0:8c9252649f4f | 879 | respond[3]=ETX; |
arturojat | 0:8c9252649f4f | 880 | respond[4]=CR; |
arturojat | 0:8c9252649f4f | 881 | respond[5]=LF; |
arturojat | 0:8c9252649f4f | 882 | respond[6]='\0'; |
arturojat | 0:8c9252649f4f | 883 | }//end else |
arturojat | 0:8c9252649f4f | 884 | printString(respond); |
arturojat | 0:8c9252649f4f | 885 | }//end zero |
arturojat | 0:8c9252649f4f | 886 | |
arturojat | 0:8c9252649f4f | 887 | void printString(char * str) |
arturojat | 0:8c9252649f4f | 888 | { |
arturojat | 0:8c9252649f4f | 889 | printf("%s",str ); |
arturojat | 0:8c9252649f4f | 890 | }//end printString |
arturojat | 0:8c9252649f4f | 891 | |
arturojat | 0:8c9252649f4f | 892 | |
arturojat | 0:8c9252649f4f | 893 | void measureCom() |
arturojat | 0:8c9252649f4f | 894 | { |
arturojat | 0:8c9252649f4f | 895 | char medidasCm[5][4]= {{'1','0','0','0'},{' ','9','8','2'}, |
arturojat | 0:8c9252649f4f | 896 | {' ',' ','8','3'},{' ','3','4','8'}, |
arturojat | 0:8c9252649f4f | 897 | {' ','7','6','4'} |
arturojat | 0:8c9252649f4f | 898 | }; |
arturojat | 0:8c9252649f4f | 899 | char medidasIn[5][4]= {{' ','3','9','3'},{' ','3','8','6'}, |
arturojat | 0:8c9252649f4f | 900 | {' ',' ','3','3'},{' ','1','3','7'}, |
arturojat | 0:8c9252649f4f | 901 | {' ','3','0','0'} |
arturojat | 0:8c9252649f4f | 902 | }; |
arturojat | 0:8c9252649f4f | 903 | char pesoLb[6][5]= {{'1','5','0','0','0'},{' ','7','9','1','5'}, |
arturojat | 0:8c9252649f4f | 904 | {' ','6','3','2','5'} |
arturojat | 0:8c9252649f4f | 905 | }; |
arturojat | 0:8c9252649f4f | 906 | |
arturojat | 0:8c9252649f4f | 907 | char pesoKg[3][5]= {{' ','6','8','0','3'},{' ','3','5','9','0'}, |
arturojat | 0:8c9252649f4f | 908 | {' ','2','8','6','8'} |
arturojat | 0:8c9252649f4f | 909 | }; |
arturojat | 0:8c9252649f4f | 910 | |
arturojat | 0:8c9252649f4f | 911 | char dimLbD[3][5]= {{' ','2','9','7','6'},{' ','1','0','4','0'},{' ',' ','8','0','9'}}; |
arturojat | 0:8c9252649f4f | 912 | char dimLbI[3][5]= {{' ','3','6','3','7'},{' ','1','3','2','2'},{' ',' ','9','9','2'}}; |
arturojat | 0:8c9252649f4f | 913 | |
arturojat | 0:8c9252649f4f | 914 | char dimKgD[3][5]= {{' ','1','3','5','0'},{' ',' ','4','7','2'},{' ',' ','3','6','7'}}; |
arturojat | 0:8c9252649f4f | 915 | char dimKgI[3][5]= {{' ','1','6','5','0'},{' ',' ','6','0','0'},{' ',' ','4','5','0'}}; |
arturojat | 0:8c9252649f4f | 916 | int token = rand()%2; |
arturojat | 0:8c9252649f4f | 917 | char respond[63]= {' '}; |
arturojat | 0:8c9252649f4f | 918 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 919 | respond[1]='M'; |
arturojat | 0:8c9252649f4f | 920 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 921 | respond[3]='H'; |
arturojat | 0:8c9252649f4f | 922 | respond[4]=id[0]; |
arturojat | 0:8c9252649f4f | 923 | respond[5]=id[1]; |
arturojat | 0:8c9252649f4f | 924 | respond[6]=id[2]; |
arturojat | 0:8c9252649f4f | 925 | respond[7]=id[3]; |
arturojat | 0:8c9252649f4f | 926 | respond[8]=id[4]; |
arturojat | 0:8c9252649f4f | 927 | respond[9]=id[5]; |
arturojat | 0:8c9252649f4f | 928 | respond[10]=','; |
arturojat | 0:8c9252649f4f | 929 | if(dimUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 930 | respond[11]='L'; |
arturojat | 0:8c9252649f4f | 931 | respond[12]=medidasIn[token][0]; |
arturojat | 0:8c9252649f4f | 932 | respond[13]=medidasIn[token][1]; |
arturojat | 0:8c9252649f4f | 933 | respond[14]=medidasIn[token][2]; |
arturojat | 0:8c9252649f4f | 934 | respond[15]='.'; |
arturojat | 0:8c9252649f4f | 935 | respond[16]=medidasIn[token][3]; |
arturojat | 0:8c9252649f4f | 936 | respond[17]=','; |
arturojat | 0:8c9252649f4f | 937 | respond[18]='W'; |
arturojat | 0:8c9252649f4f | 938 | respond[19]=medidasIn[token+1][0]; |
arturojat | 0:8c9252649f4f | 939 | respond[20]=medidasIn[token+1][1]; |
arturojat | 0:8c9252649f4f | 940 | respond[21]=medidasIn[token+1][2]; |
arturojat | 0:8c9252649f4f | 941 | respond[22]='.'; |
arturojat | 0:8c9252649f4f | 942 | respond[23]=medidasIn[token+1][3]; |
arturojat | 0:8c9252649f4f | 943 | respond[24]=','; |
arturojat | 0:8c9252649f4f | 944 | respond[25]='H'; |
arturojat | 0:8c9252649f4f | 945 | respond[26]=medidasIn[token+2][0]; |
arturojat | 0:8c9252649f4f | 946 | respond[27]=medidasIn[token+2][1]; |
arturojat | 0:8c9252649f4f | 947 | respond[28]=medidasIn[token+2][2]; |
arturojat | 0:8c9252649f4f | 948 | respond[29]='.'; |
arturojat | 0:8c9252649f4f | 949 | respond[30]=medidasIn[token+2][3]; |
arturojat | 0:8c9252649f4f | 950 | } else { |
arturojat | 0:8c9252649f4f | 951 | respond[11]='L'; |
arturojat | 0:8c9252649f4f | 952 | respond[12]=medidasCm[token][0]; |
arturojat | 0:8c9252649f4f | 953 | respond[13]=medidasCm[token][1]; |
arturojat | 0:8c9252649f4f | 954 | respond[14]=medidasCm[token][2]; |
arturojat | 0:8c9252649f4f | 955 | respond[15]='.'; |
arturojat | 0:8c9252649f4f | 956 | respond[16]=medidasCm[token][3]; |
arturojat | 0:8c9252649f4f | 957 | respond[17]=','; |
arturojat | 0:8c9252649f4f | 958 | respond[18]='W'; |
arturojat | 0:8c9252649f4f | 959 | respond[19]=medidasCm[token+1][0]; |
arturojat | 0:8c9252649f4f | 960 | respond[20]=medidasCm[token+1][1]; |
arturojat | 0:8c9252649f4f | 961 | respond[21]=medidasCm[token+1][2]; |
arturojat | 0:8c9252649f4f | 962 | respond[22]='.'; |
arturojat | 0:8c9252649f4f | 963 | respond[23]=medidasCm[token+1][3]; |
arturojat | 0:8c9252649f4f | 964 | respond[24]=','; |
arturojat | 0:8c9252649f4f | 965 | respond[25]='H'; |
arturojat | 0:8c9252649f4f | 966 | respond[26]=medidasCm[token+2][0]; |
arturojat | 0:8c9252649f4f | 967 | respond[27]=medidasCm[token+2][1]; |
arturojat | 0:8c9252649f4f | 968 | respond[28]=medidasCm[token+2][2]; |
arturojat | 0:8c9252649f4f | 969 | respond[29]='.'; |
arturojat | 0:8c9252649f4f | 970 | respond[30]=medidasCm[token+2][3]; |
arturojat | 0:8c9252649f4f | 971 | } |
arturojat | 0:8c9252649f4f | 972 | if(wUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 973 | respond[31]=','; |
arturojat | 0:8c9252649f4f | 974 | respond[32]=dimUnitsValue; |
arturojat | 0:8c9252649f4f | 975 | respond[33]=','; |
arturojat | 0:8c9252649f4f | 976 | respond[34]='K'; |
arturojat | 0:8c9252649f4f | 977 | respond[35]=pesoLb[token][0]; |
arturojat | 0:8c9252649f4f | 978 | respond[36]=pesoLb[token][1]; |
arturojat | 0:8c9252649f4f | 979 | respond[37]=pesoLb[token][2]; |
arturojat | 0:8c9252649f4f | 980 | respond[38]='.'; |
arturojat | 0:8c9252649f4f | 981 | respond[39]=pesoLb[token][3]; |
arturojat | 0:8c9252649f4f | 982 | respond[40]=pesoLb[token][4]; |
arturojat | 0:8c9252649f4f | 983 | respond[41]=','; |
arturojat | 0:8c9252649f4f | 984 | if(factor=='D') { |
arturojat | 0:8c9252649f4f | 985 | respond[42]='D'; |
arturojat | 0:8c9252649f4f | 986 | respond[43]=dimLbD[token][0]; |
arturojat | 0:8c9252649f4f | 987 | respond[44]=dimLbD[token][1]; |
arturojat | 0:8c9252649f4f | 988 | respond[45]=dimLbD[token][2]; |
arturojat | 0:8c9252649f4f | 989 | respond[46]='.'; |
arturojat | 0:8c9252649f4f | 990 | respond[47]=dimLbD[token][3]; |
arturojat | 0:8c9252649f4f | 991 | respond[48]=dimLbD[token][4]; |
arturojat | 0:8c9252649f4f | 992 | respond[49]=','; |
arturojat | 0:8c9252649f4f | 993 | respond[50]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 994 | respond[51]=','; |
arturojat | 0:8c9252649f4f | 995 | respond[52]='F'; |
arturojat | 0:8c9252649f4f | 996 | respond[53]=' '; |
arturojat | 0:8c9252649f4f | 997 | respond[54]='1'; |
arturojat | 0:8c9252649f4f | 998 | respond[55]='6'; |
arturojat | 0:8c9252649f4f | 999 | respond[56]='6'; |
arturojat | 0:8c9252649f4f | 1000 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 1001 | } else { |
arturojat | 0:8c9252649f4f | 1002 | respond[42]='D'; |
arturojat | 0:8c9252649f4f | 1003 | respond[43]=dimLbI[token][0]; |
arturojat | 0:8c9252649f4f | 1004 | respond[44]=dimLbI[token][1]; |
arturojat | 0:8c9252649f4f | 1005 | respond[45]=dimLbI[token][2]; |
arturojat | 0:8c9252649f4f | 1006 | respond[46]='.'; |
arturojat | 0:8c9252649f4f | 1007 | respond[47]=dimLbI[token][3]; |
arturojat | 0:8c9252649f4f | 1008 | respond[48]=dimLbI[token][4]; |
arturojat | 0:8c9252649f4f | 1009 | respond[49]=','; |
arturojat | 0:8c9252649f4f | 1010 | respond[50]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 1011 | respond[51]=','; |
arturojat | 0:8c9252649f4f | 1012 | respond[52]='F'; |
arturojat | 0:8c9252649f4f | 1013 | respond[53]=' '; |
arturojat | 0:8c9252649f4f | 1014 | respond[54]='1'; |
arturojat | 0:8c9252649f4f | 1015 | respond[55]='3'; |
arturojat | 0:8c9252649f4f | 1016 | respond[56]='9'; |
arturojat | 0:8c9252649f4f | 1017 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 1018 | } |
arturojat | 0:8c9252649f4f | 1019 | } else { |
arturojat | 0:8c9252649f4f | 1020 | respond[31]=','; |
arturojat | 0:8c9252649f4f | 1021 | respond[32]=dimUnitsValue; |
arturojat | 0:8c9252649f4f | 1022 | respond[33]=','; |
arturojat | 0:8c9252649f4f | 1023 | respond[34]='K'; |
arturojat | 0:8c9252649f4f | 1024 | respond[35]=pesoKg[token][0]; |
arturojat | 0:8c9252649f4f | 1025 | respond[36]=pesoKg[token][1]; |
arturojat | 0:8c9252649f4f | 1026 | respond[37]=pesoKg[token][2]; |
arturojat | 0:8c9252649f4f | 1027 | respond[38]='.'; |
arturojat | 0:8c9252649f4f | 1028 | respond[39]=pesoKg[token][3]; |
arturojat | 0:8c9252649f4f | 1029 | respond[40]=pesoKg[token][4]; |
arturojat | 0:8c9252649f4f | 1030 | respond[41]=','; |
arturojat | 0:8c9252649f4f | 1031 | if(factor=='D') { |
arturojat | 0:8c9252649f4f | 1032 | respond[42]='D'; |
arturojat | 0:8c9252649f4f | 1033 | respond[43]=dimKgD[token][0]; |
arturojat | 0:8c9252649f4f | 1034 | respond[44]=dimKgD[token][1]; |
arturojat | 0:8c9252649f4f | 1035 | respond[45]=dimKgD[token][2]; |
arturojat | 0:8c9252649f4f | 1036 | respond[46]='.'; |
arturojat | 0:8c9252649f4f | 1037 | respond[47]=dimKgD[token][3]; |
arturojat | 0:8c9252649f4f | 1038 | respond[48]=dimKgD[token][4]; |
arturojat | 0:8c9252649f4f | 1039 | respond[49]=','; |
arturojat | 0:8c9252649f4f | 1040 | respond[50]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 1041 | respond[51]=','; |
arturojat | 0:8c9252649f4f | 1042 | respond[52]='F'; |
arturojat | 0:8c9252649f4f | 1043 | respond[53]='6'; |
arturojat | 0:8c9252649f4f | 1044 | respond[54]='0'; |
arturojat | 0:8c9252649f4f | 1045 | respond[55]='0'; |
arturojat | 0:8c9252649f4f | 1046 | respond[56]='0'; |
arturojat | 0:8c9252649f4f | 1047 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 1048 | } else { |
arturojat | 0:8c9252649f4f | 1049 | respond[42]='D'; |
arturojat | 0:8c9252649f4f | 1050 | respond[43]=dimKgI[token][0]; |
arturojat | 0:8c9252649f4f | 1051 | respond[44]=dimKgI[token][1]; |
arturojat | 0:8c9252649f4f | 1052 | respond[45]=dimKgI[token][2]; |
arturojat | 0:8c9252649f4f | 1053 | respond[46]='.'; |
arturojat | 0:8c9252649f4f | 1054 | respond[47]=dimKgI[token][3]; |
arturojat | 0:8c9252649f4f | 1055 | respond[48]=dimKgI[token][4]; |
arturojat | 0:8c9252649f4f | 1056 | respond[49]=','; |
arturojat | 0:8c9252649f4f | 1057 | respond[50]=wUnitsValue; |
arturojat | 0:8c9252649f4f | 1058 | respond[51]=','; |
arturojat | 0:8c9252649f4f | 1059 | respond[52]='F'; |
arturojat | 0:8c9252649f4f | 1060 | respond[53]='5'; |
arturojat | 0:8c9252649f4f | 1061 | respond[54]='0'; |
arturojat | 0:8c9252649f4f | 1062 | respond[55]='0'; |
arturojat | 0:8c9252649f4f | 1063 | respond[56]='0'; |
arturojat | 0:8c9252649f4f | 1064 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 1065 | } |
arturojat | 0:8c9252649f4f | 1066 | } |
arturojat | 0:8c9252649f4f | 1067 | respond[58]=factor; |
arturojat | 0:8c9252649f4f | 1068 | respond[59]=ETX; |
arturojat | 0:8c9252649f4f | 1069 | respond[60]=CR; |
arturojat | 0:8c9252649f4f | 1070 | respond[61]=LF; |
arturojat | 0:8c9252649f4f | 1071 | respond[62]='\0'; |
arturojat | 0:8c9252649f4f | 1072 | |
arturojat | 0:8c9252649f4f | 1073 | |
arturojat | 0:8c9252649f4f | 1074 | printString(respond); |
arturojat | 0:8c9252649f4f | 1075 | }//end measureCom |
arturojat | 0:8c9252649f4f | 1076 | |
arturojat | 0:8c9252649f4f | 1077 | void measureCom2() |
arturojat | 0:8c9252649f4f | 1078 | { |
arturojat | 0:8c9252649f4f | 1079 | // pc.printf("Entro"); |
arturojat | 0:8c9252649f4f | 1080 | Timer tim; |
arturojat | 0:8c9252649f4f | 1081 | char measureNum[5]= {' ',' ',' ',' '}; |
arturojat | 0:8c9252649f4f | 1082 | char measureNumGap[5]= {' ',' ',' ',' '}; |
arturojat | 0:8c9252649f4f | 1083 | char medidasCm[5][4]= {{'1','0','0','0'},{' ','9','8','2'}, |
arturojat | 0:8c9252649f4f | 1084 | {' ',' ','8','3'},{' ','3','4','8'}, |
arturojat | 0:8c9252649f4f | 1085 | {' ','7','6','4'} |
arturojat | 0:8c9252649f4f | 1086 | }; |
arturojat | 0:8c9252649f4f | 1087 | char medidasIn[5][4]= {{' ','3','9','3'},{' ','3','8','6'}, |
arturojat | 0:8c9252649f4f | 1088 | {' ',' ','3','3'},{' ','1','3','7'}, |
arturojat | 0:8c9252649f4f | 1089 | {' ','3','0','0'} |
arturojat | 0:8c9252649f4f | 1090 | }; |
arturojat | 0:8c9252649f4f | 1091 | char pesoLb[6][5]= {{'1','5','0','0','0'},{' ','7','9','1','5'}, |
arturojat | 0:8c9252649f4f | 1092 | {' ','6','3','2','5'} |
arturojat | 0:8c9252649f4f | 1093 | }; |
arturojat | 0:8c9252649f4f | 1094 | |
arturojat | 0:8c9252649f4f | 1095 | char pesoKg[3][5]= {{' ','6','8','0','3'},{' ','3','5','9','0'}, |
arturojat | 0:8c9252649f4f | 1096 | {' ','2','8','6','8'} |
arturojat | 0:8c9252649f4f | 1097 | }; |
arturojat | 0:8c9252649f4f | 1098 | int token = rand()%2; |
arturojat | 0:8c9252649f4f | 1099 | int token2 = rand()%3; |
arturojat | 0:8c9252649f4f | 1100 | int token3 = rand()%2; |
arturojat | 0:8c9252649f4f | 1101 | |
arturojat | 0:8c9252649f4f | 1102 | char respond[80]= {' '}; |
arturojat | 0:8c9252649f4f | 1103 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 1104 | respond[1]='B'; |
arturojat | 0:8c9252649f4f | 1105 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 1106 | itoa(MeasureNumber,measureNum); |
arturojat | 0:8c9252649f4f | 1107 | respond[3]=measureNum[3]; |
arturojat | 0:8c9252649f4f | 1108 | respond[4]=measureNum[2]; |
arturojat | 0:8c9252649f4f | 1109 | respond[5]=measureNum[1]; |
arturojat | 0:8c9252649f4f | 1110 | respond[6]=measureNum[0]; |
arturojat | 0:8c9252649f4f | 1111 | respond[7]=ETX; |
arturojat | 0:8c9252649f4f | 1112 | respond[8]=CR; |
arturojat | 0:8c9252649f4f | 1113 | respond[9]=LF; |
arturojat | 0:8c9252649f4f | 1114 | respond[10]='\0'; |
arturojat | 0:8c9252649f4f | 1115 | |
arturojat | 0:8c9252649f4f | 1116 | printString(respond); |
arturojat | 0:8c9252649f4f | 1117 | |
arturojat | 0:8c9252649f4f | 1118 | wait(2); |
arturojat | 0:8c9252649f4f | 1119 | |
arturojat | 0:8c9252649f4f | 1120 | strcpy(respond,""); |
arturojat | 0:8c9252649f4f | 1121 | itoa(MeasureNumber+1,measureNumGap); |
arturojat | 0:8c9252649f4f | 1122 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 1123 | respond[1]='G'; |
arturojat | 0:8c9252649f4f | 1124 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 1125 | respond[3]=measureNumGap[3]; |
arturojat | 0:8c9252649f4f | 1126 | respond[4]=measureNumGap[2]; |
arturojat | 0:8c9252649f4f | 1127 | respond[5]=measureNumGap[1]; |
arturojat | 0:8c9252649f4f | 1128 | respond[6]=measureNumGap[0]; |
arturojat | 0:8c9252649f4f | 1129 | respond[7]=ETX; |
arturojat | 0:8c9252649f4f | 1130 | respond[8]=CR; |
arturojat | 0:8c9252649f4f | 1131 | respond[9]=LF; |
arturojat | 0:8c9252649f4f | 1132 | respond[10]='\0'; |
arturojat | 0:8c9252649f4f | 1133 | |
arturojat | 0:8c9252649f4f | 1134 | printString(respond); |
arturojat | 0:8c9252649f4f | 1135 | strcpy(respond,""); |
arturojat | 0:8c9252649f4f | 1136 | |
arturojat | 0:8c9252649f4f | 1137 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 1138 | respond[1]='M'; |
arturojat | 0:8c9252649f4f | 1139 | respond[2]='A'; |
arturojat | 0:8c9252649f4f | 1140 | respond[3]=measureNum[3]; |
arturojat | 0:8c9252649f4f | 1141 | respond[4]=measureNum[2]; |
arturojat | 0:8c9252649f4f | 1142 | respond[5]=measureNum[1]; |
arturojat | 0:8c9252649f4f | 1143 | respond[6]=measureNum[0]; |
arturojat | 0:8c9252649f4f | 1144 | respond[7]=','; |
arturojat | 0:8c9252649f4f | 1145 | respond[8]=id[0]; |
arturojat | 0:8c9252649f4f | 1146 | respond[9]=id[1]; |
arturojat | 0:8c9252649f4f | 1147 | respond[10]=id[2]; |
arturojat | 0:8c9252649f4f | 1148 | respond[11]=id[3]; |
arturojat | 0:8c9252649f4f | 1149 | respond[12]=id[4]; |
arturojat | 0:8c9252649f4f | 1150 | respond[13]=id[5]; |
arturojat | 0:8c9252649f4f | 1151 | respond[14]=','; |
arturojat | 0:8c9252649f4f | 1152 | if(dimUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 1153 | respond[15]='L'; |
arturojat | 0:8c9252649f4f | 1154 | respond[16]=medidasIn[token][0]; |
arturojat | 0:8c9252649f4f | 1155 | respond[17]=medidasIn[token][1]; |
arturojat | 0:8c9252649f4f | 1156 | respond[18]=medidasIn[token][2]; |
arturojat | 0:8c9252649f4f | 1157 | respond[19]='.'; |
arturojat | 0:8c9252649f4f | 1158 | respond[20]=medidasIn[token][3]; |
arturojat | 0:8c9252649f4f | 1159 | respond[21]=','; |
arturojat | 0:8c9252649f4f | 1160 | respond[22]='0'; |
arturojat | 0:8c9252649f4f | 1161 | respond[23]='0'; |
arturojat | 0:8c9252649f4f | 1162 | respond[24]=','; |
arturojat | 0:8c9252649f4f | 1163 | respond[25]='W'; |
arturojat | 0:8c9252649f4f | 1164 | respond[26]=medidasIn[token+1][0]; |
arturojat | 0:8c9252649f4f | 1165 | respond[27]=medidasIn[token+1][1]; |
arturojat | 0:8c9252649f4f | 1166 | respond[28]=medidasIn[token+1][2]; |
arturojat | 0:8c9252649f4f | 1167 | respond[29]='.'; |
arturojat | 0:8c9252649f4f | 1168 | respond[30]=medidasIn[token+1][3]; |
arturojat | 0:8c9252649f4f | 1169 | respond[31]=','; |
arturojat | 0:8c9252649f4f | 1170 | respond[32]='0'; |
arturojat | 0:8c9252649f4f | 1171 | respond[33]='0'; |
arturojat | 0:8c9252649f4f | 1172 | respond[34]=','; |
arturojat | 0:8c9252649f4f | 1173 | respond[35]='H'; |
arturojat | 0:8c9252649f4f | 1174 | respond[36]=medidasIn[token+2][0]; |
arturojat | 0:8c9252649f4f | 1175 | respond[37]=medidasIn[token+2][1]; |
arturojat | 0:8c9252649f4f | 1176 | respond[38]=medidasIn[token+2][2]; |
arturojat | 0:8c9252649f4f | 1177 | respond[39]='.'; |
arturojat | 0:8c9252649f4f | 1178 | respond[40]=medidasIn[token+2][3]; |
arturojat | 0:8c9252649f4f | 1179 | respond[41]=','; |
arturojat | 0:8c9252649f4f | 1180 | respond[42]='0'; |
arturojat | 0:8c9252649f4f | 1181 | respond[43]='0'; |
arturojat | 0:8c9252649f4f | 1182 | respond[44]=','; |
arturojat | 0:8c9252649f4f | 1183 | respond[45]='i'; |
arturojat | 0:8c9252649f4f | 1184 | respond[46]='n'; |
arturojat | 0:8c9252649f4f | 1185 | respond[47]=','; |
arturojat | 0:8c9252649f4f | 1186 | } else { |
arturojat | 0:8c9252649f4f | 1187 | respond[15]='L'; |
arturojat | 0:8c9252649f4f | 1188 | respond[16]=medidasCm[token][0]; |
arturojat | 0:8c9252649f4f | 1189 | respond[17]=medidasCm[token][1]; |
arturojat | 0:8c9252649f4f | 1190 | respond[18]=medidasCm[token][2]; |
arturojat | 0:8c9252649f4f | 1191 | respond[19]='.'; |
arturojat | 0:8c9252649f4f | 1192 | respond[20]=medidasCm[token][3]; |
arturojat | 0:8c9252649f4f | 1193 | respond[21]=','; |
arturojat | 0:8c9252649f4f | 1194 | respond[22]='0'; |
arturojat | 0:8c9252649f4f | 1195 | respond[23]='0'; |
arturojat | 0:8c9252649f4f | 1196 | respond[24]=','; |
arturojat | 0:8c9252649f4f | 1197 | respond[25]='W'; |
arturojat | 0:8c9252649f4f | 1198 | respond[26]=medidasCm[token+1][0]; |
arturojat | 0:8c9252649f4f | 1199 | respond[27]=medidasCm[token+1][1]; |
arturojat | 0:8c9252649f4f | 1200 | respond[28]=medidasCm[token+1][2]; |
arturojat | 0:8c9252649f4f | 1201 | respond[29]='.'; |
arturojat | 0:8c9252649f4f | 1202 | respond[30]=medidasCm[token+1][3]; |
arturojat | 0:8c9252649f4f | 1203 | respond[31]=','; |
arturojat | 0:8c9252649f4f | 1204 | respond[32]='0'; |
arturojat | 0:8c9252649f4f | 1205 | respond[33]='0'; |
arturojat | 0:8c9252649f4f | 1206 | respond[34]=','; |
arturojat | 0:8c9252649f4f | 1207 | respond[35]='H'; |
arturojat | 0:8c9252649f4f | 1208 | respond[36]=medidasCm[token+2][0]; |
arturojat | 0:8c9252649f4f | 1209 | respond[37]=medidasCm[token+2][1]; |
arturojat | 0:8c9252649f4f | 1210 | respond[38]=medidasCm[token+2][2]; |
arturojat | 0:8c9252649f4f | 1211 | respond[39]='.'; |
arturojat | 0:8c9252649f4f | 1212 | respond[40]=medidasCm[token+2][3]; |
arturojat | 0:8c9252649f4f | 1213 | respond[41]=','; |
arturojat | 0:8c9252649f4f | 1214 | respond[42]='0'; |
arturojat | 0:8c9252649f4f | 1215 | respond[43]='0'; |
arturojat | 0:8c9252649f4f | 1216 | respond[44]=','; |
arturojat | 0:8c9252649f4f | 1217 | respond[45]='c'; |
arturojat | 0:8c9252649f4f | 1218 | respond[46]='m'; |
arturojat | 0:8c9252649f4f | 1219 | respond[47]=','; |
arturojat | 0:8c9252649f4f | 1220 | } |
arturojat | 0:8c9252649f4f | 1221 | if(wUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 1222 | respond[48]='M'; |
arturojat | 0:8c9252649f4f | 1223 | respond[49]=pesoLb[token][0]; |
arturojat | 0:8c9252649f4f | 1224 | respond[50]=pesoLb[token][1]; |
arturojat | 0:8c9252649f4f | 1225 | respond[51]=pesoLb[token][2]; |
arturojat | 0:8c9252649f4f | 1226 | respond[52]='.'; |
arturojat | 0:8c9252649f4f | 1227 | respond[53]=pesoLb[token][3]; |
arturojat | 0:8c9252649f4f | 1228 | respond[54]=','; |
arturojat | 0:8c9252649f4f | 1229 | respond[55]='0'; |
arturojat | 0:8c9252649f4f | 1230 | respond[56]='0'; |
arturojat | 0:8c9252649f4f | 1231 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 1232 | respond[58]='l'; |
arturojat | 0:8c9252649f4f | 1233 | respond[59]='b'; |
arturojat | 0:8c9252649f4f | 1234 | respond[60]=','; |
arturojat | 0:8c9252649f4f | 1235 | |
arturojat | 0:8c9252649f4f | 1236 | } else { |
arturojat | 0:8c9252649f4f | 1237 | |
arturojat | 0:8c9252649f4f | 1238 | respond[48]='M'; |
arturojat | 0:8c9252649f4f | 1239 | respond[49]=pesoKg[token][0]; |
arturojat | 0:8c9252649f4f | 1240 | respond[50]=pesoKg[token][1]; |
arturojat | 0:8c9252649f4f | 1241 | respond[51]=pesoKg[token][2]; |
arturojat | 0:8c9252649f4f | 1242 | respond[52]='.'; |
arturojat | 0:8c9252649f4f | 1243 | respond[53]=pesoKg[token][3]; |
arturojat | 0:8c9252649f4f | 1244 | respond[54]=','; |
arturojat | 0:8c9252649f4f | 1245 | respond[55]='0'; |
arturojat | 0:8c9252649f4f | 1246 | respond[56]='0'; |
arturojat | 0:8c9252649f4f | 1247 | respond[57]=','; |
arturojat | 0:8c9252649f4f | 1248 | respond[58]='k'; |
arturojat | 0:8c9252649f4f | 1249 | respond[59]='g'; |
arturojat | 0:8c9252649f4f | 1250 | respond[60]=','; |
arturojat | 0:8c9252649f4f | 1251 | } |
arturojat | 0:8c9252649f4f | 1252 | |
arturojat | 0:8c9252649f4f | 1253 | respond[61]='1'; |
arturojat | 0:8c9252649f4f | 1254 | respond[62]='2'; |
arturojat | 0:8c9252649f4f | 1255 | respond[63]='/'; |
arturojat | 0:8c9252649f4f | 1256 | respond[64]='3'; |
arturojat | 0:8c9252649f4f | 1257 | respond[65]='1'; |
arturojat | 0:8c9252649f4f | 1258 | respond[66]='/'; |
arturojat | 0:8c9252649f4f | 1259 | respond[67]='1'; |
arturojat | 0:8c9252649f4f | 1260 | respond[68]='6'; |
arturojat | 0:8c9252649f4f | 1261 | respond[69]=','; |
arturojat | 0:8c9252649f4f | 1262 | respond[70]='1'; |
arturojat | 0:8c9252649f4f | 1263 | respond[71]='2'; |
arturojat | 0:8c9252649f4f | 1264 | respond[72]=':'; |
arturojat | 0:8c9252649f4f | 1265 | respond[73]='5'; |
arturojat | 0:8c9252649f4f | 1266 | respond[74]='9'; |
arturojat | 0:8c9252649f4f | 1267 | respond[75]='A'; |
arturojat | 0:8c9252649f4f | 1268 | respond[76]=ETX; |
arturojat | 0:8c9252649f4f | 1269 | respond[77]=CR; |
arturojat | 0:8c9252649f4f | 1270 | respond[78]=LF; |
arturojat | 0:8c9252649f4f | 1271 | respond[79]='\0'; |
arturojat | 0:8c9252649f4f | 1272 | wait_ms(120); |
arturojat | 0:8c9252649f4f | 1273 | if(ErrorNum==1) { |
arturojat | 0:8c9252649f4f | 1274 | if(token2==0) { |
arturojat | 0:8c9252649f4f | 1275 | respond[16]=' '; |
arturojat | 0:8c9252649f4f | 1276 | respond[17]=' '; |
arturojat | 0:8c9252649f4f | 1277 | respond[18]='0'; |
arturojat | 0:8c9252649f4f | 1278 | respond[19]='.'; |
arturojat | 0:8c9252649f4f | 1279 | respond[20]='0'; |
arturojat | 0:8c9252649f4f | 1280 | respond[21]=','; |
arturojat | 0:8c9252649f4f | 1281 | if(token3==0) { |
arturojat | 0:8c9252649f4f | 1282 | respond[22]='0'; |
arturojat | 0:8c9252649f4f | 1283 | respond[23]='1'; |
arturojat | 0:8c9252649f4f | 1284 | } else { |
arturojat | 0:8c9252649f4f | 1285 | respond[22]='1'; |
arturojat | 0:8c9252649f4f | 1286 | respond[23]='1'; |
arturojat | 0:8c9252649f4f | 1287 | } |
arturojat | 0:8c9252649f4f | 1288 | } else if(token2==1) { |
arturojat | 0:8c9252649f4f | 1289 | respond[26]=' '; |
arturojat | 0:8c9252649f4f | 1290 | respond[27]=' '; |
arturojat | 0:8c9252649f4f | 1291 | respond[28]='0'; |
arturojat | 0:8c9252649f4f | 1292 | respond[29]='.'; |
arturojat | 0:8c9252649f4f | 1293 | respond[30]='0'; |
arturojat | 0:8c9252649f4f | 1294 | respond[31]=','; |
arturojat | 0:8c9252649f4f | 1295 | if(token3==0) { |
arturojat | 0:8c9252649f4f | 1296 | respond[32]='0'; |
arturojat | 0:8c9252649f4f | 1297 | respond[33]='1'; |
arturojat | 0:8c9252649f4f | 1298 | } else { |
arturojat | 0:8c9252649f4f | 1299 | respond[32]='1'; |
arturojat | 0:8c9252649f4f | 1300 | respond[33]='1'; |
arturojat | 0:8c9252649f4f | 1301 | } |
arturojat | 0:8c9252649f4f | 1302 | } else { |
arturojat | 0:8c9252649f4f | 1303 | respond[36]=' '; |
arturojat | 0:8c9252649f4f | 1304 | respond[37]=' '; |
arturojat | 0:8c9252649f4f | 1305 | respond[38]='0'; |
arturojat | 0:8c9252649f4f | 1306 | respond[39]='.'; |
arturojat | 0:8c9252649f4f | 1307 | respond[40]='0'; |
arturojat | 0:8c9252649f4f | 1308 | respond[41]=','; |
arturojat | 0:8c9252649f4f | 1309 | if(token3==0) { |
arturojat | 0:8c9252649f4f | 1310 | respond[42]='0'; |
arturojat | 0:8c9252649f4f | 1311 | respond[43]='1'; |
arturojat | 0:8c9252649f4f | 1312 | } else { |
arturojat | 0:8c9252649f4f | 1313 | respond[42]='1'; |
arturojat | 0:8c9252649f4f | 1314 | respond[43]='1'; |
arturojat | 0:8c9252649f4f | 1315 | } |
arturojat | 0:8c9252649f4f | 1316 | } |
arturojat | 0:8c9252649f4f | 1317 | } else if(ErrorNum==2) { |
arturojat | 0:8c9252649f4f | 1318 | respond[49]=' '; |
arturojat | 0:8c9252649f4f | 1319 | respond[50]=' '; |
arturojat | 0:8c9252649f4f | 1320 | respond[51]='0'; |
arturojat | 0:8c9252649f4f | 1321 | respond[52]='.'; |
arturojat | 0:8c9252649f4f | 1322 | respond[53]='0'; |
arturojat | 0:8c9252649f4f | 1323 | respond[54]=','; |
arturojat | 0:8c9252649f4f | 1324 | if(token3==0) { |
arturojat | 0:8c9252649f4f | 1325 | |
arturojat | 0:8c9252649f4f | 1326 | respond[55]='0'; |
arturojat | 0:8c9252649f4f | 1327 | respond[56]='1'; |
arturojat | 0:8c9252649f4f | 1328 | } else { |
arturojat | 0:8c9252649f4f | 1329 | respond[55]='1'; |
arturojat | 0:8c9252649f4f | 1330 | respond[56]='1'; |
arturojat | 0:8c9252649f4f | 1331 | } |
arturojat | 0:8c9252649f4f | 1332 | } |
arturojat | 0:8c9252649f4f | 1333 | printString(respond); |
arturojat | 0:8c9252649f4f | 1334 | MeasureNumber++; |
arturojat | 0:8c9252649f4f | 1335 | } |
arturojat | 0:8c9252649f4f | 1336 | /* itoa: convert n to characters in s */ |
arturojat | 0:8c9252649f4f | 1337 | void measureCom2TS(void) |
arturojat | 0:8c9252649f4f | 1338 | { |
arturojat | 0:8c9252649f4f | 1339 | |
arturojat | 0:8c9252649f4f | 1340 | char measureNum[5]= {' ',' ',' ',' '}; |
arturojat | 0:8c9252649f4f | 1341 | |
arturojat | 0:8c9252649f4f | 1342 | char medidasCm[5][4]= {{'1','0','0','0'},{' ','9','8','2'}, |
arturojat | 0:8c9252649f4f | 1343 | {' ',' ','8','3'},{' ','3','4','8'}, |
arturojat | 0:8c9252649f4f | 1344 | {' ','7','6','4'} |
arturojat | 0:8c9252649f4f | 1345 | }; |
arturojat | 0:8c9252649f4f | 1346 | char medidasIn[5][4]= {{' ','3','9','3'},{' ','3','8','6'}, |
arturojat | 0:8c9252649f4f | 1347 | {' ',' ','3','3'},{' ','1','3','7'}, |
arturojat | 0:8c9252649f4f | 1348 | {' ','3','0','0'} |
arturojat | 0:8c9252649f4f | 1349 | }; |
arturojat | 0:8c9252649f4f | 1350 | char pesoLb[6][5]= {{' ','1','5','0','0'},{' ',' ','7','9','5'}, |
arturojat | 0:8c9252649f4f | 1351 | {' ',' ','6','3','5'} |
arturojat | 0:8c9252649f4f | 1352 | }; |
arturojat | 0:8c9252649f4f | 1353 | |
arturojat | 0:8c9252649f4f | 1354 | char pesoKg[3][5]= {{' ',' ','8','0','3'},{' ',' ','5','9','0'}, |
arturojat | 0:8c9252649f4f | 1355 | {' ',' ','8','6','8'} |
arturojat | 0:8c9252649f4f | 1356 | }; |
arturojat | 0:8c9252649f4f | 1357 | int token = rand()%2; |
arturojat | 0:8c9252649f4f | 1358 | int token2 = rand()%3; |
arturojat | 0:8c9252649f4f | 1359 | int token3 = rand()%2; |
arturojat | 0:8c9252649f4f | 1360 | |
arturojat | 0:8c9252649f4f | 1361 | char respond[55]= {' '}; |
arturojat | 0:8c9252649f4f | 1362 | char respond1[7]= {' '}; |
arturojat | 0:8c9252649f4f | 1363 | respond1[0]=STX; |
arturojat | 0:8c9252649f4f | 1364 | respond1[1]='B'; |
arturojat | 0:8c9252649f4f | 1365 | respond1[2]='A'; |
arturojat | 0:8c9252649f4f | 1366 | respond1[3]='1'; |
arturojat | 0:8c9252649f4f | 1367 | respond1[4]='1'; |
arturojat | 0:8c9252649f4f | 1368 | respond1[5]=ETX; |
arturojat | 0:8c9252649f4f | 1369 | respond1[6]='\0'; |
arturojat | 0:8c9252649f4f | 1370 | |
arturojat | 0:8c9252649f4f | 1371 | // printString(respond); |
arturojat | 0:8c9252649f4f | 1372 | // fputs(respond,stdout); |
arturojat | 0:8c9252649f4f | 1373 | strcpy(respond,""); |
arturojat | 0:8c9252649f4f | 1374 | itoa(MeasureNumber,measureNum); |
arturojat | 0:8c9252649f4f | 1375 | respond[0]=STX; |
arturojat | 0:8c9252649f4f | 1376 | respond[1]='A'; |
arturojat | 0:8c9252649f4f | 1377 | respond[2]=measureNum[3]; |
arturojat | 0:8c9252649f4f | 1378 | respond[3]=measureNum[2]; |
arturojat | 0:8c9252649f4f | 1379 | respond[4]=measureNum[1]; |
arturojat | 0:8c9252649f4f | 1380 | respond[5]=measureNum[0]; |
arturojat | 0:8c9252649f4f | 1381 | respond[6]='0'; |
arturojat | 0:8c9252649f4f | 1382 | respond[7]='0'; |
arturojat | 0:8c9252649f4f | 1383 | if(dimUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 1384 | respond[8]='L'; |
arturojat | 0:8c9252649f4f | 1385 | respond[9]=medidasIn[token][0]; |
arturojat | 0:8c9252649f4f | 1386 | respond[10]=medidasIn[token][1]; |
arturojat | 0:8c9252649f4f | 1387 | respond[11]=medidasIn[token][2]; |
arturojat | 0:8c9252649f4f | 1388 | respond[12]='.'; |
arturojat | 0:8c9252649f4f | 1389 | respond[13]=medidasIn[token][3]; |
arturojat | 0:8c9252649f4f | 1390 | respond[14]='i'; |
arturojat | 0:8c9252649f4f | 1391 | respond[15]='n'; |
arturojat | 0:8c9252649f4f | 1392 | respond[16]='0'; |
arturojat | 0:8c9252649f4f | 1393 | respond[17]='0'; |
arturojat | 0:8c9252649f4f | 1394 | respond[18]='W'; |
arturojat | 0:8c9252649f4f | 1395 | respond[19]=medidasIn[token+1][0]; |
arturojat | 0:8c9252649f4f | 1396 | respond[20]=medidasIn[token+1][1]; |
arturojat | 0:8c9252649f4f | 1397 | respond[21]=medidasIn[token+1][2]; |
arturojat | 0:8c9252649f4f | 1398 | respond[22]='.'; |
arturojat | 0:8c9252649f4f | 1399 | respond[23]=medidasIn[token+1][3]; |
arturojat | 0:8c9252649f4f | 1400 | respond[24]='i'; |
arturojat | 0:8c9252649f4f | 1401 | respond[25]='n'; |
arturojat | 0:8c9252649f4f | 1402 | respond[26]='0'; |
arturojat | 0:8c9252649f4f | 1403 | respond[27]='0'; |
arturojat | 0:8c9252649f4f | 1404 | respond[28]='H'; |
arturojat | 0:8c9252649f4f | 1405 | respond[29]=medidasIn[token+2][0]; |
arturojat | 0:8c9252649f4f | 1406 | respond[30]=medidasIn[token+2][1]; |
arturojat | 0:8c9252649f4f | 1407 | respond[31]=medidasIn[token+2][2]; |
arturojat | 0:8c9252649f4f | 1408 | respond[32]='.'; |
arturojat | 0:8c9252649f4f | 1409 | respond[33]=medidasIn[token+2][3]; |
arturojat | 0:8c9252649f4f | 1410 | respond[34]='i'; |
arturojat | 0:8c9252649f4f | 1411 | respond[35]='n'; |
arturojat | 0:8c9252649f4f | 1412 | respond[36]='0'; |
arturojat | 0:8c9252649f4f | 1413 | respond[37]='0'; |
arturojat | 0:8c9252649f4f | 1414 | } else { |
arturojat | 0:8c9252649f4f | 1415 | respond[8]='L'; |
arturojat | 0:8c9252649f4f | 1416 | respond[9]=medidasCm[token][0]; |
arturojat | 0:8c9252649f4f | 1417 | respond[10]=medidasCm[token][1]; |
arturojat | 0:8c9252649f4f | 1418 | respond[11]=medidasCm[token][2]; |
arturojat | 0:8c9252649f4f | 1419 | respond[12]='.'; |
arturojat | 0:8c9252649f4f | 1420 | respond[13]=medidasCm[token][3]; |
arturojat | 0:8c9252649f4f | 1421 | respond[14]='c'; |
arturojat | 0:8c9252649f4f | 1422 | respond[15]='m'; |
arturojat | 0:8c9252649f4f | 1423 | respond[16]='0'; |
arturojat | 0:8c9252649f4f | 1424 | respond[17]='0'; |
arturojat | 0:8c9252649f4f | 1425 | respond[18]='W'; |
arturojat | 0:8c9252649f4f | 1426 | respond[19]=medidasCm[token+1][0]; |
arturojat | 0:8c9252649f4f | 1427 | respond[20]=medidasCm[token+1][1]; |
arturojat | 0:8c9252649f4f | 1428 | respond[21]=medidasCm[token+1][2]; |
arturojat | 0:8c9252649f4f | 1429 | respond[22]='.'; |
arturojat | 0:8c9252649f4f | 1430 | respond[23]=medidasCm[token+1][3]; |
arturojat | 0:8c9252649f4f | 1431 | respond[24]='c'; |
arturojat | 0:8c9252649f4f | 1432 | respond[25]='m'; |
arturojat | 0:8c9252649f4f | 1433 | respond[26]='0'; |
arturojat | 0:8c9252649f4f | 1434 | respond[27]='0'; |
arturojat | 0:8c9252649f4f | 1435 | respond[28]='H'; |
arturojat | 0:8c9252649f4f | 1436 | respond[29]=medidasCm[token+2][0]; |
arturojat | 0:8c9252649f4f | 1437 | respond[30]=medidasCm[token+2][1]; |
arturojat | 0:8c9252649f4f | 1438 | respond[31]=medidasCm[token+2][2]; |
arturojat | 0:8c9252649f4f | 1439 | respond[32]='.'; |
arturojat | 0:8c9252649f4f | 1440 | respond[33]=medidasCm[token+2][3]; |
arturojat | 0:8c9252649f4f | 1441 | respond[34]='c'; |
arturojat | 0:8c9252649f4f | 1442 | respond[35]='m'; |
arturojat | 0:8c9252649f4f | 1443 | respond[36]='0'; |
arturojat | 0:8c9252649f4f | 1444 | respond[37]='0'; |
arturojat | 0:8c9252649f4f | 1445 | } |
arturojat | 0:8c9252649f4f | 1446 | if(wUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 1447 | respond[38]='M'; |
arturojat | 0:8c9252649f4f | 1448 | respond[39]=pesoLb[token][0]; |
arturojat | 0:8c9252649f4f | 1449 | respond[40]=pesoLb[token][1]; |
arturojat | 0:8c9252649f4f | 1450 | respond[41]=pesoLb[token][2]; |
arturojat | 0:8c9252649f4f | 1451 | respond[42]=pesoLb[token][3]; |
arturojat | 0:8c9252649f4f | 1452 | respond[43]='.'; |
arturojat | 0:8c9252649f4f | 1453 | respond[44]=pesoLb[token][4]; |
arturojat | 0:8c9252649f4f | 1454 | respond[45]='l'; |
arturojat | 0:8c9252649f4f | 1455 | respond[46]='b'; |
arturojat | 0:8c9252649f4f | 1456 | respond[47]='0'; |
arturojat | 0:8c9252649f4f | 1457 | respond[48]='0'; |
arturojat | 0:8c9252649f4f | 1458 | |
arturojat | 0:8c9252649f4f | 1459 | |
arturojat | 0:8c9252649f4f | 1460 | } else { |
arturojat | 0:8c9252649f4f | 1461 | respond[38]='M'; |
arturojat | 0:8c9252649f4f | 1462 | respond[39]=pesoKg[token][0]; |
arturojat | 0:8c9252649f4f | 1463 | respond[40]=pesoKg[token][1]; |
arturojat | 0:8c9252649f4f | 1464 | respond[41]=pesoKg[token][2]; |
arturojat | 0:8c9252649f4f | 1465 | respond[42]=pesoKg[token][3]; |
arturojat | 0:8c9252649f4f | 1466 | respond[43]='.'; |
arturojat | 0:8c9252649f4f | 1467 | respond[44]=pesoLb[token][4]; |
arturojat | 0:8c9252649f4f | 1468 | respond[45]='k'; |
arturojat | 0:8c9252649f4f | 1469 | respond[46]='g'; |
arturojat | 0:8c9252649f4f | 1470 | respond[47]='0'; |
arturojat | 0:8c9252649f4f | 1471 | respond[48]='0'; |
arturojat | 0:8c9252649f4f | 1472 | |
arturojat | 0:8c9252649f4f | 1473 | } |
arturojat | 0:8c9252649f4f | 1474 | |
arturojat | 0:8c9252649f4f | 1475 | respond[49]='0'; |
arturojat | 0:8c9252649f4f | 1476 | respond[50]='0'; |
arturojat | 0:8c9252649f4f | 1477 | respond[51]=ETX; |
arturojat | 0:8c9252649f4f | 1478 | //respond[52]=CR; |
arturojat | 0:8c9252649f4f | 1479 | //respond[53]=LF; |
arturojat | 0:8c9252649f4f | 1480 | respond[52]='\0'; |
arturojat | 0:8c9252649f4f | 1481 | |
arturojat | 0:8c9252649f4f | 1482 | wait_ms(200); |
arturojat | 0:8c9252649f4f | 1483 | |
arturojat | 0:8c9252649f4f | 1484 | if(ErrorNum==1) { |
arturojat | 0:8c9252649f4f | 1485 | if(token2==0) { |
arturojat | 0:8c9252649f4f | 1486 | respond[9]=' '; |
arturojat | 0:8c9252649f4f | 1487 | respond[10]=' '; |
arturojat | 0:8c9252649f4f | 1488 | respond[11]='0'; |
arturojat | 0:8c9252649f4f | 1489 | respond[12]='.'; |
arturojat | 0:8c9252649f4f | 1490 | respond[13]='0'; |
arturojat | 0:8c9252649f4f | 1491 | if(token3==0) { |
arturojat | 0:8c9252649f4f | 1492 | respond[16]='1'; |
arturojat | 0:8c9252649f4f | 1493 | respond[17]='3'; |
arturojat | 0:8c9252649f4f | 1494 | } else { |
arturojat | 0:8c9252649f4f | 1495 | respond[16]='1'; |
arturojat | 0:8c9252649f4f | 1496 | respond[17]='2'; |
arturojat | 0:8c9252649f4f | 1497 | } |
arturojat | 0:8c9252649f4f | 1498 | } else if(token2==1) { |
arturojat | 0:8c9252649f4f | 1499 | respond[19]=' '; |
arturojat | 0:8c9252649f4f | 1500 | respond[20]=' '; |
arturojat | 0:8c9252649f4f | 1501 | respond[21]='0'; |
arturojat | 0:8c9252649f4f | 1502 | respond[22]='.'; |
arturojat | 0:8c9252649f4f | 1503 | respond[23]='0'; |
arturojat | 0:8c9252649f4f | 1504 | if(token3==0) { |
arturojat | 0:8c9252649f4f | 1505 | respond[26]='1'; |
arturojat | 0:8c9252649f4f | 1506 | respond[27]='3'; |
arturojat | 0:8c9252649f4f | 1507 | } else { |
arturojat | 0:8c9252649f4f | 1508 | respond[26]='1'; |
arturojat | 0:8c9252649f4f | 1509 | respond[27]='2'; |
arturojat | 0:8c9252649f4f | 1510 | } |
arturojat | 0:8c9252649f4f | 1511 | } else { |
arturojat | 0:8c9252649f4f | 1512 | respond[29]=' '; |
arturojat | 0:8c9252649f4f | 1513 | respond[30]=' '; |
arturojat | 0:8c9252649f4f | 1514 | respond[31]='0'; |
arturojat | 0:8c9252649f4f | 1515 | respond[32]='.'; |
arturojat | 0:8c9252649f4f | 1516 | respond[33]='0'; |
arturojat | 0:8c9252649f4f | 1517 | if(token3==0) { |
arturojat | 0:8c9252649f4f | 1518 | respond[36]='1'; |
arturojat | 0:8c9252649f4f | 1519 | respond[37]='3'; |
arturojat | 0:8c9252649f4f | 1520 | } else { |
arturojat | 0:8c9252649f4f | 1521 | respond[36]='1'; |
arturojat | 0:8c9252649f4f | 1522 | respond[37]='2'; |
arturojat | 0:8c9252649f4f | 1523 | } |
arturojat | 0:8c9252649f4f | 1524 | } |
arturojat | 0:8c9252649f4f | 1525 | } else if(ErrorNum==2) { |
arturojat | 0:8c9252649f4f | 1526 | respond[39]=' '; |
arturojat | 0:8c9252649f4f | 1527 | respond[40]=' '; |
arturojat | 0:8c9252649f4f | 1528 | respond[41]=' '; |
arturojat | 0:8c9252649f4f | 1529 | respond[42]='0'; |
arturojat | 0:8c9252649f4f | 1530 | respond[43]='.'; |
arturojat | 0:8c9252649f4f | 1531 | respond[44]='0'; |
arturojat | 0:8c9252649f4f | 1532 | if(token3==0) { |
arturojat | 0:8c9252649f4f | 1533 | |
arturojat | 0:8c9252649f4f | 1534 | respond[47]='1'; |
arturojat | 0:8c9252649f4f | 1535 | respond[48]='2'; |
arturojat | 0:8c9252649f4f | 1536 | } else { |
arturojat | 0:8c9252649f4f | 1537 | respond[47]='1'; |
arturojat | 0:8c9252649f4f | 1538 | respond[48]='3'; |
arturojat | 0:8c9252649f4f | 1539 | } |
arturojat | 0:8c9252649f4f | 1540 | } |
arturojat | 0:8c9252649f4f | 1541 | pc.printf("%s%s",respond1,respond); |
arturojat | 0:8c9252649f4f | 1542 | //printString(respond); |
arturojat | 0:8c9252649f4f | 1543 | MeasureNumber++; |
arturojat | 0:8c9252649f4f | 1544 | }//end measureCom2TS |
arturojat | 0:8c9252649f4f | 1545 | void itoa(int n, char s[]) |
arturojat | 0:8c9252649f4f | 1546 | { |
arturojat | 0:8c9252649f4f | 1547 | int i; |
arturojat | 0:8c9252649f4f | 1548 | i=n; |
arturojat | 0:8c9252649f4f | 1549 | s[0]=i%10+'0'; |
arturojat | 0:8c9252649f4f | 1550 | i-=i%10; |
arturojat | 0:8c9252649f4f | 1551 | |
arturojat | 0:8c9252649f4f | 1552 | s[1]=(i%100)/10+'0'; |
arturojat | 0:8c9252649f4f | 1553 | i-=i%100; |
arturojat | 0:8c9252649f4f | 1554 | |
arturojat | 0:8c9252649f4f | 1555 | s[2]=(i%1000)/100+'0'; |
arturojat | 0:8c9252649f4f | 1556 | i-=i%1000; |
arturojat | 0:8c9252649f4f | 1557 | |
arturojat | 0:8c9252649f4f | 1558 | s[3]=(i%10000)/1000+'0'; |
arturojat | 0:8c9252649f4f | 1559 | |
arturojat | 0:8c9252649f4f | 1560 | s[4]='\0'; |
arturojat | 0:8c9252649f4f | 1561 | |
arturojat | 0:8c9252649f4f | 1562 | } |
arturojat | 0:8c9252649f4f | 1563 | |
arturojat | 0:8c9252649f4f | 1564 | void changeWUnits(void) |
arturojat | 0:8c9252649f4f | 1565 | { |
arturojat | 0:8c9252649f4f | 1566 | |
arturojat | 0:8c9252649f4f | 1567 | if(wUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 1568 | wUnitsValue='M'; |
arturojat | 0:8c9252649f4f | 1569 | // pc.printf("Weight units set to Metric.\n\r"); |
arturojat | 0:8c9252649f4f | 1570 | |
arturojat | 0:8c9252649f4f | 1571 | } else { |
arturojat | 0:8c9252649f4f | 1572 | wUnitsValue='E'; |
arturojat | 0:8c9252649f4f | 1573 | //pc.printf("Weight units set to English.\n\r"); |
arturojat | 0:8c9252649f4f | 1574 | |
arturojat | 0:8c9252649f4f | 1575 | } |
arturojat | 0:8c9252649f4f | 1576 | } |
arturojat | 0:8c9252649f4f | 1577 | |
arturojat | 0:8c9252649f4f | 1578 | |
arturojat | 0:8c9252649f4f | 1579 | void changeDUnits(void) |
arturojat | 0:8c9252649f4f | 1580 | { |
arturojat | 0:8c9252649f4f | 1581 | if(dimUnitsValue=='E') { |
arturojat | 0:8c9252649f4f | 1582 | dimUnitsValue='M'; |
arturojat | 0:8c9252649f4f | 1583 | //pc.printf("Dimension units set to Metric.\n\r"); |
arturojat | 0:8c9252649f4f | 1584 | |
arturojat | 0:8c9252649f4f | 1585 | } else { |
arturojat | 0:8c9252649f4f | 1586 | dimUnitsValue='E'; |
arturojat | 0:8c9252649f4f | 1587 | //pc.printf("Dimension units set to English.\n\r"); |
arturojat | 0:8c9252649f4f | 1588 | |
arturojat | 0:8c9252649f4f | 1589 | } |
arturojat | 0:8c9252649f4f | 1590 | } |
arturojat | 0:8c9252649f4f | 1591 | void ErrorGen(void) |
arturojat | 0:8c9252649f4f | 1592 | { |
arturojat | 0:8c9252649f4f | 1593 | if(ErrorNum<2) { |
arturojat | 0:8c9252649f4f | 1594 | ErrorNum++; |
arturojat | 0:8c9252649f4f | 1595 | } else { |
arturojat | 0:8c9252649f4f | 1596 | ErrorNum=0; |
arturojat | 0:8c9252649f4f | 1597 | } |
arturojat | 0:8c9252649f4f | 1598 | } |