serial.c 4.95 KB
Newer Older
1
#if (defined (__PO_HI_NEED_DRIVER_SERIAL_LINUX) || defined (__PO_HI_NEED_DRIVER_SERIAL_LINUX_RECEIVER) || defined (__PO_HI_NEED_DRIVER_SERIAL_LINUX_SENDER) || defined (__PO_HI_NEED_DRIVER_SERIAL_RASTA) || defined (__PO_HI_NEED_DRIVER_SERIAL_LEON) || defined (__PO_HI_NEED_DRIVER_SERIAL_LEON_SENDER) || defined (__PO_HI_NEED_DRIVER_SERIAL_LEON_RECEIVER))\n
2
3
4
/*
Code automatically generated by asn1scc tool
*/
yoogx's avatar
yoogx committed
5
#include <limits.h>
6
7
8
9
#include <string.h>
#include <math.h>


Maxime Perrotin's avatar
Maxime Perrotin committed
10
11
#include "serial.h"

yoogx's avatar
yoogx committed
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const __po_hi_c_serial_conf_t linux_ttyS0 = {
    .devname = "/dev/ttyS0",
    .speed = __po_hi_c_b38400,
    .exist = {
        .speed = 1,
        .parity = 0,
        .bits = 0,
        .sending_wait = 0,
        .use_paritybit = 0
    }
};
const __po_hi_c_serial_conf_t linux_ttyUSB0 = {
    .devname = "/dev/ttyUSB0",
    .speed = __po_hi_c_b38400,
    .exist = {
        .speed = 1,
        .parity = 0,
        .bits = 0,
        .sending_wait = 0,
        .use_paritybit = 0
    }
};
const __po_hi_c_serial_conf_t linux_ttyUSB1 = {
    .devname = "/dev/ttyUSB1",
    .speed = __po_hi_c_b38400,
    .exist = {
        .speed = 1,
        .parity = 0,
        .bits = 0,
        .sending_wait = 0,
        .use_paritybit = 0
    }
};
const __po_hi_c_serial_conf_t linux_ttyUSB2 = {
    .devname = "/dev/ttyUSB2",
    .speed = __po_hi_c_b38400,
    .exist = {
        .speed = 1,
        .parity = 0,
        .bits = 0,
        .sending_wait = 0,
        .use_paritybit = 0
    }
};
const __po_hi_c_serial_conf_t leon_rasta_apburasta0 = {
    .devname = "/dev/apburasta0",
    .speed = __po_hi_c_b38400,
    .exist = {
        .speed = 1,
        .parity = 0,
        .bits = 0,
        .sending_wait = 0,
        .use_paritybit = 0
    }
};
const __po_hi_c_serial_conf_t leon_rasta_apburasta1 = {
    .devname = "/dev/apburasta1",
    .speed = __po_hi_c_b38400,
    .exist = {
        .speed = 1,
        .parity = 0,
        .bits = 0,
        .sending_wait = 0,
        .use_paritybit = 0
    }
};
78
79
80
81


void __po_hi_c_Baudrate_T_Initialize(__po_hi_c_Baudrate_T* pVal)
{
Maxime Perrotin's avatar
Maxime Perrotin committed
82
83
	(void)pVal;

84
85
86
87
88
89
90

	(*(pVal)) = __po_hi_c_b9600;
}

flag __po_hi_c_Baudrate_T_IsConstraintValid(const __po_hi_c_Baudrate_T* pVal, int* pErrCode)
{
    flag ret = TRUE;
Maxime Perrotin's avatar
Maxime Perrotin committed
91
	(void)pVal;
92
93
	
    ret = ((((((((((((*(pVal)) == __po_hi_c_b9600)) || (((*(pVal)) == __po_hi_c_b19200)))) || (((*(pVal)) == __po_hi_c_b38400)))) || (((*(pVal)) == __po_hi_c_b57600)))) || (((*(pVal)) == __po_hi_c_b115200)))) || (((*(pVal)) == __po_hi_c_b230400)));
Maxime Perrotin's avatar
Maxime Perrotin committed
94
    *pErrCode = ret ? 0 :  ERR_BAUDRATE_T; 
95
96
97
98
99
100
101
102

	return ret;
}



void __po_hi_c_Parity_T_Initialize(__po_hi_c_Parity_T* pVal)
{
Maxime Perrotin's avatar
Maxime Perrotin committed
103
104
	(void)pVal;

105
106
107
108
109
110
111

	(*(pVal)) = __po_hi_c_even;
}

