1 /* picoproj - communication with AM7xxx based USB pico projectors
3 * Copyright (C) 2011 Antonio Ospite <ospite@studenti.unina.it>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 AM7x01_PACKET_TYPE_INIT = 0x01,
29 AM7x01_PACKET_TYPE_IMAGE = 0x02,
30 AM7x01_PACKET_TYPE_POWER = 0x04,
31 AM7x01_PACKET_TYPE_UNKNOWN = 0x05,
35 AM7x01_IMAGE_FORMAT_JPEG = 1,
36 } am7x01_image_format;
42 AM7x01_POWER_HIGH = 3,
59 * Examples of packet headers:
62 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
63 * +02|00|00|00|00|10|3e|10|01|00|00|00|20|03|00|00|e0|01|00|00|53|E8|00|00+
64 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
68 * +04|00|00|00|00|0c|ff|ff|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00+
69 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
72 static uint8_t reference_image_header[] = {
73 0x02, 0x00, 0x00, 0x00,
78 0x01, 0x00, 0x00, 0x00,
79 0x20, 0x03, 0x00, 0x00,
80 0xe0, 0x01, 0x00, 0x00,
81 0x53, 0xE8, 0x00, 0x00
91 struct image_header image;
92 struct power_header power;
97 static void dump_image_header(struct image_header *i)
102 printf("Image header:\n");
103 printf("format: 0x%08x (%u)\n", i->format, i->format);
104 printf("width: 0x%08x (%u)\n", i->width, i->width);
105 printf("height: 0x%08x (%u)\n", i->height, i->height);
106 printf("image size: 0x%08x (%u)\n", i->image_size, i->image_size);
109 static void dump_header(struct header *h)
114 printf("packet_type: 0x%08x (%u)\n", h->packet_type, h->packet_type);
115 printf("unknown0: 0x%02hhx (%hhu)\n", h->unknown0, h->unknown0);
116 printf("header_len: 0x%02hhx (%hhu)\n", h->header_len, h->header_len);
117 printf("unknown2: 0x%02hhx (%hhu)\n", h->unknown2, h->unknown2);
118 printf("unknown3: 0x%02hhx (%hhu)\n", h->unknown3, h->unknown3);
120 switch(h->packet_type) {
121 case AM7x01_PACKET_TYPE_IMAGE:
122 dump_image_header(&(h->header_data.image));
126 printf("Packet type not supported!\n");
133 static void dump_buffer(uint8_t *buffer, unsigned int len)
137 if (buffer == NULL || len == 0)
140 for (i = 0; i < len; i++) {
141 printf("%02hhX%c", buffer[i], (i < len - 1) ? ' ' : '\n');
146 static int send_data(uint8_t *buffer, unsigned int len)
148 dump_buffer(buffer, len);
152 static int send_header(struct header *h)
155 struct header header;
156 uint8_t buffer[sizeof (struct header)];
161 return send_data(data.buffer, sizeof (struct header));
164 static int send_image(am7x01_image_format format,
172 .packet_type = htole32(AM7x01_PACKET_TYPE_IMAGE),
174 .header_len = sizeof(struct image_header),
179 .format = htole32(format),
180 .width = htole32(width),
181 .height = htole32(height),
182 .image_size = htole32(size),
190 printf("Dump Buffers\n");
191 dump_buffer(reference_image_header, sizeof(struct header));
193 ret = send_header(&h);
197 if (image == NULL || size == 0)
200 return send_data(image, size);
203 static void usage(char *name)
205 printf("usage: %s [OPTIONS]\n\n", name);
206 printf("OPTIONS:\n");
207 printf("\t-f <filename>\t\tthe image file to upload\n");
208 printf("\t-F <format>\t\tthe image format to use (default is JPEG).\n");
209 printf("\t\t\t\tSUPPORTED FORMATS:\n");
210 printf("\t\t\t\t\t1 - JPEG\n");
211 printf("\t-W <image width>\tthe width of the image to upload\n");
212 printf("\t-H <image height>\tthe height of the image to upload\n");
213 printf("\t-h \t\t\tthis help message\n");
216 int main(int argc, char *argv[])
221 char filename[FILENAME_MAX] = {0};
222 int format = AM7x01_IMAGE_FORMAT_JPEG;
225 uint8_t *image = NULL;
228 while ((opt = getopt(argc, argv, "f:F:W:H:h")) != -1) {
231 strncpy(filename, optarg, FILENAME_MAX);
234 format = atoi(optarg);
236 fprintf(stderr, "Unsupported format\n");
241 width = atoi(optarg);
243 fprintf(stderr, "Unsupported width\n");
248 height = atoi(optarg);
250 fprintf(stderr, "Unsupported height\n");
260 ret = send_image(format, width, height, image, size);
262 perror("send_image");