-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserIO.c
190 lines (151 loc) · 6.32 KB
/
UserIO.c
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <c8051F040.h> // declaratii SFR
#include <osc.h>
#include <Protocol.h>
#include <uart0.h>
#include <lcd.h>
#include <keyb.h>
#include <UserIO.h>
void Afisare_meniu(void); // afisare meniu initial
void Afisare_mesaj(void); // afisare mesaj receptionat
void Error(char *ptr); // afisare mesaj de eroare
unsigned char TERM_Input(void);
unsigned char AFISARE = 1;
extern unsigned char LCD_line,LCD_col;
//***********************************************************************************************************
extern unsigned char ADR_MASTER;
extern unsigned char TIP_NOD;
extern unsigned char STARE_IO;
extern nod retea[];
//***********************************************************************************************************
void UserIO(void){ // interfata cu utilizatorul
static unsigned char tasta, cmd, dest, lng; // variabile locale statice
if(0 == (tasta = TERM_Input())){
tasta = KEYB_Input();
if(tasta) LCD_Putch(tasta);
}
if(tasta){
switch(STARE_IO){
case 0: switch(tasta){
case '1': // s-a dat comanda de transmisie mesaj
// afiseaza Tx Msg:> Nod =
// blocheaza afisarea (AFISARE = 0)
// trece in starea 1
// comanda este '1'
break;
case '2': // s-a dat comanda de afisare Stare Nod:
// blocheaza afisarea (AFISARE = 0)
// trece in starea 1
// comanda este '2'
default: break;
}
break;
case 1: // s-a selectat nodul
// daca comanda e '1' si adresa e intre '0' - '4', mai putin adresa proprie
// extrage dest din tasta
// Daca este deja un mesaj in buffer ...
// afiseaza Buffer plin
// trece in starea 0, s-a terminat tratarea comenzii '1'
// afisare meniu
// altfel ...
// daca nodul e master
// pune in bufferul dest adresa hw dest egala cu dest
// altfel ...
// pune in bufferul dest adresa hw dest egala cu ADR_MASTER
// pune in bufferul dest adresa hw sursa egala cu ADR_NOD
// pune in bufferul dest adresa nodului sursa ADR_NOD
// pune in bufferul dest adresa nodului destinatie (dest)
// cere introducerea mesajului
// initializeaza lng = 0
// trece in starea 2, sa astepte caracterele mesajului
// daca comanda e '2' si adresa e intre '0'-'4'
// extrage dest din tasta
// Daca este deja un mesaj in buffer ...
// Afiseaza Buffer plin
// altfel
// Afiseaza Buffer gol
// trece in starea 0, s-a terminat tratarea comenzii
// afisare meniu
break;
case 2: // daca tasta e diferita de CR ('\r'), de NL ('\n') si de '*' si nu s-a ajuns la limita maxima a bufferului de caractere
// stocheaza codul tastei apasate in bufferul de date si incrementeaza lng
// daca s-a atins nr maxim de caractere sau s-a apasat Enter ('\r') sau ('\n') sau '*'
// stocheaza lng
// pune in bufbin tipul mesajului (USER_MES)
// marcheaza buffer plin
// trece in starea 0, s-a terminat tratarea comenzii
// afisare meniu
break;
}
}
}
//***********************************************************************************************************
void Afisare_meniu(void){ // afisare meniu initial
AFISARE = 1;
UART0_Putstr("\n\rTema ");
LCD_PutStr(0,0,"T");
UART0_Putch(TEMA + '0');
LCD_Putch(TEMA + '0');
#if(PROTOCOL == MS)
if(TIP_NOD == MASTER){
UART0_Putstr(" Master "); // daca programul se executa pe nodul master
LCD_PutStr(LCD_line, LCD_col, " Master:");
}
else{
UART0_Putstr(" Slave "); // daca programul se executa pe un nod slave
LCD_PutStr(LCD_line, LCD_col, " Slave:");
}
#elif(PROTOCOL == JT)
if(TIP_NOD == JETON){
UART0_Putstr(" Jeton ");
LCD_PutStr(LCD_line, LCD_col, " Jeton:");
}
else{
UART0_Putstr(" NoJet ");
LCD_PutStr(LCD_line, LCD_col, "NoJet:");
}
#endif
UART0_Putch(ADR_NOD + '0'); // afiseaza adresa nodului
LCD_Putch(ADR_NOD + '0');
#if(TEMA == 1 || TEMA == 3)
UART0_Putstr(":ASC" ); // afiseaza parametrii specifici temei
LCD_PutStr(LCD_line, LCD_col, " ASC");
#elif(TEMA == 2 || TEMA == 4)
UART0_Putstr(":BIN" );
LCD_PutStr(LCD_line, LCD_col, " BIN");
#endif
UART0_Putstr("\n\r> 1-TxM 2-Stare :>"); // meniul de comenzi
LCD_PutStr(1,0, "1-TxM 2-Stare :>");
}
//***********************************************************************************************************
void Afisare_mesaj(void){ // afisare mesaj din bufferul de receptie i
unsigned char j, lng, *ptr;
if(retea[ADR_NOD].full){ // exista mesaj in bufferul de receptie?
lng = retea[ADR_NOD].bufbin.lng;
UART0_Putstr("\n\r>Rx: De la nodul ");
LCD_DelLine(1);
LCD_PutStr(1,0, "Rx: ");
UART0_Putch(retea[ADR_NOD].bufbin.src + '0'); // afiseaza adresa nodului sursa al mesajului
LCD_Putch(retea[ADR_NOD].bufbin.src + '0');
UART0_Putstr(": ");
LCD_PutStr(LCD_line, LCD_col, ">: ");
for(j = 0, ptr = retea[ADR_NOD].bufbin.date; j < lng; j++) UART0_Putch(*ptr++); // afiseaza mesajul, caracter cu caracter
for(j = 0, ptr = retea[ADR_NOD].bufbin.date; j < lng; j++) LCD_Putch(*ptr++); // afiseaza mesajul, caracter cu caracter
retea[ADR_NOD].full = 0; // mesajul a fost afisat, marcheaza buffer gol
}
}
//***********************************************************************************************************
void Error(char *ptr){
if(AFISARE){
UART0_Putstr(ptr);
LCD_DelLine(1);
LCD_PutStr(1,0, ptr+2);
}
}
unsigned char TERM_Input(void){
unsigned char ch, SFRPAGE_save = SFRPAGE;
SFRPAGE = LEGACY_PAGE;
ch = 0;
if(RI0) ch = UART0_Getch(1);
SFRPAGE = SFRPAGE_save;
return ch;
}