Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
#include "devpropparser.h"
2
 
3
const char* DevPropParser::dtNames1[] PROGMEM =
4
{
5
        msgUNDEF,
6
        msgINT8,       
7
        msgUINT8,      
8
        msgINT16,      
9
        msgUINT16,
10
        msgINT32,      
11
        msgUINT32,
12
        msgINT64,      
13
        msgUINT64,
14
        msgINT128,
15
        msgUINT128
16
};
17
 
18
const char* DevPropParser::dtNames2[] PROGMEM =
19
{
20
        msgUNDEF,
21
        msgAINT8,
22
        msgAUINT8,     
23
        msgAINT16,     
24
        msgAUINT16,
25
        msgAINT32,
26
        msgAUINT32,
27
        msgAINT64,     
28
        msgAUINT64,
29
        msgAINT128,
30
        msgAUINT128
31
};
32
 
33
const char* DevPropParser::prNames[] PROGMEM =
34
{
35
        msgUndefined,                                  
36
        msgBatteryLevel,                               
37
        msgFunctionalMode,                     
38
        msgImageSize,                                  
39
        msgCompressionSetting,         
40
        msgWhiteBalance,                               
41
        msgRGBGain,                                    
42
        msgFNumber,                                    
43
        msgFocalLength,                        
44
        msgFocusDistance,                              
45
        msgFocusMode,                                  
46
        msgExposureMeteringMode,               
47
        msgFlashMode,                                  
48
        msgExposureTime,                               
49
        msgExposureProgramMode,        
50
        msgExposureIndex,                              
51
        msgExposureBiasCompensation,   
52
        msgDateTime,                                   
53
        msgCaptureDelay,                               
54
        msgStillCaptureMode,                   
55
        msgContrast,                                   
56
        msgSharpness,                                  
57
        msgDigitalZoom,                        
58
        msgEffectMode,                         
59
        msgBurstNumber,                        
60
        msgBurstInterval,                              
61
        msgTimelapseNumber,                    
62
        msgTimelapseInterval,                  
63
        msgFocusMeteringMode,                  
64
        msgUploadURL,                                  
65
        msgArtist,                                     
66
        msgCopyrightInfo                               
67
};
68
 
69
void DevPropParser::PrintDataType(uint8_t **pp, uint16_t *pcntdn)
70
{
71
        dataType = *((uint16_t*)(*pp));
72
        bytesSize = GetDataSize();
73
 
74
        Notify(PSTR("Data Type:\t\t"));
75
 
76
        switch (((dataType >> 8) & 0xFF))
77
        {
78
        case 0x00:
79
                if ((dataType & 0xFF) <= (PTP_DTC_UINT128 & 0xFF))
80
                        Notify((char*)pgm_read_word(&dtNames1[(dataType & 0xFF)]));
81
                break;
82
        case 0x40:
83
                if ((dataType & 0xFF) <= (PTP_DTC_AUINT128 & 0xFF))
84
                        Notify((char*)pgm_read_word(&dtNames2[(dataType & 0xFF)]));
85
                break;
86
        case 0xFF:
87
                Notify(PSTR("STR"));
88
                break;
89
        default:
90
                Notify(PSTR("Unknown"));
91
        }
92
        Notify(PSTR("\r\n"));
93
        (*pp)           += 2;          
94
        (*pcntdn)       -= 2;
95
}
96
 
97
void DevPropParser::PrintDevProp(uint8_t **pp, uint16_t *pcntdn)
98
{
99
        uint16_t        op = *((uint16_t*)(*pp));
100
 
101
        Notify(PSTR("\r\nDevice Property:\t"));
102
 
103
        if ((((op >> 8) & 0xFF) == 0x50) && ((op & 0xFF) <= (PTP_DPC_CopyrightInfo & 0xFF)))
104
        {
105
                PrintHex<uint16_t>(op);
106
                Notify(PSTR("\t"));
107
                Notify((char*)pgm_read_word(&prNames[(op & 0xFF)]));
108
                Notify(PSTR("\r\n"));
109
        }
110
        else
111
        {
112
                PrintHex<uint16_t>(op);
113
                Notify(PSTR(" (Vendor defined)\r\n"));
114
        }
115
        (*pp)           += 2;          
116
        (*pcntdn)       -= 2;
117
}
118
 
119
void DevPropParser::PrintGetSet(uint8_t **pp, uint16_t *pcntdn)
120
{
121
        Notify(PSTR("Get/Set:\t\t"));
122
        Notify(((**pp) == 0x01) ? PSTR("Get/Set\r\n") : (!(**pp)) ? PSTR("Get\r\n") : PSTR("Illegal\r\n"));
123
        (*pp) ++;              
124
        (*pcntdn) --;
125
}
126
 
