-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesg_sci_semb.c
More file actions
100 lines (92 loc) · 1.76 KB
/
mesg_sci_semb.c
File metadata and controls
100 lines (92 loc) · 1.76 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "mesg_sci_semb.h"
#include <string.h>
/**
* mesg_sci_sembを生成する
*/
mesg_sci_t* mesg_sci_create (void)
{
static mesg_sci_t self;
return &self;
}
/* 終了処理 */
void mesg_sci_delete (mesg_sci_t* self)
{
}
static char enc_buff[2048];
static char enc_size = 0;
/**
* @brief 受信処理
* @return 処理したmesgの数
*
* HOSからはポーリング処理される
*/
int
mesg_sci_recv (mesg_sci_t* self)
{
short mesg;
int numb = 0;
int i;
char menu[8];
#if 0
/* 文字の受信 */
for (;;) {
int c;
/* 受信文字なし */
if (uart1_getchar (&c) == 0) {
return numb;
}
if (c == '\n') {
break;
}
enc_buff[enc_size++] = c;
}
#endif
/* 文字の受信 */
for (;;) {
int c;
/* 受信文字なし */
while (uart1_getchar (&c) == 0) {
dly_tsk (1);
}
if (c == '\n') {
break;
}
enc_buff[enc_size++] = c;
}
/* BASE64デコード */
self->recv_size = base64_decode (self->recv_buff, enc_buff, enc_size);
enc_size = 0;
/* mesg番号 */
pack_load (self->recv_buff, "c8", menu);
/* 受信関数を呼び出し */
for (i=0; i<mesg_sci_menu_numb; i++) {
if (strcmp (mesg_sci_menu_vect[i].name, menu) == 0) {
mesg_sci_menu_vect[i].func (self);
}
}
numb ++;
return 0;
//}
}
/**
* @brief 送信処理
*
* どうするか?送り終わるまで待つのか?
*/
int mesg_sci_send (mesg_sci_t* self)
{
int size;
char buff[1000];
int i;
/* BASE64エンコード */
size = base64_encode (buff, self->send_buff, self->send_size);
/* 送信 */
for (i=0; i<size; i++) {
while( ( io_in16( UART_1LSR ) & 0x20 ) == 0 ) {
dly_tsk (1);
}
uart1_putchar (buff[i]);
}
uart1_putchar ('\n');
return size;
}