File: saveThumb.c

package info (click to toggle)
gphoto 0.3.5-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,636 kB
  • ctags: 1,973
  • sloc: ansic: 23,035; sh: 4,851; makefile: 175
file content (47 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "defs.h"
#include "transmission.h"
#include "saveThumb.h"

int qm100_saveThumb(int serialdev, char *filename, int pic)
{
  int jpgfile;
  char success=1;
  char cmd_getthumb[QM100_GETTHUMB_LEN]=QM100_GETTHUMB;
  qm100_packet_block packet;  

  cmd_getthumb[5] = (pic >> 8) & 0xff;
  cmd_getthumb[6] = (pic & 0xff);

  qm100_attention(serialdev);
  qm100_sendPacket(serialdev, cmd_getthumb, sizeof(cmd_getthumb));
  qm100_getAck(serialdev);
  packet = qm100_getPacket(serialdev);

  
  if (packet.packet_len == 4)
    {
      success = 0; /* No pic there! */
    }
  else
    {
      jpgfile = open(filename, O_RDWR|O_CREAT|O_EXCL, 0700);
      write(jpgfile, packet.packet, packet.packet_len);
      
      while (packet.transmission_continues)
      {
	qm100_continueTransmission(serialdev);
	packet = qm100_getPacket(serialdev);
	write(jpgfile, packet.packet, packet.packet_len);
      }
      close(jpgfile);     
    }
  qm100_endTransmit(serialdev);
  return success;
}