127
uint8_t DevPropParser::GetDataSize()
128
{
129
        switch (dataType)
130
        {
131
        case PTP_DTC_INT8:     
132
        case PTP_DTC_UINT8:    
133
            bytesSize = 1;
134
            break;
135
        case PTP_DTC_AINT8:    
136
        case PTP_DTC_AUINT8:
137
            bytesSize = 1;
138
            enumParser.Initialize(4, bytesSize, &theBuffer);
139
            break;
140
        case PTP_DTC_INT16:    
141
        case PTP_DTC_UINT16:   
142
            bytesSize = 2;
143
            enumParser.Initialize(4, bytesSize, &theBuffer);
144
            break;
145
        case PTP_DTC_AINT16:   
146
        case PTP_DTC_AUINT16:
147
            bytesSize = 2;
148
            break;
149
        case PTP_DTC_STR:
150
            bytesSize = 2;
151
            enumParser.Initialize(1, bytesSize, &theBuffer);
152
            break;
153
        case PTP_DTC_INT32:    
154
        case PTP_DTC_UINT32:   
155
            bytesSize = 4;
156
            break;
157
        case PTP_DTC_AINT32:   
158
        case PTP_DTC_AUINT32:
159
            bytesSize = 4;
160
            enumParser.Initialize(4, bytesSize, &theBuffer);
161
            break;
162
        case PTP_DTC_INT64:    
163
        case PTP_DTC_UINT64:   
164
            bytesSize = 8;
165
            break;
166
        case PTP_DTC_AINT64:   
167
        case PTP_DTC_AUINT64:
168
            bytesSize = 8;
169
            enumParser.Initialize(4, bytesSize, &theBuffer);
170
            break;
171
        case PTP_DTC_INT128:   
172
        case PTP_DTC_UINT128:  
173
            bytesSize = 16;
174
            break;
175
        case PTP_DTC_AINT128:  
176
        case PTP_DTC_AUINT128:
177
            bytesSize = 16;
178
            enumParser.Initialize(4, bytesSize, &theBuffer);
179
            break;
180
        }
181
    return bytesSize;
182
}
183
 
184
bool DevPropParser::PrintValue(uint8_t **pp, uint16_t *pcntdn)
185
{
186
        switch (dataType)
187
        {
188
        case PTP_DTC_INT8:     
189
        case PTP_DTC_UINT8:    
190
                PrintHex<uint8_t>(**pp);
191
                (*pp) ++;
192
                (*pcntdn) --;
193
                break;
194
        case PTP_DTC_AINT8:    
195
        case PTP_DTC_AUINT8:
196
                if (!enumParser.Parse(pp, pcntdn, (PTP_ARRAY_EL_FUNC)&PrintByte))
197
                        return false;
198
                break;
199
        case PTP_DTC_INT16:    
200
        case PTP_DTC_UINT16:   
201
                PrintHex<uint16_t>(*((uint16_t*)*pp));
202
                (*pp)           += 2;
203
                (*pcntdn)       -= 2;
204
                break;
205
        case PTP_DTC_AINT16:   
206
        case PTP_DTC_AUINT16:
207
                if (!enumParser.Parse(pp, pcntdn, (PTP_ARRAY_EL_FUNC)&PrintTwoBytes))
208
                        return false;
209
                break;
210
        case PTP_DTC_INT32:    
211
        case PTP_DTC_UINT32:   
212
                PrintHex<uint32_t>(*((uint32_t*)*pp));
213
                (*pp)           += 4;
214
                (*pcntdn)       -= 4;
215
                break;
216
        case PTP_DTC_AINT32:   
217
        case PTP_DTC_AUINT32:
218
                if (!enumParser.Parse(pp, pcntdn, (PTP_ARRAY_EL_FUNC)&PrintFourBytes))
219
                        return false;
220
                break;
221
        case PTP_DTC_INT64:    
222
        case PTP_DTC_UINT64:   
223
                (*pp)           += 8;
224
                (*pcntdn)       -= 8;
225
                break;
226
        case PTP_DTC_AINT64:   
227
        case PTP_DTC_AUINT64:
228
                if (!enumParser.Parse(pp, pcntdn, (PTP_ARRAY_EL_FUNC)&PrintEightBytes))
229
                        return false;
230
                break;
231
        case PTP_DTC_INT128:   
232
        case PTP_DTC_UINT128:  
233
                (*pp)           += 16;
234
                (*pcntdn)       -= 16;
235
                break;
236
        case PTP_DTC_AINT128:  
237
        case PTP_DTC_AUINT128:
238
                if (!enumParser.Parse(pp, pcntdn, NULL))
239
                        return false;
240
                break;
241
        case PTP_DTC_STR:
242
                if (!enumParser.Parse(pp, pcntdn, (PTP_ARRAY_EL_FUNC)&PrintChar))
243
                        return false;
244
                break;
245
        }
246
        return true;
247
}
248
 
