View Javadoc
1   package net.sf.atmodem4j.spsw;
2   
3   /*
4    * #%L
5    * SPSW Java
6    * %%
7    * Copyright (C) 2009 - 2014 atmodem4j
8    * %%
9    * atmodem4j - A serial port socket wrapper- http://atmodem4j.sourceforge.net/
10   * Copyright (C) 2009-2014, atmodem4j.sf.net, and individual contributors as indicated
11   * by the @authors tag. See the copyright.txt in the distribution for a
12   * full listing of individual contributors.
13   * 
14   * This is free software; you can redistribute it and/or modify it
15   * under the terms of the GNU General Public License as
16   * published by the Free Software Foundation; either version 3 of
17   * the License, or (at your option) any later version.
18   * 
19   * This software is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22   * Lesser General Public License for more details.
23   * 
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this software; if not, write to the Free
26   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
28   * #L%
29   */
30  
31  /**
32   *
33   * @author aploese
34   */
35  public enum Baudrate {
36  
37              B0(0),
38              B50(50),
39              B75(75),
40              B110(110),
41              B134(134),
42              B150(150),
43              B200(200),
44              B300(300),
45              B600(600),
46              B1200(1200),
47              B1800(1800),
48              B2400(2400),
49              B4800(4800),
50              B9600(9600),
51              B19200(19200),
52              B38400(38400),
53              B57600(57600),
54              B115200(115200),
55              B230400(230400),
56              B460800(460800),
57              B500000(500000),
58              B576000(576000),
59              B921600(921600),
60              B1000000(1000000),
61              B1152000(1152000),
62              B1500000(1500000),
63              B2000000(2000000),
64              B2500000(2500000),
65              B3000000(3000000),
66              B3500000(3500000),
67              B4000000(4000000);
68  
69      public static Baudrate fromValue(int baudrate) {
70          return fromNative(baudrate);
71      }
72      
73      static Baudrate fromNative(int baudrate) {
74          switch (baudrate) {
75              case 0: return B0;
76              case 50: return B50;
77              case 75: return B75;
78              case 110: return B110;
79              case 134: return B134;
80              case 150: return B150;
81              case 200: return B200;
82              case 300: return B300;
83              case 600: return B600;
84              case 1200: return B1200;
85              case 1800: return B1800;
86              case 2400: return B2400;
87              case 4800: return B4800;
88              case 9600: return B9600;
89              case 19200: return B19200;
90              case 38400: return B38400;
91              case 57600: return B57600;
92              case 115200: return B115200;
93              case 230400: return B230400;
94              case 460800: return B460800;
95              case 500000: return B500000;
96              case 576000: return B576000;
97              case 921600: return B921600;
98              case 1000000: return B1000000;
99              case 1152000: return B1152000;
100             case 1500000: return B1500000;
101             case 2000000: return B2000000;
102             case 2500000: return B2500000;
103             case 3000000: return B3000000;
104             case 3500000: return B3500000;
105             case 4000000: return B4000000;
106                 default: throw new RuntimeException("Non standard baudrate " + baudrate);
107         }
108     }
109 
110 public final int value;
111 
112     private Baudrate(int baudrate) {
113         this.value = baudrate;
114     }
115     
116 }