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
|
/*
* c't-Sim - Robotersimulator fuer den c't-Bot
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your
* option) any later version.
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA.
*
*/
/*! @file bot-2-pc.c
* @brief Verbindung zwischen c't-Bot und PC
* @author Benjamin Benz (bbe@heise.de)
* @date 28.2.06
*/
#include "ct-Bot.h"
#include "command.h"
#include "uart.h"
#include "bot-2-pc.h"
#include "sensor.h"
#include "motor.h"
#include "led.h"
#include "mouse.h"
#include "log.h"
#include <stdlib.h>
#ifdef MCU
#ifdef BOT_2_PC_AVAILABLE
/*!
* Diese Funktion nimmt die Daten vom PC entgegen
* und wertet sie aus. dazu nutzt er die Funktion command_evaluate()
*/
void bot_2_pc_listen(void){
// LOG_DEBUG(("%d bytes recvd",uart_data_available()));
if (uart_data_available() >= sizeof(command_t)){
// LOG_DEBUG(("%d bytes recvd",uart_data_available()));
if (command_read() ==0){
LOG_DEBUG(("command received"));
command_evaluate();
}else {
// TODO Fehlerbehandlung
}
}
}
/*!
* Diese Funktion informiert den PC ueber alle Sensor und Aktuator-Werte
*/
void bot_2_pc_inform(void){
int16 value1, value2;
command_write(CMD_AKT_MOT, SUB_CMD_NORM ,(int16*)&speed_l,(int16*)&speed_r,0);
value1=(int16)led;
command_write(CMD_AKT_LED, SUB_CMD_NORM ,&value1,&value1,0);
command_write(CMD_SENS_IR, SUB_CMD_NORM ,(int16*)&sensDistL,(int16*)&sensDistR,0);
command_write(CMD_SENS_ENC, SUB_CMD_NORM ,(int16*)&sensEncL,(int16*)&sensEncR,0);
command_write(CMD_SENS_BORDER, SUB_CMD_NORM ,(int16*)&sensBorderL,(int16*)&sensBorderR,0);
command_write(CMD_SENS_LINE, SUB_CMD_NORM ,(int16*)&sensLineL,(int16*)&sensLineR,0);
command_write(CMD_SENS_LDR, SUB_CMD_NORM ,(int16*)&sensLDRL,(int16*)&sensLDRR,0);
value1= (int16) sensTrans; value2=0;
command_write(CMD_SENS_TRANS, SUB_CMD_NORM ,&value1,&value2,0);
value1= (int16) sensDoor;
command_write(CMD_SENS_DOOR, SUB_CMD_NORM ,&value1,&value2,0);
#ifdef MAUS_AVAILABLE
value1=(int16)sensMouseDX;
value2=(int16)sensMouseDY;
command_write(CMD_SENS_MOUSE, SUB_CMD_NORM ,&value1,&value2,0);
#endif
value1=(int16)sensError; value2=0;
command_write(CMD_SENS_ERROR, SUB_CMD_NORM ,&value1,&value2,0);
// command_write(CMD_SENS_RC5, SUB_CMD_NORM ,(int16*)&RC5_Code,&value2,0);
}
#include <stdio.h>
#include <string.h>
/*!
* Meldet den Bot am c't-Sim an
*/
void bot_2_pc_init(void){
int16 null =0;
uint8 j;
uart_init();
for(j=0;j<5;j++)
command_write(CMD_WELCOME, SUB_WELCOME_REAL ,&null,&null,0);
}
#endif
#endif
|