File: setSpeed.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 (56 lines) | stat: -rw-r--r-- 1,296 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
48
49
50
51
52
53
54
55
56
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>

#include "defs.h"
#include "setSpeed.h"
#include "transmission.h"
#include "error.h"

void qm100_setSpeed(int serialdev, int speed)
{
  qm100_packet_block packet;
  int reg;
  unsigned char cmd_speed[QM100_SPEED_LEN]=QM100_SPEED;
  unsigned char cmd_init[QM100_INIT_LEN]=QM100_INIT;

  newt.c_cflag |= CS8;
  newt.c_iflag &= ~(IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR);
  newt.c_iflag &= ~(IGNCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL);
  newt.c_oflag &= ~(OPOST);
  newt.c_lflag &= ~(ISIG|ICANON);
  newt.c_cflag &= ~(XCASE);
  newt.c_cc[VMIN] = 255;
  newt.c_cc[VTIME] = 5;

  switch (speed)
    {
    case B9600:
      reg = 0x020;
      break;
    case B19200:
      reg = 0x040;
      break;
    case B38400:
      reg = 0x080;
      break;
    case B57600:
      reg = 0x100;
      break;
    case B115200:
      reg = 0x200;
      break;
    }
  cmd_speed[4]=(reg & 0xff);
  cmd_speed[5]=((reg>>8) & 0xff);

  qm100_transmit(serialdev, cmd_speed, sizeof(cmd_speed));

  cfsetispeed(&newt, speed);
  cfsetospeed(&newt, speed);

  if (tcsetattr(serialdev, TCSANOW, &newt) < 0) qm100_error(serialdev, "Serial speed change problem");

  packet = qm100_transmit(serialdev, cmd_init, sizeof(cmd_init));
}