1 /* This test is designed to test the simple dpump host/device class operation. */
2
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "fx_api.h"
6 #include "ux_api.h"
7 #include "ux_system.h"
8 #include "ux_utility.h"
9
10 #include "ux_device_class_pima.h"
11 #include "ux_host_class_pima.h"
12
13 #include "ux_pictbridge.h"
14
15 #include "ux_hcd_sim_host.h"
16 #include "ux_device_stack.h"
17
18 #include "ux_test_dcd_sim_slave.h"
19 #include "ux_test_hcd_sim_host.h"
20 #include "ux_test_utility_sim.h"
21
22 #include "ux_test_jpeg_image.h"
23
24 /* Define constants. */
25 #define UX_TEST_STACK_SIZE (2*1024)
26 #define UX_TEST_MEMORY_SIZE (512*1024)
27
28 /* Define local/extern function prototypes. */
29
30 static void test_thread_entry(ULONG);
31
32 static TX_THREAD test_thread_host_simulation;
33 static TX_THREAD test_thread_device_simulation;
34 static void test_thread_host_simulation_entry(ULONG);
35 static void test_thread_device_simulation_entry(ULONG);
36
37 static VOID test_pima_instance_activate(VOID *pima_instance);
38 static VOID test_pima_instance_deactivate(VOID *pima_instance);
39
40
41 /* Define global data structures. */
42 static UCHAR usbx_memory[UX_TEST_MEMORY_SIZE + (UX_TEST_STACK_SIZE * 2)];
43
44 static UX_SLAVE_CLASS_PIMA_DEVICE *pima_device;
45 static UX_PICTBRIDGE pictbridge_device;
46 static UX_PICTBRIDGE_PRINTINFO printinfo;
47 static UX_PICTBRIDGE_JOBINFO *jobinfo;
48 static UX_SLAVE_CLASS_PIMA_OBJECT *object;
49 static TX_SEMAPHORE print_semaphore;
50 static ULONG pictbridge_device_copy_count = 0;
51
52 static UX_HOST_CLASS_PIMA *pima_host;
53 static UX_PICTBRIDGE pictbridge_host;
54 static ULONG pictbridge_host_copy_count = 0;
55 static TX_SEMAPHORE wait_semaphore;
56
57 static ULONG error_counter;
58
59 static ULONG set_cfg_counter;
60
61 static ULONG rsc_mem_free_on_set_cfg;
62 static ULONG rsc_sem_on_set_cfg;
63 static ULONG rsc_sem_get_on_set_cfg;
64 static ULONG rsc_mutex_on_set_cfg;
65
66 static ULONG rsc_enum_sem_usage;
67 static ULONG rsc_enum_sem_get_count;
68 static ULONG rsc_enum_mutex_usage;
69 static ULONG rsc_enum_mem_usage;
70
71 static ULONG rsc_cdc_sem_usage;
72 static ULONG rsc_cdc_sem_get_count;
73 static ULONG rsc_cdc_mutex_usage;
74 static ULONG rsc_cdc_mem_usage;
75
76 static ULONG interaction_count;
77
78 static UCHAR error_callback_ignore = UX_TRUE;
79 static ULONG error_callback_counter;
80
81 /* Define device framework. */
82
83 UCHAR device_framework_full_speed[] = {
84
85 /* Device descriptor */
86 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08,
87 0xE8, 0x04, 0xC5, 0x68, 0x00, 0x00, 0x01, 0x02,
88 0x03, 0x01,
89
90 /* Configuration descriptor */
91 0x09, 0x02, 0x27, 0x00, 0x01, 0x01, 0x00, 0xc0,
92 0x32,
93
94 /* Interface descriptor */
95 0x09, 0x04, 0x00, 0x00, 0x03, 0x06, 0x01, 0x01,
96 0x00,
97
98 /* Endpoint descriptor (Bulk In) */
99 0x07, 0x05, 0x81, 0x02, 0x40, 0x00, 0x00,
100
101 /* Endpoint descriptor (Bulk Out) */
102 0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00,
103
104 /* Endpoint descriptor (Interrupt In) */
105 0x07, 0x05, 0x83, 0x03, 0x40, 0x00, 0x04
106 };
107 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED sizeof(device_framework_full_speed)
108
109 UCHAR device_framework_high_speed[] = {
110
111 /* Device descriptor */
112 0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
113 0xE8, 0x04, 0xC5, 0x68, 0x01, 0x00, 0x01, 0x02,
114 0x03, 0x01,
115
116 /* Device qualifier descriptor */
117 0x0a, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
118 0x01, 0x00,
119
120 /* Configuration descriptor */
121 0x09, 0x02, 0x27, 0x00, 0x01, 0x01, 0x00, 0xc0,
122 0x32,
123
124 /* Interface descriptor */
125 0x09, 0x04, 0x00, 0x00, 0x03, 0x06, 0x01, 0x01,
126 0x00,
127
128 /* Endpoint descriptor (Bulk In) */
129 0x07, 0x05, 0x81, 0x02, 0x00, 0x02, 0x00,
130
131 /* Endpoint descriptor (Bulk Out) */
132 0x07, 0x05, 0x02, 0x02, 0x00, 0x02, 0x00,
133
134 /* Endpoint descriptor (Interrupt In) */
135 0x07, 0x05, 0x83, 0x03, 0x40, 0x00, 0x04
136 };
137 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED sizeof(device_framework_high_speed)
138
139 /* String Device Framework :
140 Byte 0 and 1 : Word containing the language ID : 0x0904 for US or 0x0000 for none.
141 Byte 2 : Byte containing the index of the descriptor
142 Byte 3 : Byte containing the length of the descriptor string
143
144 The last string entry can be the optional Microsoft String descriptor.
145 */
146 UCHAR string_framework[] = {
147
148 /* Manufacturer string descriptor : Index 1 */
149 0x09, 0x04, 0x01, 0x0c,
150 0x45, 0x78, 0x70, 0x72, 0x65, 0x73, 0x20, 0x4c,
151 0x6f, 0x67, 0x69, 0x63,
152
153 /* Product string descriptor : Index 2 */
154 0x09, 0x04, 0x02, 0x0a,
155 0x4d, 0x54, 0x50, 0x20, 0x70, 0x6c, 0x61, 0x79,
156 0x65, 0x72,
157
158 /* Serial Number string descriptor : Index 3 */
159 0x09, 0x04, 0x03, 0x04,
160 0x30, 0x30, 0x30, 0x31,
161
162 };
163 #define STRING_FRAMEWORK_LENGTH sizeof(string_framework)
164
165 /* Multiple languages are supported on the device, to add
166 a language besides english, the unicode language code must
167 be appended to the language_id_framework array and the length
168 adjusted accordingly. */
169 UCHAR language_id_framework[] = {
170
171 /* English. */
172 0x09, 0x04
173 };
174 #define LANGUAGE_ID_FRAMEWORK_LENGTH sizeof(language_id_framework)
175
176 /* Pima device info manufacture string (Unicode). */
177 UCHAR string_pima_manufacturer[] =
178 {
179 0x0C,
180 0x45, 0x00, 0x78, 0x00, 0x70, 0x00, 0x72, 0x00,
181 0x65, 0x00, 0x73, 0x00, 0x20, 0x00, 0x4c, 0x00,
182 0x6f, 0x00, 0x67, 0x00, 0x69, 0x00, 0x63, 0x00
183 };
184
185 /* Pima device info Model string (Unicode). */
186 UCHAR string_pima_model[] =
187 {
188 0x0C,
189 0x50, 0x00, 0x69, 0x00, 0x6D, 0x00, 0x61, 0x00,
190 0x20, 0x00, 0x43, 0x00, 0x61, 0x00, 0x6D, 0x00,
191 0x65, 0x00, 0x72, 0x00, 0x61, 0x00, 0x20, 0x00
192 };
193
194 /* Pima device info Device version (Unicode). */
195 UCHAR string_pima_device_version[] =
196 {
197 0x04,
198 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x31, 0x00
199 };
200
201 /* Pima device info Device serial number (Unicode). */
202 UCHAR string_pima_serial_number[] =
203 {
204 0x04,
205 0x30, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00
206 };
207
208 UCHAR string_pima_storage_description[] =
209 {
210 0x0b,
211 0x56, 0x00, 0x69, 0x00, 0x72, 0x00, 0x74, 0x00,
212 0x75, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00,
213 0x44, 0x00, 0x69, 0x00, 0x73, 0x00, 0x6b, 0x00
214 };
215
216 UCHAR string_pima_storage_volume_label[] =
217 {
218 0x09,
219 0x4d, 0x00, 0x79, 0x00, 0x20, 0x00, 0x56, 0x00,
220 0x6f, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x6d, 0x00,
221 0x65, 0x00
222 };
223
224 /* Prototype for test control return. */
225
226 void test_control_return(UINT status);
227
error_callback(UINT system_level,UINT system_context,UINT error_code)228 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
229 {
230
231 error_callback_counter ++;
232
233 if (!error_callback_ignore)
234 {
235 {
236 /* Failed test. */
237 printf("Error #%d, system_level: %d, system_context: %d, error_code: 0x%x\n", __LINE__, system_level, system_context, error_code);
238 test_control_return(1);
239 }
240 }
241 }
242
sleep_break_on_error(VOID)243 static UINT sleep_break_on_error(VOID)
244 {
245
246 if (error_callback_counter >= 3)
247 return error_callback_counter;
248
249 return UX_SUCCESS;
250 }
251
252 /* Define the ISR dispatch routine. */
253
test_isr(void)254 static void test_isr(void)
255 {
256
257 /* For further expansion of interrupt-level testing. */
258 }
259
260
261
test_system_host_change_function(ULONG event,UX_HOST_CLASS * cls,VOID * inst)262 static UINT test_system_host_change_function(ULONG event, UX_HOST_CLASS *cls, VOID *inst)
263 {
264 // printf("hChg:%lx, %p, %p\n", event, cls, inst);
265 switch(event)
266 {
267 case UX_DEVICE_INSERTION:
268 if (cls->ux_host_class_entry_function == ux_host_class_pima_entry)
269 {
270 pima_host = (UX_HOST_CLASS_PIMA *)inst;
271 }
272 break;
273
274 case UX_DEVICE_REMOVAL:
275 if (cls->ux_host_class_entry_function == ux_host_class_pima_entry)
276 {
277 if ((VOID*)pima_host == inst)
278 pima_host = UX_NULL;
279 }
280 break;
281
282 default:
283 break;
284 }
285 return 0;
286 }
287
test_pima_instance_activate(VOID * instance)288 static VOID test_pima_instance_activate(VOID *instance)
289 {
290 pima_device = (UX_SLAVE_CLASS_PIMA_DEVICE *)instance;
291 }
test_pima_instance_deactivate(VOID * instance)292 static VOID test_pima_instance_deactivate(VOID *instance)
293 {
294 if ((VOID *)pima_device == instance)
295 pima_device = UX_NULL;
296 }
297
298
299 /* Define what the initial system looks like. */
300
301 #ifdef CTEST
test_application_define(void * first_unused_memory)302 void test_application_define(void *first_unused_memory)
303 #else
304 void usbx_pictbridge_basic_test_application_define(void *first_unused_memory)
305 #endif
306 {
307
308 UINT status;
309 CHAR * stack_pointer;
310 CHAR * memory_pointer;
311 ULONG test_n;
312
313 /* Inform user. */
314 printf("Running Pictbridge Basic Functionality Test......................... ");
315
316 /* Reset testing counts. */
317 ux_test_utility_sim_mutex_create_count_reset();
318 ux_test_utility_sim_sem_create_count_reset();
319 ux_test_utility_sim_sem_get_count_reset();
320 /* Reset error generations */
321 ux_test_utility_sim_sem_error_generation_stop();
322 ux_test_utility_sim_mutex_error_generation_stop();
323 ux_test_utility_sim_sem_get_error_generation_stop();
324
325 /* Initialize the free memory pointer */
326 stack_pointer = (CHAR *) usbx_memory;
327 memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
328
329 /* Initialize USBX Memory */
330 status = ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL,0);
331 UX_TEST_CHECK_SUCCESS(status);
332
333 /* Register the error callback. */
334 _ux_utility_error_callback_register(error_callback);
335
336 /* The code below is required for installing the host portion of USBX */
337 status = ux_host_stack_initialize(test_system_host_change_function);
338 UX_TEST_CHECK_SUCCESS(status);
339
340 /* Register PIMA class. */
341 status = ux_host_stack_class_register(_ux_system_host_class_pima_name, ux_host_class_pima_entry);
342 UX_TEST_CHECK_SUCCESS(status);
343
344 /* The code below is required for installing the device portion of USBX. No call back for
345 device status change in this example. */
346 status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
347 device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
348 string_framework, STRING_FRAMEWORK_LENGTH,
349 language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
350 UX_TEST_CHECK_SUCCESS(status);
351
352 /* Initialize the Pictbridge string components. */
353 ux_utility_memory_copy(pictbridge_device.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_vendor_name, "ExpressLogic",13);
354 ux_utility_memory_copy(pictbridge_device.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_product_name, "EL_Pictbridge_Camera",21);
355 ux_utility_memory_copy(pictbridge_device.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_serial_no, "ABC_123",7);
356 ux_utility_memory_copy(pictbridge_device.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_dpsversions, "1.0 1.1",7);
357 pictbridge_device.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_vendor_specific_version = 0x0100;
358
359 pictbridge_device.ux_pictbridge_pima_parameter.ux_device_class_pima_instance_activate = test_pima_instance_activate;
360 pictbridge_device.ux_pictbridge_pima_parameter.ux_device_class_pima_instance_deactivate = test_pima_instance_deactivate;
361
362 pictbridge_device.ux_pictbridge_pima_parameter.ux_device_class_pima_parameter_device_version = "0.0";
363
364 /* Start the Pictbridge client. */
365 status = ux_pictbridge_dpsclient_start(&pictbridge_device);
366 UX_TEST_CHECK_SUCCESS(status);
367
368 /* Initialize the simulated device controller. */
369 status = _ux_dcd_sim_slave_initialize();
370 if (status != UX_SUCCESS)
371 {
372 printf("ERROR #%d\n", __LINE__);
373 test_control_return(1);
374 }
375
376 /* Register all the USB host controllers available in this system */
377 status = ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize,0,0);
378 UX_TEST_CHECK_SUCCESS(status);
379
380 /* Create a semaphore for the demo. */
381 status = tx_semaphore_create(&wait_semaphore,"Wait Semaphore", 0);
382 UX_TEST_CHECK_SUCCESS(status);
383
384 /* Create the main host simulation thread. */
385 status = tx_thread_create(&test_thread_host_simulation, "tx demo host simulation", test_thread_host_simulation_entry, 0,
386 stack_pointer, UX_TEST_STACK_SIZE,
387 20, 20, 1, TX_AUTO_START);
388 UX_TEST_CHECK_SUCCESS(status);
389
390 /* Create the main slave simulation thread. */
391 status = tx_thread_create(&test_thread_device_simulation, "tx demo device simulation", test_thread_device_simulation_entry, 0,
392 stack_pointer + UX_TEST_STACK_SIZE, UX_TEST_STACK_SIZE,
393 20, 20, 1, TX_AUTO_START);
394 UX_TEST_CHECK_SUCCESS(status);
395 }
396
397 /* Copy the object data. */
test_pictbridge_host_object_data_write(UX_PICTBRIDGE * pictbridge,UCHAR * object_buffer,ULONG offset,ULONG total_length,ULONG length)398 static UINT test_pictbridge_host_object_data_write(UX_PICTBRIDGE *pictbridge,UCHAR *object_buffer, ULONG offset, ULONG total_length, ULONG length)
399 {
400 pictbridge_host_copy_count ++;
401
402 /* We have copied the requested data. Return OK. */
403 return(UX_SUCCESS);
404
405 }
406
test_thread_host_simulation_entry(ULONG arg)407 void test_thread_host_simulation_entry(ULONG arg)
408 {
409
410 UINT status;
411 INT i;
412
413 for (i = 0; i < 100; i ++)
414 {
415 if (pima_host && pima_device)
416 break;
417 ux_utility_delay_ms(1);
418 }
419 if (pima_host == UX_NULL || pima_device == UX_NULL)
420 {
421 printf("ERROR #%d\n", __LINE__);
422 test_control_return(1);
423 }
424
425 /* Initialize the dpshost structure with the printer vendor info. */
426 ux_utility_memory_copy(pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_vendor_name, "ExpressLogic",13);
427 ux_utility_memory_copy(pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_product_name, "EL_Pictbridge_Printer",21);
428 ux_utility_memory_copy(pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_serial_no, "ABC_123",7);
429
430 /* Set supported versions. */
431 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_dpsversions[0] = 0x00010000;
432 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_dpsversions[1] = 0x00010001;
433 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_dpsversions[2] = 0;
434 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_vendor_specific_version = 0x00010000;
435
436 /* Set print services to TRUE. */
437 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_print_service_available = 0x30010000;
438
439 /* Set Qualities. */
440 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_qualities[0] = UX_PICTBRIDGE_QUALITIES_DEFAULT;
441 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_qualities[1] = UX_PICTBRIDGE_QUALITIES_NORMAL;
442 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_qualities[2] = UX_PICTBRIDGE_QUALITIES_DRAFT;
443 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_qualities[3] = UX_PICTBRIDGE_QUALITIES_FINE;
444 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_qualities[4] = 0;
445
446 /* Set Paper Sizes. */
447 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papersizes[0] = UX_PICTBRIDGE_PAPER_SIZES_DEFAULT;
448 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papersizes[1] = UX_PICTBRIDGE_PAPER_SIZES_4IX6I;
449 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papersizes[2] = UX_PICTBRIDGE_PAPER_SIZES_L;
450 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papersizes[3] = UX_PICTBRIDGE_PAPER_SIZES_2L;
451 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papersizes[4] = UX_PICTBRIDGE_PAPER_SIZES_LETTER;
452 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papersizes[5] = 0;
453
454 /* Set Paper Types. */
455 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papertypes[0] = UX_PICTBRIDGE_PAPER_TYPES_DEFAULT;
456 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papertypes[1] = UX_PICTBRIDGE_PAPER_TYPES_PLAIN;
457 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papertypes[2] = UX_PICTBRIDGE_PAPER_TYPES_PHOTO;
458 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papertypes[3] = 0;
459
460 /* Set File Types. */
461 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_filetypes[0] = UX_PICTBRIDGE_FILE_TYPES_DEFAULT;
462 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_filetypes[1] = UX_PICTBRIDGE_FILE_TYPES_EXIF_JPEG;
463 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_filetypes[2] = UX_PICTBRIDGE_FILE_TYPES_JFIF;
464 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_filetypes[3] = UX_PICTBRIDGE_FILE_TYPES_DPOF;
465 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_filetypes[4] = 0;
466
467 /* Set Date Prints. */
468 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_dateprints[0] = UX_PICTBRIDGE_DATE_PRINTS_DEFAULT;
469 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_dateprints[1] = UX_PICTBRIDGE_DATE_PRINTS_OFF;
470 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_dateprints[2] = UX_PICTBRIDGE_DATE_PRINTS_ON;
471 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_dateprints[3] = 0;
472
473 /* Set File Name Prints. */
474 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_filenameprints[0] = UX_PICTBRIDGE_FILE_NAME_PRINTS_DEFAULT;
475 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_filenameprints[1] = UX_PICTBRIDGE_FILE_NAME_PRINTS_OFF;
476 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_filenameprints[2] = UX_PICTBRIDGE_FILE_NAME_PRINTS_ON;
477 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_filenameprints[3] = 0;
478
479 /* Set Image optimizes. */
480 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_imageoptimizes[0] = UX_PICTBRIDGE_IMAGE_OPTIMIZES_DEFAULT;
481 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_imageoptimizes[1] = UX_PICTBRIDGE_IMAGE_OPTIMIZES_OFF;
482 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_imageoptimizes[2] = UX_PICTBRIDGE_IMAGE_OPTIMIZES_ON;
483 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_imageoptimizes[3] = 0;
484
485 /* Set Layouts. */
486 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_layouts[0] = UX_PICTBRIDGE_LAYOUTS_DEFAULT;
487 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_layouts[1] = UX_PICTBRIDGE_LAYOUTS_1_UP_BORDER;
488 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_layouts[2] = UX_PICTBRIDGE_LAYOUTS_INDEX_PRINT;
489 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_layouts[3] = UX_PICTBRIDGE_LAYOUTS_1_UP_BORDERLESS;
490 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_layouts[4] = 0;
491
492 /* Set Fixed Sizes. */
493 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_fixedsizes[0] = UX_PICTBRIDGE_FIXED_SIZE_DEFAULT;
494 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_fixedsizes[1] = UX_PICTBRIDGE_FIXED_SIZE_35IX5I;
495 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_fixedsizes[2] = UX_PICTBRIDGE_FIXED_SIZE_4IX6I;
496 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_fixedsizes[3] = UX_PICTBRIDGE_FIXED_SIZE_5IX7I;
497 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_fixedsizes[4] = UX_PICTBRIDGE_FIXED_SIZE_7CMX10CM;
498 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_fixedsizes[5] = UX_PICTBRIDGE_FIXED_SIZE_LETTER;
499 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_fixedsizes[6] = UX_PICTBRIDGE_FIXED_SIZE_A4;
500 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_fixedsizes[7] = 0;
501
502 /* Set croppings. */
503 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_croppings[0] = UX_PICTBRIDGE_CROPPINGS_DEFAULT;
504 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_croppings[1] = UX_PICTBRIDGE_CROPPINGS_OFF;
505 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_croppings[2] = UX_PICTBRIDGE_CROPPINGS_ON;
506 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_croppings[3] = 0;
507
508 /* Set Print Service Status to idle. */
509 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_dpsprintservicestatus = UX_PICTBRIDGE_DPS_PRINTSERVICE_STATUS_IDLE;
510
511 /* Set Job End Reason. */
512 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_jobendreason = UX_PICTBRIDGE_JOB_END_REASON_NOT_ENDED;
513
514 /* Set Error Status. */
515 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_errorstatus = UX_PICTBRIDGE_ERROR_STATUS_NO_ERROR;
516
517 /* Set Error Reason. */
518 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_errorreason = UX_PICTBRIDGE_ERROR_REASON_NO_REASON;
519
520 /* Set Disconnection Enable. */
521 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_disconnectenable = UX_PICTBRIDGE_DISCONNECT_ENABLE_TRUE;
522
523 /* Set Capability Changed. */
524 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_capabilitychanged = UX_PICTBRIDGE_CAPABILITY_CHANGED_FALSE;
525
526 /* Set New Job OK. */
527 pictbridge_host.ux_pictbridge_dpslocal.ux_pictbridge_devinfo_newjobok = UX_PICTBRIDGE_NEW_JOB_TRUE;
528
529 /* Set a callback when an object is being received. */
530 pictbridge_host.ux_pictbridge_application_object_data_write = test_pictbridge_host_object_data_write;
531
532 /* Activate the pictbridge dpshost. */
533 status = _ux_pictbridge_dpshost_start(&pictbridge_host, pima_host);
534 UX_TEST_CHECK_SUCCESS(status);
535
536 status = tx_semaphore_get(&wait_semaphore, 30000);
537 UX_TEST_CHECK_SUCCESS(status);
538 tx_thread_sleep(5);
539
540 stepinfo(">>>>>>>>>>>> All Done\n");
541
542 /* Finally disconnect the device. */
543 ux_device_stack_disconnect();
544
545 /* And deinitialize the class. */
546 status = ux_device_stack_class_unregister(_ux_system_slave_class_pima_name, ux_device_class_pima_entry);
547
548 /* Deinitialize the device side of usbx. */
549 _ux_device_stack_uninitialize();
550
551 /* And finally the usbx system resources. */
552 _ux_system_uninitialize();
553
554 /* Successful test. */
555 printf("SUCCESS!\n");
556 test_control_return(0);
557
558 }
559
test_pictbridge_device_object_data_copy(UX_PICTBRIDGE * pictbridge,ULONG object_handle,UCHAR * object_buffer,ULONG object_offset,ULONG object_length,ULONG * actual_length)560 static UINT test_pictbridge_device_object_data_copy(UX_PICTBRIDGE *pictbridge, ULONG object_handle, UCHAR *object_buffer, ULONG object_offset, ULONG object_length, ULONG *actual_length)
561 {
562 pictbridge_device_copy_count ++;
563
564 /* Copy the demanded object data portion. */
565 ux_utility_memory_copy(object_buffer, ux_test_jpeg_image + object_offset, object_length);
566
567 /* Update the actual length. */
568 *actual_length = object_length;
569
570 /* We have copied the requested data. Return OK. */
571 return(UX_SUCCESS);
572
573 }
574
575
test_pictbridge_device_event_callback(struct UX_PICTBRIDGE_STRUCT * pictbridge,UINT event_flag)576 UINT test_pictbridge_device_event_callback(struct UX_PICTBRIDGE_STRUCT *pictbridge, UINT event_flag)
577 {
578
579 /* Check if we received NotifyDeviceStatus event. */
580 if (event_flag & UX_PICTBRIDGE_EVENT_FLAG_NOTIFY_DEVICE_STATUS)
581 {
582
583 /* Check if the printer can accept new job. */
584 if (pictbridge -> ux_pictbridge_dpsclient.ux_pictbridge_devinfo_newjobok == UX_PICTBRIDGE_NEW_JOB_TRUE)
585 {
586
587 /* Let the demo thread to send a new job. */
588 tx_semaphore_put(&print_semaphore);
589 }
590 }
591
592 return UX_SUCCESS;
593 }
594
595
test_thread_device_simulation_entry(ULONG arg)596 void test_thread_device_simulation_entry(ULONG arg)
597 {
598
599 UINT status;
600 ULONG actual_flags;
601
602 /* Create a semaphore for the demo. */
603 status = tx_semaphore_create(&print_semaphore,"Print Semaphore", 0);
604 UX_TEST_CHECK_SUCCESS(status);
605
606 while(1)
607 {
608
609 /* We should wait for the host and the client to discover one another. */
610 status = ux_utility_event_flags_get(&pictbridge_device.ux_pictbridge_event_flags_group, UX_PICTBRIDGE_EVENT_FLAG_DISCOVERY,
611 TX_AND_CLEAR, &actual_flags, UX_PICTBRIDGE_EVENT_TIMEOUT);
612
613 /* Check status. */
614 if (status == UX_SUCCESS)
615 {
616
617 /* Check if the pictbridge state machine has changed to discovery complete. */
618 if (pictbridge_device.ux_pictbridge_discovery_state == UX_PICTBRIDGE_DPSCLIENT_DISCOVERY_COMPLETE)
619 {
620
621 /* We can now communicate using XML scripts with the printer. First get information on capabilities. */
622 status = ux_pictbridge_dpsclient_api_configure_print_service(&pictbridge_device);
623 UX_TEST_CHECK_SUCCESS(status);
624
625 /* Check status. */
626 if (status == UX_SUCCESS)
627 {
628
629 /* Get the printer capabilities : Qualities. */
630 status = ux_pictbridge_dpsclient_api_capability(&pictbridge_device, UX_PICTBRIDGE_API_QUALITIES, 0);
631 UX_TEST_CHECK_SUCCESS(status);
632
633 /* Get the printer capabilities : PaperSizes. */
634 status = ux_pictbridge_dpsclient_api_capability(&pictbridge_device, UX_PICTBRIDGE_API_PAPER_SIZES, 0);
635 UX_TEST_CHECK_SUCCESS(status);
636
637 /* Get the printer capabilities : FileTypes. */
638 status = ux_pictbridge_dpsclient_api_capability(&pictbridge_device, UX_PICTBRIDGE_API_FILE_TYPES, 0);
639 UX_TEST_CHECK_SUCCESS(status);
640
641 /* Get the printer capabilities : DatePrints. */
642 status = ux_pictbridge_dpsclient_api_capability(&pictbridge_device, UX_PICTBRIDGE_API_DATE_PRINTS, 0);
643 UX_TEST_CHECK_SUCCESS(status);
644
645 /* Get the printer capabilities : FileNamePrints. */
646 status = ux_pictbridge_dpsclient_api_capability(&pictbridge_device, UX_PICTBRIDGE_API_FILE_NAME_PRINTS, 0);
647 UX_TEST_CHECK_SUCCESS(status);
648
649 /* Get the printer capabilities : ImageOptimizes. */
650 status = ux_pictbridge_dpsclient_api_capability(&pictbridge_device, UX_PICTBRIDGE_API_IMAGE_OPTIMIZES, 0);
651 UX_TEST_CHECK_SUCCESS(status);
652
653 /* Get the printer capabilities : Layouts. */
654 status = ux_pictbridge_dpsclient_api_capability(&pictbridge_device, UX_PICTBRIDGE_API_LAYOUTS, 0);
655 UX_TEST_CHECK_SUCCESS(status);
656
657 /* Get the printer capabilities : FixedSizes. */
658 status = ux_pictbridge_dpsclient_api_capability(&pictbridge_device, UX_PICTBRIDGE_API_FIXED_SIZES, 0);
659 UX_TEST_CHECK_SUCCESS(status);
660
661 /* Get the printer capabilities : Croppings. */
662 status = ux_pictbridge_dpsclient_api_capability(&pictbridge_device, UX_PICTBRIDGE_API_CROPPINGS, 0);
663 UX_TEST_CHECK_SUCCESS(status);
664
665 /* We have all the printer capabilities, get the device status. */
666 status = ux_pictbridge_dpsclient_api_device_status(&pictbridge_device);
667 UX_TEST_CHECK_SUCCESS(status);
668
669 /* Check status. */
670 if (status == UX_SUCCESS)
671 {
672
673 /* Check if the printer is ready for a pring job. */
674 if (pictbridge_device.ux_pictbridge_dpsclient.ux_pictbridge_devinfo_newjobok == UX_PICTBRIDGE_NEW_JOB_TRUE)
675 {
676
677 /* We can start a new job. Fill in the JobConfig and PrintInfo structures. */
678 jobinfo = &pictbridge_device.ux_pictbridge_jobinfo;
679
680 /* Attach a printinfo structure to the job. */
681 jobinfo -> ux_pictbridge_jobinfo_printinfo_start = &printinfo;
682
683
684 /* Set the default values for print job. */
685 jobinfo -> ux_pictbridge_jobinfo_quality = UX_PICTBRIDGE_QUALITIES_DEFAULT;
686 jobinfo -> ux_pictbridge_jobinfo_papersize = UX_PICTBRIDGE_PAPER_SIZES_DEFAULT;
687 jobinfo -> ux_pictbridge_jobinfo_papertype = UX_PICTBRIDGE_PAPER_TYPES_DEFAULT;
688 jobinfo -> ux_pictbridge_jobinfo_filetype = UX_PICTBRIDGE_FILE_TYPES_DEFAULT;
689 jobinfo -> ux_pictbridge_jobinfo_dateprint = UX_PICTBRIDGE_DATE_PRINTS_DEFAULT;
690 jobinfo -> ux_pictbridge_jobinfo_filenameprint = UX_PICTBRIDGE_FILE_NAME_PRINTS_DEFAULT;
691 jobinfo -> ux_pictbridge_jobinfo_imageoptimize = UX_PICTBRIDGE_IMAGE_OPTIMIZES_OFF;
692 jobinfo -> ux_pictbridge_jobinfo_layout = UX_PICTBRIDGE_LAYOUTS_DEFAULT;
693 jobinfo -> ux_pictbridge_jobinfo_fixedsize = UX_PICTBRIDGE_FIXED_SIZE_DEFAULT;
694 jobinfo -> ux_pictbridge_jobinfo_cropping = UX_PICTBRIDGE_CROPPINGS_DEFAULT;
695
696 /* Program the callback function for reading the object data. */
697 jobinfo -> ux_pictbridge_jobinfo_object_data_read = test_pictbridge_device_object_data_copy;
698
699 /* This is a demo, the fileID is hardwired (1 and 2 for scripts, 3 for photo to be printed. */
700 printinfo.ux_pictbridge_printinfo_fileid = UX_PICTBRIDGE_OBJECT_HANDLE_PRINT;
701 ux_utility_memory_copy(printinfo.ux_pictbridge_printinfo_filename, "Pictbridge demo file", 20);
702 ux_utility_memory_copy(printinfo.ux_pictbridge_printinfo_date, "01/01/2008", 10);
703
704 /* Fill in the object info to be printed. First get the pointer to the object container in the job info structure. */
705 object = (UX_SLAVE_CLASS_PIMA_OBJECT *) jobinfo -> ux_pictbridge_jobinfo_object;
706
707 /* Store the object format : JPEG picture. */
708 object -> ux_device_class_pima_object_format = UX_DEVICE_CLASS_PIMA_OFC_EXIF_JPEG;
709 object -> ux_device_class_pima_object_compressed_size = UX_TEST_JPEG_IMAGE_LENGTH;
710 object -> ux_device_class_pima_object_offset = 0;
711 object -> ux_device_class_pima_object_handle_id = UX_PICTBRIDGE_OBJECT_HANDLE_PRINT;
712 object -> ux_device_class_pima_object_length = UX_TEST_JPEG_IMAGE_LENGTH;
713
714 /* File name is in Unicode. */
715 ux_utility_string_to_unicode("JPEG Image", object -> ux_device_class_pima_object_filename);
716
717 /* And start the job. */
718 status = ux_pictbridge_dpsclient_api_start_job(&pictbridge_device);
719 UX_TEST_CHECK_SUCCESS(status);
720
721 /* Register the callback function to receive events from the printer. */
722 ux_pictbridge_dpsclient_register_event_callback_function(&pictbridge_device, test_pictbridge_device_event_callback);
723
724 /* Wait for the job to complete. */
725 status = tx_semaphore_get(&print_semaphore, 30000);
726 UX_TEST_CHECK_SUCCESS(status);
727
728 if (status == TX_SUCCESS)
729 {
730
731 /* Print the job again to demo the use of callback function. */
732 status = ux_pictbridge_dpsclient_api_start_job(&pictbridge_device);
733 UX_TEST_CHECK_SUCCESS(status);
734
735 /* Let host thread run to end. */
736 tx_semaphore_put(&wait_semaphore);
737 }
738
739 /* Unregister the callback function by passing a Null pointer. */
740 ux_pictbridge_dpsclient_register_event_callback_function(&pictbridge_device, UX_NULL);
741 }
742 }
743 }
744 }
745 }
746 }
747 }
748