-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_server.c
executable file
·73 lines (58 loc) · 1.95 KB
/
task_server.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
#include "task_server.h"
unsigned char ReportData[64];
unsigned char CommandData[50];
unsigned int CommandLength = 0 ;
unsigned char NextCharIn = 0;
unsigned long counter0;
unsigned long counter1;
unsigned long SystemTime;
extern void RightPWM(int pwmDuty, int threshold) ;
extern void LeftPWM(int pwmDuty, int threshold) ;
void procesCommand(void) ;
void sendReport(void) ;
void initTimer(void) ;
char c;
void Task_Server(void)
{
PORTB=0x55 ;
OS_Delay(2000) ; // modem has to init
initUSART();
OS_Delay(2000) ; // modem has to init
PORTB= 0 ;
//putStrUSART((char *)"reset\n") ; // RESET modem
OS_Delay(500) ; // modem has to init
CommandData[0] = 0;
NextCharIn = 0;
PORTB = 0 ;
while(1) {
int stuffed = 0; // Are we in a escape sequence?
NextCharIn = 0; //
while(1) {
OS_Wait(PIR1bits.RCIF);
c = RCREG ;
PIR1bits.RCIF = 0;
// if (stuffed == 0) {
// if (c == '\\') { // entered escape sequense stage
// stuffed = 1;
// continue;
// }
// stuffed = 0; // Only one byte escaped
if (c == 27) { // Recieved ascii ESC reset input buffer and start over
NextCharIn = 0;
continue;
}
if (c == 13 || c == 10) { // ascii NL or CR
CommandData[NextCharIn] = 0;
if (NextCharIn == 0) continue; // Recieved multiple NL or CR start over
else break; // we have a command break out while
}
// }
CommandData[NextCharIn++] = c;
// if (NextCharIn == 32) break; // Command should not be langer than 32 bytes
//PORTB = c ; // small debug on leds.
}
CommandLength = NextCharIn; // Can do without, make NextChar in the target
procesCommand();
// sendReport();
}
}