249
bool DevPropParser::ParseEnum(uint8_t **pp, uint16_t *pcntdn)
250
{
251
    if ((dataType & 0xFF00) == 0)
252
        return ParseEnumSingle(pp, pcntdn);
253
    else
254
        return ParseEnumArray(pp, pcntdn);
255
}
256
 
257
bool DevPropParser::ParseEnumArray(uint8_t **pp, uint16_t *pcntdn)
258
{
259
    switch(enStage)
260
    {
261
    case 0:
262
        theBuffer.valueSize = 2;
263
        valParser.Initialize(&theBuffer);
264
        enStage = 1;
265
    case 1:
266
        if (!valParser.Parse(pp, pcntdn))
267
            return false;
268
        enLen = 0;
269
        enLen = *((uint16_t*)theBuffer.pValue);
270
        enLenCntdn = enLen;
271
        enumParser.Initialize(4, bytesSize, &theBuffer);
272
        enStage = 2;
273
    case 2:
274
        for (; enLenCntdn; enLenCntdn--)
275
        {
276
            if (!enumParser.Parse(pp, pcntdn, (PTP_ARRAY_EL_FUNC)&PrintEnumValue), PTPListParser::modeArray, this)
277
                return false;
278
 
279
            Notify(PSTR("\r\n"));
280
            enumParser.Initialize(4, bytesSize, &theBuffer);
281
        }
282
        enStage = 0;
283
    } // switch
284
    return true;
285
}
286
 
287
bool DevPropParser::ParseEnumSingle(uint8_t **pp, uint16_t *pcntdn)
288
{
289
    switch(enStage)
290
    {
291
    case 0:
292
        enumParser.Initialize(2, bytesSize, &theBuffer);
293
//        Serial.println(bytesSize, DEC);
294
        enStage = 1;
295
    case 1:
296
        if (!enumParser.Parse(pp, pcntdn, (PTP_ARRAY_EL_FUNC)&PrintEnumValue, this))
297
            return false;
298
        enStage = 0;
299
    } // switch
300
    return true;
301
}
302
 
303
void DevPropParser::Parse(const uint16_t len, const uint8_t *pbuf, const uint32_t &offset)
304
{
305
        uint16_t        cntdn   = (uint16_t)len;
306
        uint8_t         *p      = (uint8_t*)pbuf;
307
 
308
        switch (nStage)
309
        {
310
        case 0:
311
                p       += 12;
312
                cntdn   -= 12;
313
                nStage = 1;
314
        case 1:
315
                PrintDevProp(&p, &cntdn);
316
                nStage = 2; //++;
317
        case 2:
318
                PrintDataType(&p, &cntdn);
319
                nStage = 3; //++;
320
        case 3:
321
                PrintGetSet(&p, &cntdn);
322
                nStage = 4; //++;
323
        case 4:
324
                Notify(PSTR("Default Value:\t\t"));
325
                nStage = 5; //++;
326
        case 5:
327
                if (!PrintValue(&p, &cntdn))
328
                        return;
329
                Notify(PSTR("\r\n"));
330
                nStage = 6; //++;
331
        case 6:
332
                Notify(PSTR("Current Value:\t\t"));
333
                nStage = 7; //++;
334
        case 7:
335
                if (!PrintValue(&p, &cntdn))
336
                        return;
337
                Notify(PSTR("\r\n"));
338
                nStage = 8; //++;
339
        case 8:
340
                formFlag = (*p);
341
                p ++;          
342
                cntdn --;
343
                nStage = 9; //++;
344
        case 9:
345
                if (formFlag == 1)
346
                {
347
                        Notify(PSTR("Range (Min,Max,Step):\t\t{"));
348
                        enumParser.Initialize(2, bytesSize, &theBuffer, PTPListParser::modeRange);
349
                }
350
                if (formFlag == 2)
351
                        Notify(PSTR("Enumeration:\t\t{"));
352
                nStage = 10; //++;
353
        case 10:
354
                if (formFlag == 1)
355
                        if (!enumParser.Parse(&p, &cntdn, (PTP_ARRAY_EL_FUNC)&PrintEnumValue))
356
                              return;
357
 
358
                if (formFlag == 2)
359
                        if (!ParseEnum(&p, &cntdn))
360
                                return;
361
 
362
                if (formFlag)
363
                        Notify(PSTR("}\r\n"));
364
 
365
                nStage = 0;
366
        }
367
}
368