flag __po_hi_c_Parity_T_IsConstraintValid(const __po_hi_c_Parity_T* pVal, int* pErrCode)
{
    flag ret = TRUE;
Maxime Perrotin's avatar
Maxime Perrotin committed
112
	(void)pVal;
113
114
	
    ret = ((((*(pVal)) == __po_hi_c_even)) || (((*(pVal)) == __po_hi_c_odd)));
Maxime Perrotin's avatar
Maxime Perrotin committed
115
    *pErrCode = ret ? 0 :  ERR_PARITY_T; 
116
117
118
119
120
121
122
123

	return ret;
}



void __po_hi_c_serial_conf_t_devname_Initialize(__po_hi_c_serial_conf_t_devname val)
{
Maxime Perrotin's avatar
Maxime Perrotin committed
124
125
	(void)val;

126
127
128
129
130
131

	memset(val, 0x0, 21);

}
void __po_hi_c_serial_conf_t_bits_Initialize(__po_hi_c_serial_conf_t_bits* pVal)
{
Maxime Perrotin's avatar
Maxime Perrotin committed
132
133
	(void)pVal;

134
135
136
137
138

	(*(pVal)) = 7;
}
void __po_hi_c_serial_conf_t_sending_wait_Initialize(__po_hi_c_serial_conf_t_sending_wait* pVal)
{
Maxime Perrotin's avatar
Maxime Perrotin committed
139
140
	(void)pVal;

141
142
143
144
145

	(*(pVal)) = 0;
}
void __po_hi_c_serial_conf_t_Initialize(__po_hi_c_serial_conf_t* pVal)
{
Maxime Perrotin's avatar
Maxime Perrotin committed
146
147
	(void)pVal;

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168


	/*set devname */
	__po_hi_c_serial_conf_t_devname_Initialize(pVal->devname);
	/*set speed */
	pVal->exist.speed = 1;
	__po_hi_c_Baudrate_T_Initialize((&(pVal->speed)));
	/*set parity */
	pVal->exist.parity = 1;
	__po_hi_c_Parity_T_Initialize((&(pVal->parity)));
	/*set bits */
	pVal->exist.bits = 1;
	__po_hi_c_serial_conf_t_bits_Initialize((&(pVal->bits)));
	/*set sending_wait */
	pVal->exist.sending_wait = 1;
	__po_hi_c_serial_conf_t_sending_wait_Initialize((&(pVal->sending_wait)));
	/*set use_paritybit */
	pVal->exist.use_paritybit = 1;
	pVal->use_paritybit = FALSE;
}

Maxime Perrotin's avatar
Maxime Perrotin committed
169
flag __po_hi_c_serial_conf_t_IsConstraintValid(const __po_hi_c_serial_conf_t* pVal, int* pErrCode)
170
171
{
    flag ret = TRUE;
Maxime Perrotin's avatar
Maxime Perrotin committed
172
	(void)pVal;
173
174
	
    ret = ((1 <= strlen(pVal->devname)) && (strlen(pVal->devname) <= 20));
Maxime Perrotin's avatar
Maxime Perrotin committed
175
    *pErrCode = ret ? 0 :  ERR_SERIAL_CONF_T_DEVNAME; 
176
177
    if (ret) {
        if (pVal->exist.speed) {
178
        	ret = __po_hi_c_Baudrate_T_IsConstraintValid((&(pVal->speed)), pErrCode);
179
180
181
        }
        if (ret) {
            if (pVal->exist.parity) {
182
            	ret = __po_hi_c_Parity_T_IsConstraintValid((&(pVal->parity)), pErrCode);
183
184
185
186
            }
            if (ret) {
                if (pVal->exist.bits) {
                	ret = ((7UL <= pVal->bits) && (pVal->bits <= 8UL));
Maxime Perrotin's avatar
Maxime Perrotin committed
187
                	*pErrCode = ret ? 0 :  ERR_SERIAL_CONF_T_BITS; 
188
189
190
191
                }
                if (ret) {
                    if (pVal->exist.sending_wait) {
                    	ret = (pVal->sending_wait <= 9000000UL);
Maxime Perrotin's avatar
Maxime Perrotin committed
192
                    	*pErrCode = ret ? 0 :  ERR_SERIAL_CONF_T_SENDING_WAIT; 
193
194
195
196
197
198
199
200
201
                    }
                }
            }
        }
    }

	return ret;
}

202
\n#endif