00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "stdafx.h"
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "ippdme/ippChangeToolActionType.h"
00036 #include "ippdme/Property/ippOnePropertyNumber.h"
00037 #include "ippdme/Property/ippOnePropertyAlignment.h"
00038 #include "ippdme/Property/ippOnePropertyName.h"
00039 #include "ippdme/Property/ippOnePropertyId.h"
00040 #include "ippdme/Property/ippOnePropertyCollisionVolume.h"
00041
00042 #include "ippdme/Response/ippResponse.h"
00043 #include "ippdme/Response/ippAlignResponse.h"
00044 #include "ippdme/Response/ippCenterPartResponse.h"
00045 #include "ippdme/Response/ippChangeToolEResponse.h"
00046 #include "ippdme/Response/ippEnumPropResponse.h"
00047 #include "ippdme/Response/ippErrorResponse.h"
00048 #include "ippdme/Response/ippGetChangeToolActionResponse.h"
00049 #include "ippdme/Response/ippGetCoordSystemResponse.h"
00050 #include "ippdme/Response/ippGetCsyTransformationResponse.h"
00051 #include "ippdme/Response/ippGetDMEVersionResponse.h"
00052 #include "ippdme/Response/ippGetErrStatusEResponse.h"
00053 #include "ippdme/Response/ippGetMachineClassResponse.h"
00054 #include "ippdme/Response/ippGetPropResponse.h"
00055 #include "ippdme/Response/ippGoToEResponse.h"
00056 #include "ippdme/Response/ippIsHomedResponse.h"
00057 #include "ippdme/Response/ippIsUserEnabledResponse.h"
00058 #include "ippdme/Response/ippKeyPressEResponse.h"
00059 #include "ippdme/Response/ippPtMeasEResponse.h"
00060 #include "ippdme/Response/ippPtMeasOrGetResponse.h"
00061 #include "ippdme/Response/ippScanResponse.h"
00062 #include "ippdme/Response/ippSetPropEResponse.h"
00063 #include "ippdme/Response/ippOnMoveReportEResponse.h"
00064 #include "ippdme/Response/ippStringResponse.h"
00065 #include "ippdme/Response/ippTiltCenterPartResponse.h"
00066 #include "ippdme/Response/ippTiltPartResponse.h"
00067 #include "ippdme/Response/ippAckResponse.h"
00068 #include "ippdme/Response/ippCompleteResponse.h"
00069
00070
00071 #include "ippdme/Parser/ippResponseParser.h"
00072 #include "ippdme/ippResponseNameStrings.h"
00073
00074 #include "ippPatternChecker.h"
00075 #include "ippdme/misc/ippPropDefinition.h"
00076 #include "ippdme/assert.h"
00077
00078 #include <memory>
00079 #include <iostream>
00080 #include <iomanip>
00081 using namespace ipp;
00082
00083
00084 #define INITSIZE 10
00085
00086 #ifdef _DEBUG
00087 #define new DEBUG_NEW
00088 #undef THIS_FILE
00089 static char THIS_FILE[] = __FILE__;
00090 #endif
00091
00092
00093
00094
00095 ippResponseParser::ippResponseParser()
00096
00097 {
00098 _itemCount = 0;
00099 _resSize = INITSIZE;
00100 _resTypes.resize(_resSize);
00101 _resKeywords.resize(_resSize);
00102 _resDoubles.resize(_resSize);
00103 _arrayIndex = 0;
00104 }
00105
00106
00107 ippResponseParser::~ippResponseParser()
00108
00109 {
00110
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 std::string ippResponseParser::getErrorMessageString() const
00137 {
00138 static const char * const errorStrings[] = {
00139 "OK",
00140 "BAD CHARACTER AFTER KEYWORD",
00141 "BAD CHARACTER AFTER RESPONSE END",
00142 "BAD COORDINATE SYSTEM",
00143 "BAD E NUMBER EXPONENT MUST HAVE ONE TWO OR THREE DIGITS",
00144 "BAD ERROR CODE",
00145 "BAD GOTOPAR PROPERTY",
00146 "BAD KEYWORD",
00147 "BAD MACHINE CLASS",
00148 "BAD NUMBER MORE THAN 16 DIGITS",
00149 "BAD NUMBER NO DIGITS",
00150 "BAD NUMBER TWO DECIMAL POINTS",
00151 "BAD PTMEASPAR PROPERTY",
00152 "BAD RESPONSE ITEMS",
00153 "BAD SECOND KEYWORD",
00154 "BAD SEVENTH CHARACTER IN RESPONSE",
00155 "BAD SEVERITY",
00156 "BAD STRING",
00157 "BAD _tag CHARACTER",
00158 "BAD TEXT",
00159 "BAD THIRD KEYWORD",
00160 "BUG",
00161 "ER USED TWICE",
00162 "ERROR CODE MUST HAVE FOUR DIGITS",
00163 "FIRST ARGUMENT MUST BE SWITCH ROTATE MOVEAUTO OR MOVEMAN",
00164 "IJK USED TWICE",
00165 "IJKAct USED TWICE",
00166 "Q USED TWICE",
00167 "IJK VALUES MUST BE ZERO",
00168 "ILLEGAL SPACE",
00169 "R USED TWICE",
00170 "RESPONSE NAME MUST BE ERROR",
00171 "SEVERITY MUST HAVE ONE DIGIT",
00172 "SPACE MISSING AFTER _tag",
00173 "SPACE MISSING AT EIGHTH CHARACTER OF RESPONSE",
00174 "_tag NUMBER OUT OF RANGE FOR COMMAND _tag",
00175 "TOOL A USED TWICE",
00176 "TOOL B USED TWICE",
00177 "TOOL C USED TWICE",
00178 "VALUE MUST BE 0 OR 1",
00179 "X USED TWICE",
00180 "Y USED TWICE",
00181 "Z USED TWICE",
00182 "ZERO _tag MUST BE SERVER INITIATED RESPONSE",
00183 "Bad Property"
00184 };
00185 static char buffer[1000];
00186 if ((_responseName > -1) && (_responseName < ippResponseNameType_MAXVALUE))
00187 sprintf(buffer, "%s: %s",
00188 ippResponseNameStrings[_responseName], errorStrings[_errorCode]);
00189 else
00190 sprintf(buffer, "%s",errorStrings[_errorCode]);
00191 return buffer;
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 void ippResponseParser::makeArraysBigger()
00214 {
00215 _resSize = (2 * _resSize);
00216 _resKeywords.resize(_resSize);
00217 _resDoubles.resize(_resSize);
00218 _resTypes.resize(_resSize);
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 ippResponsePtr ippResponseParser::makeAlignResponse()
00254 {
00255 _responseName = DataAlign;
00256
00257 if (match(_resTypes,"(#,#,#)")) {
00258 return new ippAlignResponse(_tag,
00259 _resDoubles[1], _resDoubles[3],_resDoubles[5]);
00260
00261 } else if (match(_resTypes,"(#,#,#,#,#,#)")) {
00262 return new ippAlignResponse(_tag,
00263 _resDoubles[1], _resDoubles[3],_resDoubles[5],
00264 _resDoubles[7], _resDoubles[9], _resDoubles[11] );
00265 } else {
00266 _errorCode = BAD_RESPONSE_ITEMS;
00267 }
00268 return 0;
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 ippResponsePtr ippResponseParser::makeCenterPartResponse()
00301 {
00302 _responseName = DataCenterPart;
00303
00304
00305 if (!match(_resTypes,"k(#)")) {
00306 _errorCode = BAD_RESPONSE_ITEMS;
00307 return 0;
00308 }
00309
00310 if ((_resDoubles[2] != 0) && (_resDoubles[2] != 1)) {
00311 _errorCode = VALUE_MUST_BE_0_OR_1;
00312 return 0;
00313 }
00314 bool value = ((_resDoubles[2] == 1) ? true : false);
00315
00316 return new ippCenterPartResponse(_tag, value);
00317 }
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 ippResponsePtr ippResponseParser::makeChangeToolEResponse()
00345 {
00346 _responseName = DataChangeToolE;
00347
00348 if (!match(_resTypes,"k(s)")) {
00349 _errorCode = BAD_RESPONSE_ITEMS;
00350 return 0;
00351 }
00352 return new ippChangeToolEResponse(_resStrings[2].c_str());
00353 }
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 ippResponsePtr ippResponseParser::makeDataResponse()
00378 {
00379 ippResponsePtr aResponse;
00380
00381 if (_resTypes[0] == RESPARENLEFT)
00382 aResponse = makeAlignResponse();
00383 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == CenterPartKey))
00384 aResponse = makeCenterPartResponse();
00385 else if ((_resTypes[0] == RESSTRING) && (_itemCount == 3))
00386 aResponse = makeEnumPropResponse();
00387 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == ChangeToolAction))
00388 aResponse = makeGetChangeToolActionResponse();
00389 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == CoordSystem))
00390 aResponse = makeGetCoordSystemResponse();
00391 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == GetCsyTr))
00392 aResponse = makeGetCsyTransformationResponse();
00393 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == DMEVersion))
00394 aResponse = makeGetDMEVersionResponse();
00395 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == ErrStatus))
00396 aResponse = makeGetErrStatusEResponse();
00397 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == GetMachineKey))
00398 aResponse = makeGetMachineClassResponse();
00399 else if ( match(_resTypes,"k.k") && IsMainObject(_resKeywords[0],_resKeywords[2]))
00400 aResponse = makeGetPropResponse();
00401 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == IsHomedKey))
00402 aResponse = makeIsHomedResponse();
00403 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == IsUserEnabledKey))
00404 aResponse = makeIsUserEnabledResponse();
00405 else if ((_resTypes[0] == RESKEYWORD) &&
00406 ((_resKeywords[0] == ER) ||
00407 (_resKeywords[0] == IJK) ||
00408 (_resKeywords[0] == R) ||
00409 (_resKeywords[0] == X) ||
00410 (_resKeywords[0] == Y) ||
00411 (_resKeywords[0] == Z) ||
00412 (_resKeywords[0] == Tool)))
00413 aResponse = makePtMeasOrGetResponse();
00414 else if (_resTypes[0] == RESDOUBLE)
00415 aResponse = makeScanResponse();
00416 else if ((_resTypes[0] == RESSTRING) && (_itemCount == 1))
00417 aResponse = makeStringResponse();
00418 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == TiltCenterPartKey))
00419 aResponse = makeTiltCenterPartResponse();
00420 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == TiltPartKey))
00421 aResponse = makeTiltPartResponse();
00422 else
00423 {
00424 aResponse = NULL;
00425 _errorCode = BAD_RESPONSE_ITEMS;
00426 }
00427 return aResponse;
00428 }
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 ippResponsePtr ippResponseParser::makeEnumPropResponse()
00457 {
00458 _responseName = DataEnumProp;
00459
00460 if (!match(_resTypes,"s,s")) {
00461 _errorCode = BAD_RESPONSE_ITEMS;
00462 return 0;
00463 }
00464 return new ippEnumPropResponse(_tag,
00465 _resStrings[0].c_str(), _resStrings[2].c_str());
00466 }
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 ippResponsePtr ippResponseParser::makeErrorResponse()
00510 {
00511 char severity;
00512 ipp::parserResErrorId code = OK;
00513 ippErrorResponsePtr aResponse;
00514
00515
00516 if (!match(_resTypes,"k(#,#,s,s)")) {
00517 _errorCode = BAD_RESPONSE_ITEMS;
00518 return 0;
00519 }
00520 _responseName = ErrorError;
00521
00522 if (_resKeywords[0] != ErrorKey) {
00523 _errorCode = RESPONSE_NAME_MUST_BE_ERROR;
00524
00525 } else if (_inputArray[15] != ','){
00526 _errorCode = SEVERITY_MUST_HAVE_ONE_DIGIT;
00527
00528 } else if (
00529 !isdigit(_inputArray[16]) ||
00530 !isdigit(_inputArray[17]) ||
00531 !isdigit(_inputArray[18]) ||
00532 !isdigit(_inputArray[19]) ||
00533 (_inputArray[20] != ',')) {
00534 _errorCode = ERROR_CODE_MUST_HAVE_FOUR_DIGITS;
00535 } else {
00536 severity = ((_resDoubles[2] == 0) ? '0' :
00537 (_resDoubles[2] == 1) ? '1' :
00538 (_resDoubles[2] == 2) ? '2' :
00539 (_resDoubles[2] == 3) ? '3' :
00540 (_resDoubles[2] == 9) ? '9' : '4');
00541
00542 ippErrorNameType errCode = Convert2ippErrorNameType(_resDoubles[4]);
00543
00544 aResponse = new ippErrorResponse(_tag, _tagType, errCode, _resStrings[6].c_str());
00545
00546 std::string errTxt = aResponse->getTheError()->getText();
00547 if (aResponse->getTheError()->getSeverity() == '4') {
00548 _errorCode = BAD_ERROR_CODE;
00549
00550 } else if ( aResponse->getTheError()->getText()!= _resStrings[8] ){
00551 _errorCode = BAD_TEXT;
00552 } else if (severity != aResponse->getTheError()->getSeverity()){
00553 _errorCode = BAD_SEVERITY;
00554 }
00555 }
00556 return ((_errorCode != OK) ? NULL : aResponse);
00557 }
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587 ippResponsePtr ippResponseParser::makeGetChangeToolActionResponse()
00588 {
00589 _responseName = DataGetChangeToolAction;
00590
00591 if (!match(_resTypes,"k(k,k(#),k(#),k(#))")) {
00592 _errorCode = BAD_RESPONSE_ITEMS;
00593 return 0;
00594 }
00595 if (_resKeywords[4] != X) {
00596 _errorCode = BAD_RESPONSE_ITEMS;
00597 return 0;
00598 }
00599 if (_resKeywords[9] != Y) {
00600 _errorCode = BAD_RESPONSE_ITEMS;
00601 return 0;
00602 }
00603 if (_resKeywords[14]!= Z) {
00604 _errorCode = BAD_RESPONSE_ITEMS;
00605 return 0;
00606 }
00607
00608 ippChangeToolActionType action = ChangeToolActionFromKeyWord(_resKeywords[2]);
00609
00610 if (ippChangeToolActionType_INVALID == action) {
00611 _errorCode = FIRST_ARGUMENT_MUST_BE_SWITCH_ROTATE_MOVEAUTO_OR_MOVEMAN;
00612 return 0;
00613 }
00614 return new ippGetChangeToolActionResponse(_tag,action,
00615 _resDoubles[6],
00616 _resDoubles[11],
00617 _resDoubles[16]);
00618 }
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648 ippResponsePtr ippResponseParser::makeGetCoordSystemResponse()
00649 {
00650 _responseName = DataGetCoordSystem;
00651 if (!match(_resTypes,"k(k)")) {
00652 _errorCode = BAD_RESPONSE_ITEMS;
00653 return 0;
00654 }
00655
00656 if ( (_resKeywords[2] < MachineCsy) || (_resKeywords[2] > PartCsy)) {
00657 _errorCode = BAD_COORDINATE_SYSTEM;
00658 return 0;
00659 }
00660 return ((_errorCode != OK) ? NULL :
00661 new ippGetCoordSystemResponse(_tag, (ippCoordSysType)_resKeywords[2]));
00662 }
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692 ippResponsePtr ippResponseParser::makeGetCsyTransformationResponse()
00693 {
00694 _responseName = DataGetCsyTransformation;
00695
00696 if (!match(_resTypes,"k(#,#,#,#,#,#)")) {
00697 _errorCode = BAD_RESPONSE_ITEMS;
00698 return 0;
00699 }
00700
00701 return new ippGetCsyTransformationResponse(_tag,
00702 _resDoubles[2], _resDoubles[4], _resDoubles[6],
00703 _resDoubles[8], _resDoubles[10], _resDoubles[12]);
00704 }
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731 ippResponsePtr ippResponseParser::makeGetDMEVersionResponse()
00732 {
00733 _responseName = DataGetDMEVersion;
00734 if (!match(_resTypes,"k(s)")) {
00735 _errorCode = BAD_RESPONSE_ITEMS;
00736 return 0;
00737 }
00738 return ((_errorCode != OK) ? NULL :
00739 new ippGetDMEVersionResponse(_tag, _resStrings[2].c_str()));
00740 }
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772 ippResponsePtr ippResponseParser::makeGetErrStatusEResponse()
00773 {
00774 _responseName = DataGetErrStatusE;
00775
00776 if (!match(_resTypes,"k(#)")) {
00777 _errorCode = BAD_RESPONSE_ITEMS;
00778 return 0;
00779 }
00780
00781 if ((_resDoubles[2] != 0) && (_resDoubles[2] != 1)) {
00782 _errorCode = VALUE_MUST_BE_0_OR_1;
00783 }
00784
00785 bool value = (_resDoubles[2]==1) ? true : false;
00786
00787 return new ippGetErrStatusEResponse(_tag, value);
00788 }
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817 ippResponsePtr ippResponseParser::makeGetMachineClassResponse()
00818 {
00819 _responseName = DataGetMachineClass;
00820
00821 if (!match(_resTypes,"k(k)")) {
00822 _errorCode = BAD_RESPONSE_ITEMS;
00823 return 0;
00824 }
00825
00826 ippMachineClassType machineType = MachineClassTypeFromKeyWord(_resKeywords[2]);
00827 if (machineType ==ippMachineClassType_INVALID) {
00828 _errorCode = BAD_MACHINE_CLASS;
00829 return 0;
00830
00831 }
00832 return new ippGetMachineClassResponse(_tag,machineType);
00833 }
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876 ippResponsePtr ippResponseParser::makeGetPropResponse()
00877 {
00878
00879 _responseName = DataGetProp;
00880
00881 ippGetPropResponsePtr response = new ippGetPropResponse(_tag, _tagType);
00882
00883
00884 for (int n = 0; ((n < _itemCount) && (_errorCode == OK)); ) {
00885
00886 ippOtherKeyType key1 = EmptyKey;
00887 ippOtherKeyType key2 = EmptyKey;
00888 ippOtherKeyType key3 = EmptyKey;
00889 ippOtherKeyType key4 = EmptyKey;
00890 double value = 0;
00891
00892 int m=n;
00893 bool foundPropertyNumber = false;
00894
00895
00896
00897
00898
00899
00900
00901 if(match(_resTypes,"k.k(#)",m)) {
00902 key1 = _resKeywords[m];
00903 key2 = _resKeywords[m+2];
00904 value = _resDoubles[m+4];
00905 foundPropertyNumber = true;
00906 n = (m + 7);
00907 } else if(match(_resTypes,"k.k.k(#)",m)) {
00908 key1 = _resKeywords[m];
00909 key2 = _resKeywords[m+2];
00910 key3 = _resKeywords[m+4];
00911 value = _resDoubles[m+6];
00912 foundPropertyNumber = true;
00913 n = (m + 9);
00914 } else if(match(_resTypes,"k.k.k.k(#)",m)) {
00915 key1 = _resKeywords[m];
00916 key2 = _resKeywords[m+2];
00917 key3 = _resKeywords[m+4];
00918 key4 = _resKeywords[m+6];
00919 value = _resDoubles[m+8];
00920 foundPropertyNumber = true;
00921 n = (m + 11);
00922 }
00923 if (foundPropertyNumber) {
00924 ippProp prop(key1,key2,key3,key4);
00925 if (!PropertyIsDouble(prop)) {
00926 _errorCode = BAD_PROPERTY;
00927 }
00928 ippOnePropertyPtr r = new ippOnePropertyNumber(prop,value);
00929 response->append(r);
00930
00931 } else if (_resKeywords[n + 2] == Alignment){
00932 response->append(makeOnePropertyAlignment(&n));
00933 } else if (_resKeywords[n+2 ] == AlignmentVolume ) {
00934 response->append(makeOnePropertyAlignmentVolume(&n));
00935 } else if (_resKeywords[n + 2] == CollisionVolume){
00936 response->append(makeOnePropertyCollisionVolume(&n));
00937 } else if (_resKeywords[n + 2] == Name) {
00938 response->append(makeOnePropertyName(&n));
00939 } else if (_resKeywords[n + 2] == Id){
00940 response->append(makeOnePropertyId(&n));
00941 } else {
00942 _errorCode = BAD_SECOND_KEYWORD;
00943 }
00944 }
00945 if (_errorCode != OK) {
00946 response =0;
00947 }
00948 return response;
00949 }
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005 ippResponsePtr ippResponseParser::makeGoToEResponse()
01006 {
01007 int n;
01008 bool hasER = false;
01009 bool hasIJK = false;
01010 bool hasR = false;
01011 bool hasToolA = false;
01012 bool hasToolB = false;
01013 bool hasToolC = false;
01014 bool hasX = false;
01015 bool hasY = false;
01016 bool hasZ = false;
01017 double ERvalue = 0;
01018 double Rvalue = 0;
01019 double toolAvalue = 0;
01020 double toolBvalue = 0;
01021 double toolCvalue = 0;
01022 double Xvalue = 0;
01023 double Yvalue = 0;
01024 double Zvalue = 0;
01025 double Ivalue = 0;
01026 double Jvalue = 0;
01027 double Kvalue = 0;
01028 _responseName = DataGoToE;
01029
01030
01031
01032 if (_resTypes[1] != RESPARENLEFT) {
01033 _errorCode = BAD_RESPONSE_ITEMS;
01034 }
01035 if (_resTypes[_itemCount-1] != RESPARENRIGHT) {
01036 _errorCode = BAD_RESPONSE_ITEMS;
01037 }
01038
01039 for (n = 2; ((n < _itemCount) && (_errorCode == OK)); ) {
01040
01041 int old_n=n;
01042 CheckOptionalArgument(n,hasER,ER,ERvalue,ER_USED_TWICE);
01043 CheckOptionalArgument(n,hasX, _X,Xvalue ,X_USED_TWICE);
01044 CheckOptionalArgument(n,hasY, _Y,Yvalue ,Y_USED_TWICE);
01045 CheckOptionalArgument(n,hasZ, _Z,Zvalue ,Z_USED_TWICE);
01046 CheckOptionalArgument(n,hasR, _R,Rvalue ,R_USED_TWICE);
01047 CheckOptionalArgument(n,hasToolA,Tool,_A,toolAvalue ,TOOL_A_USED_TWICE);
01048 CheckOptionalArgument(n,hasToolB,Tool,_B,toolBvalue ,TOOL_B_USED_TWICE);
01049 CheckOptionalArgument(n,hasToolC,Tool,_C,toolCvalue ,TOOL_C_USED_TWICE);
01050 CheckOptionalArgument(n,hasIJK ,_IJK, Ivalue,Jvalue,Kvalue,IJK_USED_TWICE);
01051
01052 if (old_n == n && _errorCode == OK) {
01053
01054 _errorCode = BAD_RESPONSE_ITEMS;
01055 }
01056 }
01057
01058 if (hasIJK) {
01059 if (Ivalue!=0 || Jvalue !=0 || Kvalue!=0 ){
01060 _errorCode = IJK_VALUES_MUST_BE_ZERO;
01061 }
01062 }
01063 return ((_errorCode != OK) ? NULL:
01064 new ippGoToEResponse(hasER, hasIJK, hasR, hasToolA, hasToolB, hasToolC,
01065 hasX, hasY, hasZ, ERvalue, Rvalue, toolAvalue,
01066 toolBvalue, toolCvalue, Xvalue, Yvalue, Zvalue));
01067 }
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100 ippResponsePtr ippResponseParser::makeIsHomedResponse()
01101 {
01102 _responseName = DataIsHomed;
01103
01104
01105 if (!match(_resTypes,"k(#)")) {
01106 _errorCode = BAD_RESPONSE_ITEMS;
01107 return 0;
01108 }
01109
01110 if ((_resDoubles[2] != 0) && (_resDoubles[2] != 1)) {
01111 _errorCode = VALUE_MUST_BE_0_OR_1;
01112 return 0;
01113 }
01114 bool value = ((_resDoubles[2] == 1) ? true : false);
01115 return ((_errorCode != OK) ? NULL :
01116 new ippIsHomedResponse(_tag, value));
01117 }
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149 ippResponsePtr ippResponseParser::makeIsUserEnabledResponse()
01150 {
01151 _responseName = DataIsUserEnabled;
01152
01153
01154 if (!match(_resTypes,"k(#)")) {
01155 _errorCode = BAD_RESPONSE_ITEMS;
01156 return 0;
01157 }
01158
01159 if ((_resDoubles[2] != 0) && (_resDoubles[2] != 1)) {
01160 _errorCode = VALUE_MUST_BE_0_OR_1;
01161 return 0;
01162 }
01163
01164 bool value = ((_resDoubles[2] == 1) ? true : false);
01165
01166 return ((_errorCode != OK) ? NULL :
01167 new ippIsUserEnabledResponse(_tag, value));
01168 }
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195 ippResponsePtr ippResponseParser::makeKeyPressEResponse()
01196 {
01197 _responseName = DataKeyPressE;
01198
01199 if (!match(_resTypes,"k(s)")) {
01200 _errorCode = BAD_RESPONSE_ITEMS;
01201 return 0;
01202 }
01203
01204 return ((_errorCode != OK) ? NULL :
01205 new ippKeyPressEResponse(_resStrings[2].c_str()));
01206 }
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245 ippOnePropertyAlignmentPtr ippResponseParser::makeOnePropertyAlignment(
01246 int* n
01247 )
01248 {
01249
01250 int m = *n;
01251 if ( _resKeywords[m]!=ipp::Tool && _resKeywords[m]!=ipp::FoundTool ) {
01252 _errorCode = BAD_SECOND_KEYWORD;
01253 return 0;
01254 }
01255
01256 if (match(_resTypes,"k.k(#,#,#)",m)) {
01257 *n = (m + 11);
01258 return new ippOnePropertyAlignment(
01259 _resKeywords[m],
01260 _resDoubles[m + 4], _resDoubles[m + 6],_resDoubles[m + 8]);
01261
01262 } else if (match(_resTypes,"k.k(#,#,#,#,#,#)",m)) {
01263
01264 *n = (m + 17);
01265 return new ippOnePropertyAlignment(
01266 _resKeywords[m],
01267 _resDoubles[m + 4], _resDoubles[m + 6], _resDoubles[m + 8],
01268 _resDoubles[m + 10],_resDoubles[m + 12], _resDoubles[m + 14]);
01269 }
01270
01271 _errorCode = BAD_RESPONSE_ITEMS;
01272
01273 return 0;
01274 }
01275 ippOnePropertyAlignmentVolumePtr ippResponseParser::makeOnePropertyAlignmentVolume(
01276 int* n
01277 )
01278 {
01279
01280 int m = *n;
01281
01282 if (match(_resTypes,"k.k(k,#,#,#,#)",m)) {
01283 *n = (m + 15);
01284 if ( _resKeywords[m]!=ipp::Tool && _resKeywords[m]!=ipp::FoundTool ) {
01285 _errorCode = BAD_SECOND_KEYWORD;
01286 return 0;
01287 }
01288 return new ippOnePropertyAlignmentVolume(
01289 _resKeywords[m],
01290 _resDoubles[m + 6], _resDoubles[m + 8],
01291 _resDoubles[m + 10],_resDoubles[m + 12]);
01292
01293 }
01294
01295 _errorCode = BAD_RESPONSE_ITEMS;
01296
01297 return 0;
01298 }
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342 #if _MSC_VER <= 1200
01343 #ifndef _DEBUG
01344 #pragma message("Turning compiler optimisation off to make makeOnePropertyCollisionVolume work ")
01345 #pragma optimize("",off)
01346 #endif
01347
01348 #endif
01349
01350 ippOnePropertyCollisionVolumePtr
01351 ippResponseParser::makeOnePropertyCollisionVolume(int * n)
01352 {
01353
01354 ippOtherKeyType _keyword = _resKeywords[*n];
01355 if ( _keyword!=ipp::Tool && _keyword!=ipp::FoundTool ) {
01356 _errorCode = BAD_SECOND_KEYWORD;
01357 return 0;
01358 }
01359 int m =0;
01360
01361
01362 int j = 0;
01363
01364 std::vector<ippBox> boxes;
01365
01366 int k = (*n + 3);
01367 if (_resTypes[k] != RESPARENLEFT) {
01368 _errorCode = BAD_RESPONSE_ITEMS;
01369
01370 } else if (_resTypes[k + 1] == RESPARENRIGHT) {
01371
01372 *n = (*n + 6);
01373 m = 0;
01374 if ((_itemCount != (k + 2)) && (_resTypes[k + 2] != RESCOMMA)){
01375 _errorCode = BAD_RESPONSE_ITEMS;
01376 }
01377
01378 } else {
01379
01380 while(_errorCode == OK) {
01381
01382 m++;
01383
01384
01385
01386 if (_resTypes[k + 1] != RESKEYWORD) {
01387
01388 _errorCode = BAD_RESPONSE_ITEMS;
01389 } else if (_resKeywords[k + 1] != OBB) {
01390
01391 _errorCode = BAD_RESPONSE_ITEMS;
01392 } else if (_itemCount < (k + 32) ) {
01393
01394 _errorCode = BAD_RESPONSE_ITEMS;
01395 }
01396
01397 if (_errorCode == OK) {
01398
01399 k += 2;
01400
01401 for (j = 0; j < 30; j = (j + 2)) {
01402 if ((_resTypes[k + j] != RESCOMMA) ||
01403 (_resTypes[k + j + 1] != RESDOUBLE)) {
01404 _errorCode = BAD_RESPONSE_ITEMS;
01405 }
01406 }
01407 }
01408
01409 if (_errorCode == OK) {
01410
01411 if (_resTypes[k + 30] == RESPARENRIGHT) {
01412
01413 break;
01414 } else if (_resTypes[k + 30] != RESCOMMA) {
01415
01416 _errorCode = BAD_RESPONSE_ITEMS;
01417 } else {
01418
01419 k += 30;
01420 }
01421 }
01422 }
01423 if (_errorCode == OK) {
01424 if ((_itemCount != (k + 31)) && (_resTypes[k + 31] != RESCOMMA)){
01425 _errorCode = BAD_RESPONSE_ITEMS;
01426 }
01427 }
01428 if (_errorCode == OK) {
01429
01430 k = (*n + 6);
01431
01432 for (j = 0; j < m; j++) {
01433 ippBox box;
01434 box.Cx = _resDoubles[k + 0];
01435 box.Cy = _resDoubles[k + 2];
01436 box.Cz = _resDoubles[k + 4];
01437 box.Ex = _resDoubles[k + 6];
01438 box.Ey = _resDoubles[k + 8];
01439 box.Ez = _resDoubles[k + 10];
01440 box.Ix = _resDoubles[k + 12];
01441 box.Iy = _resDoubles[k + 14];
01442 box.Iz = _resDoubles[k + 16];
01443 box.Jx = _resDoubles[k + 18];
01444 box.Jy = _resDoubles[k + 20];
01445 box.Jz = _resDoubles[k + 22];
01446 box.Kx = _resDoubles[k + 24];
01447 box.Ky = _resDoubles[k + 26];
01448 box.Kz = _resDoubles[k + 28];
01449 boxes.push_back(box);
01450
01451 k = (k + 32);
01452 }
01453 }
01454 *n = (*n + 5 + (m * 32));
01455 }
01456 return ((_errorCode != OK) ? NULL :
01457 new ippOnePropertyCollisionVolume(_keyword, boxes));
01458 }
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498 ippOnePropertyIdPtr ippResponseParser::makeOnePropertyId(int * n)
01499 {
01500 int m;
01501 m = *n;
01502 if ((_itemCount < (m + 6)) ||
01503 (_resTypes[m + 3] != RESPARENLEFT) ||
01504 (_resTypes[m + 4] != RESSTRING) ||
01505 (_resTypes[m + 5] != RESPARENRIGHT) ||
01506 ((_itemCount != (m + 6)) && (_resTypes[m + 6] != RESCOMMA)))
01507 _errorCode = BAD_RESPONSE_ITEMS;
01508 *n = (m + 7);
01509 return ((_errorCode != OK) ? NULL :
01510 new ippOnePropertyId(_resKeywords[m], _resStrings[m + 4].c_str()));
01511 }
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550 ippOnePropertyNamePtr ippResponseParser::makeOnePropertyName(int * n)
01551 {
01552 int m;
01553 m = *n;
01554 if ((_itemCount < (m + 6)) ||
01555 (_resTypes[m + 3] != RESPARENLEFT) ||
01556 (_resTypes[m + 4] != RESSTRING) ||
01557 (_resTypes[m + 5] != RESPARENRIGHT) ||
01558 ((_itemCount != (m + 6)) && (_resTypes[m + 6] != RESCOMMA)))
01559 _errorCode = BAD_RESPONSE_ITEMS;
01560 *n = (m + 7);
01561 return ((_errorCode != OK) ? NULL :
01562 new ippOnePropertyName(_resKeywords[m], _resStrings[m+4].c_str()));
01563 }
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610 bool ippResponseParser::CheckOptionalArgument(
01611 int& n,
01612 bool& hasArgument,
01613 ippOtherKeyType type,
01614 double& value,
01615 parserResErrorId errorIfDuplicated
01616 )
01617 {
01618
01619 if (_errorCode != OK) { return false; }
01620 if (_itemCount < n+3) { return false; }
01621 if (!match(_resTypes,"k(#)",n)) {
01622 return true;
01623 }
01624 if (_resKeywords[n] != type ){
01625 return true;
01626 }
01627 if (hasArgument ) {
01628 _errorCode = errorIfDuplicated;
01629 } else {
01630 hasArgument = true;
01631 value = _resDoubles[ n + 2];
01632 n += 5;
01633 }
01634
01635
01636
01637
01638
01639
01640 return true;
01641 }
01642 bool ippResponseParser::CheckOptionalArgument(
01643 int& n,
01644 bool& hasArgument,
01645 ippOtherKeyType type1,
01646 ippOtherKeyType type2,
01647 double& value,
01648 parserResErrorId errorIfDuplicated
01649 )
01650 {
01651
01652 if (_errorCode != OK) { return false; }
01653 if (_itemCount < n+3) { return false; }
01654 if (!match(_resTypes,"k.k(#)",n)) {
01655 return true;
01656 }
01657 if (_resKeywords[n] != type1 || _resKeywords[n+2] != type2){
01658 return true;
01659 }
01660 if (hasArgument ) {
01661 _errorCode = errorIfDuplicated;
01662 } else {
01663 hasArgument = true;
01664 value = _resDoubles[ n + 4];
01665 n += 7;
01666 }
01667 return true;
01668 }
01669
01670 bool ippResponseParser::CheckOptionalArgument(
01671 int& n,
01672 bool& hasArgument,
01673 ippOtherKeyType type,
01674 double& value1,
01675 double& value2,
01676 double& value3,
01677 parserResErrorId errorIfDuplicated
01678 )
01679 {
01680
01681 if (_errorCode != OK) { return false; }
01682 if (_itemCount < n+3) { return false; }
01683 if (!match(_resTypes,"k(#,#,#)",n)) {
01684 return true;
01685 }
01686 if (_resKeywords[n] != type ){
01687 return true;
01688 }
01689 if (hasArgument ) {
01690 _errorCode = errorIfDuplicated;
01691 } else {
01692 hasArgument = true;
01693 value1 = _resDoubles[ n + 2];
01694 value2 = _resDoubles[ n + 4];
01695 value3 = _resDoubles[ n + 6];
01696 n += 9;
01697 }
01698
01699
01700
01701
01702
01703
01704 return true;
01705 }
01706
01707 ippResponsePtr ippResponseParser::makePtMeasEResponse()
01708 {
01709 int n;
01710 bool hasER = false;
01711 bool hasIJK = false;
01712 bool hasIJKAct = false;
01713 bool hasQ = false;
01714 bool hasR = false;
01715 bool hasToolA = false;
01716 bool hasToolB = false;
01717 bool hasToolC = false;
01718 bool hasX = false;
01719 bool hasY = false;
01720 bool hasZ = false;
01721 double ERvalue = 0;
01722 double Ivalue = 0;
01723 double Jvalue = 0;
01724 double Kvalue = 0;
01725 double Rvalue = 0;
01726 double IJKActvalue = 0;
01727 double QValue = 0;
01728 double toolAvalue = 0;
01729 double toolBvalue = 0;
01730 double toolCvalue = 0;
01731 double Xvalue = 0;
01732 double Yvalue = 0;
01733 double Zvalue = 0;
01734
01735 _responseName = DataPtMeasE;
01736
01737 if (_resTypes[1] != RESPARENLEFT) {
01738 _errorCode = BAD_RESPONSE_ITEMS;
01739 }
01740
01741 for (n = 2; ((n < _itemCount) && (_errorCode == OK)); ) {
01742
01743 int old_n=n;
01744 CheckOptionalArgument(n,hasER,ER,ERvalue,ER_USED_TWICE);
01745 CheckOptionalArgument(n,hasX, _X,Xvalue ,X_USED_TWICE);
01746 CheckOptionalArgument(n,hasY, _Y,Yvalue ,Y_USED_TWICE);
01747 CheckOptionalArgument(n,hasZ, _Z,Zvalue ,Z_USED_TWICE);
01748 CheckOptionalArgument(n,hasR, _R,Rvalue ,R_USED_TWICE);
01749 CheckOptionalArgument(n,hasToolA,Tool,_A,toolAvalue ,TOOL_A_USED_TWICE);
01750 CheckOptionalArgument(n,hasToolB,Tool,_B,toolBvalue ,TOOL_B_USED_TWICE);
01751 CheckOptionalArgument(n,hasToolC,Tool,_C,toolCvalue ,TOOL_C_USED_TWICE);
01752 CheckOptionalArgument(n,hasIJK ,_IJK, Ivalue,Jvalue,Kvalue,IJK_USED_TWICE);
01753 CheckOptionalArgument(n,hasIJKAct,_IJKAct, IJKActvalue,IJK_USED_TWICE);
01754 if (old_n == n && _errorCode == OK) {
01755
01756 _errorCode = BAD_RESPONSE_ITEMS;
01757 }
01758 }
01759 return ((_errorCode != OK) ? NULL :
01760 new ippPtMeasEResponse(hasER, hasIJK,hasIJKAct, hasR, hasToolA, hasToolB,
01761 hasToolC, hasX, hasY, hasZ, ERvalue, Ivalue,
01762 Jvalue, Kvalue, IJKActvalue,Rvalue, toolAvalue, toolBvalue,
01763 toolCvalue, Xvalue, Yvalue, Zvalue));
01764 }
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821 ippResponsePtr ippResponseParser::makePtMeasOrGetResponse()
01822 {
01823 int n;
01824 bool hasER = false;
01825 bool hasIJK = false;
01826 bool hasIJKAct = false;
01827 bool hasQ = false;
01828
01829 bool hasR = false;
01830 bool hasToolA = false;
01831 bool hasToolB = false;
01832 bool hasToolC = false;
01833 bool hasX = false;
01834 bool hasY = false;
01835 bool hasZ = false;
01836 double ERvalue = 0;
01837 double Ivalue = 0;
01838 double Jvalue = 0;
01839 double Kvalue = 0;
01840 double IJKActvalue = 0;
01841 double Qvalue =0;
01842 double Rvalue = 0;
01843 double toolAvalue = 0;
01844 double toolBvalue = 0;
01845 double toolCvalue = 0;
01846 double Xvalue = 0;
01847 double Yvalue = 0;
01848 double Zvalue = 0;
01849
01850 _responseName = DataPtMeasOrGet;
01851
01852 for (n = 0; ((n <=_itemCount) && (_errorCode == OK)); ) {
01853
01854 int old_n=n;
01855 CheckOptionalArgument(n,hasER,ER,ERvalue,ER_USED_TWICE);
01856 CheckOptionalArgument(n,hasX, _X,Xvalue ,X_USED_TWICE);
01857 CheckOptionalArgument(n,hasY, _Y,Yvalue ,Y_USED_TWICE);
01858 CheckOptionalArgument(n,hasZ, _Z,Zvalue ,Z_USED_TWICE);
01859 CheckOptionalArgument(n,hasR, _R,Rvalue ,R_USED_TWICE);
01860 CheckOptionalArgument(n,hasToolA,Tool,_A,toolAvalue ,TOOL_A_USED_TWICE);
01861 CheckOptionalArgument(n,hasToolB,Tool,_B,toolBvalue ,TOOL_B_USED_TWICE);
01862 CheckOptionalArgument(n,hasToolC,Tool,_C,toolCvalue ,TOOL_C_USED_TWICE);
01863 CheckOptionalArgument(n,hasIJK ,_IJK, Ivalue,Jvalue,Kvalue,IJK_USED_TWICE);
01864 CheckOptionalArgument(n,hasIJKAct,_IJKAct, IJKActvalue,IJKACT_USED_TWICE);
01865 CheckOptionalArgument(n,hasQ ,Q, Qvalue,Q_USED_TWICE);
01866 if (old_n == n && _errorCode == OK) {
01867
01868 _errorCode = BAD_RESPONSE_ITEMS;
01869 }
01870 }
01871 if(_errorCode != OK) {
01872 return 0;
01873 }
01874 if (_tagType == EventTag) {
01875
01876 if (hasER || hasIJK) {
01877 _errorCode = BAD_RESPONSE_ITEMS;
01878 return 0;
01879 }
01880 return new ippOnMoveReportEResponse(_tag, hasR, hasToolA,
01881 hasToolB, hasToolC, hasX, hasY, hasZ,
01882 Rvalue,
01883 toolAvalue, toolBvalue, toolCvalue,
01884 Xvalue, Yvalue, Zvalue);
01885
01886 } else {
01887 return new ippPtMeasOrGetResponse(
01888 _tag, hasER, hasIJK,hasIJKAct,hasQ, hasR,
01889 hasToolA,hasToolB, hasToolC,
01890 hasX, hasY, hasZ,
01891 ERvalue, Ivalue, Jvalue, Kvalue, int(IJKActvalue),Qvalue,Rvalue,
01892 toolAvalue, toolBvalue, toolCvalue,
01893 Xvalue, Yvalue, Zvalue);
01894 }
01895 }
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923 ippResponsePtr ippResponseParser::makeScanResponse()
01924 {
01925 int n;
01926
01927
01928 _responseName = DataScan;
01929
01930 if ((_itemCount % 2) != 1) {
01931 _errorCode = BAD_RESPONSE_ITEMS;
01932 }
01933
01934 std::auto_ptr<double> scanData(new double[(_itemCount + 1) / 2]);
01935
01936 for (n = 0; (_errorCode == OK); n++) {
01937 if (_resTypes[n] == RESDOUBLE) {
01938 scanData.get()[n / 2] = _resDoubles[n];
01939 } else {
01940 _errorCode = BAD_RESPONSE_ITEMS;
01941 }
01942 n++;
01943 if (n >= _itemCount) {
01944 break;
01945 }
01946 if (_resTypes[n] != RESCOMMA) {
01947 _errorCode = BAD_RESPONSE_ITEMS;
01948 }
01949 }
01950 return ((_errorCode != OK) ? NULL :
01951 new ippScanResponse(_tag, ((_itemCount + 1) / 2), scanData.get()));
01952 }
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975 ippResponsePtr ippResponseParser::makeServerInitiatedResponse()
01976 {
01977 ippResponsePtr aResponse;
01978
01979 if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == ChangeToolKey))
01980 aResponse = makeChangeToolEResponse();
01981 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == GoToKey))
01982 aResponse = makeGoToEResponse();
01983 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == KeyPress))
01984 aResponse = makeKeyPressEResponse();
01985 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == PtMeasKey))
01986 aResponse = makePtMeasEResponse();
01987 else if ((_resTypes[0] == RESKEYWORD) && (_resKeywords[0] == SetPropKey))
01988 aResponse = makeSetPropEResponse();
01989 else
01990 {
01991 aResponse = NULL;
01992 _errorCode = BAD_RESPONSE_ITEMS;
01993 }
01994 return aResponse;
01995 }
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036 ippResponsePtr ippResponseParser::makeSetPropEResponse()
02037 {
02038 _responseName = DataSetPropE;
02039
02040 ippSetPropEResponsePtr response = new ippSetPropEResponse();
02041
02042 IPP_ASSERT(_resTypes[0] == RESKEYWORD || _resKeywords[0] == SetPropKey);
02043 if (_resTypes[1] != RESPARENLEFT) {
02044 _errorCode = BAD_CHARACTER_AFTER_KEYWORD;
02045 return 0;
02046 }
02047 if (_resTypes[_itemCount-1] != RESPARENRIGHT) {
02048 _errorCode = BAD_CHARACTER_AFTER_KEYWORD;
02049 return 0;
02050 }
02051
02052 int n =2;
02053 for ( n = 2; ((n < _itemCount-1) && (_errorCode == OK)); ) {
02054
02055 ippOtherKeyType key1 = EmptyKey;
02056 ippOtherKeyType key2 = EmptyKey;
02057 ippOtherKeyType key3 = EmptyKey;
02058 ippOtherKeyType key4 = EmptyKey;
02059 double value = 0;
02060
02061 int m=n;
02062 bool foundPropertyNumber = false;
02063
02064 if(match(_resTypes,"k.k(#)",m)) {
02065 key1 = _resKeywords[m];
02066 key2 = _resKeywords[m+2];
02067 value = _resDoubles[m+4];
02068 foundPropertyNumber = true;
02069 n = (m + 7);
02070 } else if(match(_resTypes,"k.k.k(#)",m)) {
02071 key1 = _resKeywords[m];
02072 key2 = _resKeywords[m+2];
02073 key3 = _resKeywords[m+4];
02074 value = _resDoubles[m+6];
02075 foundPropertyNumber = true;
02076 n = (m + 9);
02077 } else if(match(_resTypes,"k.k.k.k(#)",m)) {
02078 key1 = _resKeywords[m];
02079 key2 = _resKeywords[m+2];
02080 key3 = _resKeywords[m+4];
02081 key4 = _resKeywords[m+6];
02082 value = _resDoubles[m+8];
02083 foundPropertyNumber = true;
02084 n = (m + 11);
02085 }
02086 if (foundPropertyNumber) {
02087 ippProp prop(key1,key2,key3,key4);
02088 if (!PropertyIsAllowedAndWritable(prop)) {
02089 _errorCode = BAD_PROPERTY;
02090 }
02091
02092 response->addPropValue(prop,value);
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105 } else {
02106 _errorCode = BAD_SECOND_KEYWORD;
02107 }
02108 }
02109 if (n -1 >= _resTypes.size() || _resTypes[n-1] != RESPARENRIGHT) {
02110 _errorCode = BAD_CHARACTER_AFTER_KEYWORD;
02111 return 0;
02112 }
02113 if (_errorCode != OK) {
02114 response =0;
02115 }
02116 return response;
02117
02118 }
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145 ippResponsePtr ippResponseParser::makeStringResponse()
02146 {
02147 _responseName = DataString;
02148 return new ippStringResponse(_tag, _resStrings[0].c_str());
02149 }
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175 ippResponsePtr ippResponseParser::makeTiltCenterPartResponse()
02176 {
02177 _responseName = DataTiltCenterPart;
02178 if ((_itemCount != 4) || !match(_resTypes,"k(#)")) {
02179 _errorCode = BAD_RESPONSE_ITEMS;
02180 } else if ((_resDoubles[2] != 0) && (_resDoubles[2] != 1)) {
02181 _errorCode = VALUE_MUST_BE_0_OR_1;
02182 }
02183 return ((_errorCode != OK) ? NULL :
02184 new ippTiltCenterPartResponse(_tag,((_resDoubles[2] == 1) ? true :false)));
02185 }
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211 ippResponsePtr ippResponseParser::makeTiltPartResponse()
02212 {
02213 _responseName = DataTiltPart;
02214 if ((_itemCount != 4) || !match(_resTypes,"k(#)")) {
02215 _errorCode = BAD_RESPONSE_ITEMS;
02216 } else if ((_resDoubles[2] != 0) && (_resDoubles[2] != 1)) {
02217 _errorCode = VALUE_MUST_BE_0_OR_1;
02218 }
02219 return ((_errorCode != OK) ? NULL :
02220 new ippTiltPartResponse(_tag, ((_resDoubles[2] == 1) ? true : false)));
02221 }
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256 ippOtherKeyType getFromString(const std::string& );
02257
02258 void ippResponseParser::parseKeyword()
02259 {
02260 int length =0;
02261
02262 _resKeywords[_itemCount] = ippOtherKeyType_INVALID;
02263 _errorCode = BAD_KEYWORD;
02264 const char* keyword = (_inputArray + _arrayIndex);
02265 const char* endkeyword = keyword;
02266 while(isalpha(*endkeyword++));
02267
02268 int keywordLength = (endkeyword-keyword)-1;
02269
02270 _resKeywords[_itemCount] = getFromString(std::string(keyword,keywordLength));
02271 if (ippOtherKeyType_INVALID== _resKeywords[_itemCount]) {
02272 _errorCode = BAD_KEYWORD;
02273 return;
02274 }
02275
02276 if (_resKeywords[_itemCount] != -1) {
02277 _arrayIndex = (_arrayIndex + keywordLength)-1;
02278 if ((_inputArray[_arrayIndex + 1] == '.') ||
02279 (_inputArray[_arrayIndex + 1] == ',') ||
02280 (_inputArray[_arrayIndex + 1] == '(') ||
02281 (_inputArray[_arrayIndex + 1] == ')')) {
02282 _errorCode = OK;
02283 } else {
02284 _errorCode = BAD_CHARACTER_AFTER_KEYWORD;
02285 }
02286 }
02287 }
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318 void ippResponseParser::parseNumber()
02319 {
02320 int sign = 0;
02321 int dot = 0;
02322 int k;
02323 int j;
02324 char save;
02325
02326 if ((_inputArray[_arrayIndex] == '-') || (_inputArray[_arrayIndex] == '+')) {
02327 sign = 1;
02328 }
02329 for (k = (_arrayIndex + sign); ((_errorCode == OK) && ((_inputArray[k] == '.') || ((_inputArray[k] > 47) && (_inputArray[k] < 58)))); k++) {
02330 if (_inputArray[k] == '.') {
02331 if (dot == 0) {
02332 dot = 1;
02333 } else {
02334 _errorCode = BAD_NUMBER_TWO_DECIMAL_POINTS;
02335 }
02336 }
02337 }
02338 if ((_errorCode == OK) && ((_arrayIndex + sign + dot) == k)) {
02339 _errorCode = BAD_NUMBER_NO_DIGITS;
02340 }
02341 if ((_errorCode == OK) && ((k - (_arrayIndex + sign + dot)) > 16)) {
02342 _errorCode = BAD_NUMBER_MORE_THAN_16_DIGITS;
02343 }
02344 if ((_errorCode == OK) && ((_inputArray[k] == 'E') || (_inputArray[k] == 'e'))) {
02345 k++;
02346 if ((_inputArray[k] == '+') || (_inputArray[k] == '-')) {
02347 k++;
02348 }
02349 for (j = 0; ((_inputArray[k] > 47) && (_inputArray[k] < 58)); j++) {
02350 k++;
02351 }
02352 if ((j < 1) || (j > 3)) {
02353 _errorCode = BAD_E_NUMBER_EXPONENT_MUST_HAVE_ONE_TWO_OR_THREE_DIGITS;
02354 }
02355 }
02356 if (_errorCode == OK) {
02357 save = _inputArray[k];
02358 _inputArray[k] = 0;
02359 sscanf((_inputArray +_arrayIndex), "%lf", &(_resDoubles[_itemCount]));
02360 _inputArray[k] = save;
02361 _arrayIndex = (k - 1);
02362 }
02363 }
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383 void ippResponseParser::parseResItems()
02384 {
02385 char c;
02386 char d;
02387
02388 _arrayIndex = 8;
02389
02390 for(_itemCount = 0; ((c = _inputArray[_arrayIndex]) != 13); _itemCount++) {
02391
02392 if (_itemCount == _resSize) {
02393 makeArraysBigger();
02394 }
02395
02396 d = _inputArray[_arrayIndex + 1];
02397
02398 if (c == '(') {
02399 _resTypes[_itemCount] = RESPARENLEFT;
02400
02401 } else if (c == ')') {
02402 _resTypes[_itemCount] = RESPARENRIGHT;
02403
02404 } else if (c == '"') {
02405
02406 parseString();
02407 _resTypes[_itemCount] = RESSTRING;
02408
02409 } else if (c == ',') {
02410 _resTypes[_itemCount] = RESCOMMA;
02411
02412 } else if ((c == '.') && isupper(d) ) {
02413 _resTypes[_itemCount] = RESDOT;
02414
02415 } else if ((c == '-') ||(c == '+') ||(c == '.') || isdigit(c)) {
02416 parseNumber();
02417 _resTypes[_itemCount] = RESDOUBLE;
02418
02419 } else if (isupper(c)) {
02420 parseKeyword();
02421 _resTypes[_itemCount] = RESKEYWORD;
02422
02423 } else {
02424 _errorCode = BAD_RESPONSE_ITEMS;
02425 }
02426
02427 if (_errorCode != OK) {
02428 break;
02429 }
02430 _arrayIndex++;
02431 }
02432 }
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463 ippResponsePtr ippResponseParser::parseResponse()
02464 {
02465 ippResponsePtr aResponse;
02466
02467 _responseName = ippResponseNameType_ERROR;
02468
02469 parseTag();
02470
02471 if (_errorCode == OK) {
02472 if (_inputArray[6] == '&'){
02473 if ((_inputArray[7] != 13) ||
02474 (_inputArray[8] != 10) ||
02475 (_inputArray[9] != 0)) {
02476 _errorCode = BAD_CHARACTER_AFTER_RESPONSE_END;
02477 } else {
02478 aResponse = new ippAckResponse(_tag, _tagType);
02479 }
02480 } else if (_inputArray[6] == '%') {
02481 if ((_inputArray[7] != 13) ||
02482 (_inputArray[8] != 10) ||
02483 (_inputArray[9] != 0))
02484 _errorCode = BAD_CHARACTER_AFTER_RESPONSE_END;
02485 else {
02486 aResponse = new ippCompleteResponse(_tag, _tagType);
02487 }
02488
02489 } else if ((_inputArray[6] != '!') &&(_inputArray[6] != '#')) {
02490 _errorCode = BAD_SEVENTH_CHARACTER_IN_RESPONSE;
02491
02492 } else if (_inputArray[7] != ' ') {
02493 _errorCode = SPACE_MISSING_AT_EIGHTH_CHARACTER_OF_RESPONSE;
02494
02495 } else {
02496 unSpaceInputArray();
02497
02498 if (_errorCode == OK){
02499 parseResItems();
02500 }
02501 if ((_errorCode == OK) &&
02502 ((_inputArray[_arrayIndex] != 13) ||
02503 (_inputArray[_arrayIndex + 1] != 10) ||
02504 (_inputArray[_arrayIndex + 2] != 0))) {
02505 _errorCode = BAD_CHARACTER_AFTER_RESPONSE_END;
02506 }
02507 if (_errorCode == OK) {
02508 if (_inputArray[6] == '!') {
02509 aResponse = makeErrorResponse();
02510 } else if (_tag == 0) {
02511 aResponse = makeServerInitiatedResponse();
02512 } else {
02513 aResponse = makeDataResponse();
02514 }
02515 }
02516 }
02517 }
02518
02519 return ((_errorCode == OK) ? aResponse : NULL);
02520 }
02521
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553 void ippResponseParser::parseString()
02554 {
02555
02556 _arrayIndex++;
02557 int start = _arrayIndex;
02558 for (; (_inputArray[_arrayIndex] != '"'); _arrayIndex++) {
02559
02560 if ((_inputArray[_arrayIndex] < 32) || (_inputArray[_arrayIndex] > 126)) {
02561 _errorCode = BAD_STRING;
02562 return;
02563 }
02564 }
02565 _inputArray[_arrayIndex] = 0;
02566 _resStrings.resize(_itemCount+1,"");
02567 _resStrings[_itemCount] = _inputArray + start;
02568 _inputArray[_arrayIndex] = '"';
02569 }
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600 void ippResponseParser::parseTag()
02601 {
02602 if (!isdigit(_inputArray[1]) ||
02603 !isdigit(_inputArray[2]) ||
02604 !isdigit(_inputArray[3]) ||
02605 !isdigit(_inputArray[4])) {
02606 _errorCode = BAD_TAG_CHARACTER;
02607
02608 } else if (_inputArray[5] != 32) {
02609 _errorCode = SPACE_MISSING_AFTER_TAG;
02610
02611 } else if (_inputArray[0] == 'E') {
02612
02613 sscanf((_inputArray + 1), "%d", &_tag);
02614
02615 if ((_tag == 0) && (_inputArray[6] != '!') && (_inputArray[6] != '#')) {
02616 _errorCode = ZERO_TAG_MUST_BE_SERVER_INITIATED_RESPONSE;
02617 } else {
02618 _tagType = EventTag;
02619 _errorCode = OK;
02620 }
02621
02622 } else if (isdigit(_inputArray[0])) {
02623
02624 sscanf(_inputArray, "%d", &_tag);
02625 if (_tag == 0) {
02626 _errorCode = TAG_NUMBER_OUT_OF_RANGE_FOR_COMMAND_TAG;
02627 } else {
02628 _tagType = CommandTag;
02629 }
02630 _errorCode = OK;
02631 } else {
02632 _errorCode = BAD_TAG_CHARACTER;
02633 }
02634 }
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653 void ippResponseParser::setInput(
02654 const char * input
02655 )
02656 {
02657 strncpy(_inputArray, input, (IPPSIZE - 1));
02658 }
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688 bool UnSpaceInputArray(char* _inputArray,int start);
02689
02690 void ippResponseParser::unSpaceInputArray()
02691 {
02692 if (!::UnSpaceInputArray(_inputArray,8)) {
02693 _errorCode = ILLEGAL_SPACE;
02694 }
02695 }
02696
02697
02698 void ippResponseParser::dump_token(int k)
02699 {
02700 std::cout << "item " << std::setw(3) << k << " ";
02701 switch(_resTypes[k])
02702 {
02703 case RESCOMMA: std::cout << "," ;break;
02704 case RESDOT: std::cout << "." ;break;
02705 case RESDOUBLE: std::cout << "#" ;break;
02706 std::cout <<"( value " << _resDoubles[k] << ")";
02707 case RESKEYWORD:
02708 std::cout << "K" ;
02709 std::cout <<" ( keywork " << getKeyString(_resKeywords[k]) << ")";
02710 break;
02711 case RESPARENLEFT: std::cout << "(" ;break;
02712 case RESPARENRIGHT: std::cout << ")" ;break;
02713 case RESSTRING: std::cout << "s" ;break;
02714 }
02715 std::cout << std::endl;
02716 }
02717
02718
02719