Robot Agent  1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
task_mission.c
Go to the documentation of this file.
1 
11 /* -- Includes -- */
12 /* system libraries */
13 
14 /* project libraries */
15 #include "task.h"
16 
20 void task_mission(void)
21 {
22  // Check if task is enabled
24  {
25  // -- Loacal variables --
26  int i, j;
27  void *data; // Void pointer for data
28  int data_type; // Data type
29  int stream_time, stream_time_reminder, stream_packet_count; // Stream time to be sent
30  int go_ahead_time; // Go ahead time passed
31  stream_t stream;
32 
33  // -- Check go ahead timer --
35  if(go_ahead_time > s_CONFIG_GO_AHEAD_TIME)
36  {
37  //g_go_ahead = 0;
38  }
39 
40  // -- Process all data in the queue --
41  while(g_queue_mission->count != 0)
42  {
43  // Allocate memory for data structure
45  {
46  // Victim information
48  data = (void *)malloc(sizeof(victim_t));
49  break;
50  // Command
52  data = (void *)malloc(sizeof(command_t));
53  break;
54  // Other
55  default :
56  // Do nothing
57  break;
58  }
59 
60  // Get data from the queue
61  queue_dequeue(g_queue_mission, data, &data_type);
62 
63  // Choose action depending on data type
64  switch(data_type)
65  {
66  // Victim information
68 
69  // Check if this victim is new
70  for(i = 0; i < g_task_mission_data.victim_count; i++)
71  {
72  // If there is victim with the same ID -> stop searching
73  if(strcmp(g_task_mission_data.victims[i].id, ((victim_t *)data)->id) == 0)
74  {
75  break;
76  }
77  }
78  // If counter is the same as victim count -> new victim is found
79  // Add it to the list
81  {
84  }
85 
86  break;
87  // Command
89 
90  // Choose action depending on command
91  switch(((command_t *)data)->cmd)
92  {
93  // Start tasks
94  case s_CMD_START :
102 
103  debug_printf("cmd start\n");
104 
105  break;
106  // Stop tasks
107  case s_CMD_STOP :
115 
116  debug_printf("cmd stop\n");
117 
118  // Get full control over robot
119  openinterface_drive(g_ois, 0, 0x8000);
120  break;
121  case s_CMD_GO_AHEAD :
122  // Go Ahead received
123  g_go_ahead = 1;
125  break;
126  // Other
127  default :
128  // Do nothing
129  break;
130  }
131 
132  break;
133  // Other
134  default :
135  // Do nothing
136  break;
137  }
138 
139  // Free memory
140  free(data);
141  }
142 
143  // -- Check pipe for event --
145  {
146 
147  // Check if this victim is new
148  for(i = 0; i < g_task_mission_data.victim_count; i++)
149  {
150  // If there is victim with the same ID -> stop searching
152  {
153  break;
154  }
155  }
156  // If counter is the same as victim count -> new victim is found
157  // Add it to the list
159  {
162  }
163 
164  // Reset event
166  }
167 
168  // -- Generate stream data --
169  // Get time for stream
171  stream_packet_count = (int)(stream_time / (1000 / (float)s_CONFIG_STREAM_RATE));
172 
173  //stream_time_reminder = (int)fmod(stream_time, (1000 / (float)s_CONFIG_STREAM_RATE)); // Calculate reminder not to loose miliseconds
174  //timelib_timer_add_ms(&g_task_mission_data.stream_timer, stream_time_reminder); // Add them back
175 
176  //debug_printf("STREAM: %d, %d\n", stream_time, stream_packet_count);
177 
178  // Generate and send stream
179  for(i = 0; i < stream_packet_count; i++)
180  {
182  stream.size = s_CONFIG_STREAM_SIZE;
183 
184  // Gnerate random data
185  for(j = 0; j < s_CONFIG_STREAM_SIZE; j++)
186  {
187  // For test copy just ones
188  stream.data[j] = 1;
189  }
190 
191  // Place data in a list
193  // Increment stream packet counter
195  }
196 
197  }
198 }
void debug_printf(const char *format,...)
Definition: debug.c:25
int size
Definition: def.h:51
#define s_CMD_START
Definition: def.h:75
queue_node_t * head
Definition: queue.h:36
task_t g_task_communicate
Definition: task.c:44
int enabled
Definition: task.h:46
#define s_CONFIG_STREAM_RATE
Definition: config.h:90
Stream structure.
Definition: def.h:48
int count
Definition: queue.h:39
doublylinkedlist_t * g_list_send
Definition: task.c:32
#define s_TASK_EVENT_SET
Definition: task.h:111
task_t g_task_report
Definition: task.c:43
Victim structure.
Definition: def.h:28
task_t g_task_control
Definition: task.c:41
double timelib_timer_get(struct timeval tv)
Definition: timelib.c:43
taskpipe_report_mission_t g_tp_report_mission
Definition: task.c:53
unsigned char data[s_CONFIG_STREAM_SIZE]
Definition: def.h:52
Command structure.
Definition: def.h:39
task_t g_task_mission
Definition: task.c:39
#define s_CMD_GO_AHEAD
Definition: def.h:77
int g_go_ahead
Definition: task.c:60
struct timeval go_ahead_timer
Definition: task.h:64
victim_t victims[s_CONFIG_VICTIM_MAX_COUNT]
Definition: task.h:57
double timelib_timer_reset(struct timeval *tv)
Definition: timelib.c:64
char id[11]
Definition: def.h:32
#define s_TASK_EVENT_RESET
Definition: task.h:112
task_mission_t g_task_mission_data
Definition: task.c:48
#define s_DATA_STRUCT_TYPE_STREAM
Definition: def.h:72
queue_t * g_queue_mission
Definition: task.c:35
#define s_CMD_STOP
Definition: def.h:76
#define s_CONFIG_GO_AHEAD_TIME
Definition: config.h:92
#define s_FALSE
Definition: def.h:61
int openinterface_drive(openinterface_t *ois, int velocity, int radius)
openinterface_t * g_ois
Definition: task.c:24
task_t g_task_refine
Definition: task.c:42
void doublylinkedlist_insert_end(doublylinkedlist_t *dlls, void *data, int data_type)
#define s_DATA_STRUCT_TYPE_CMD
Definition: def.h:71
long counter
Definition: def.h:50
task_t g_task_avoid
Definition: task.c:45
#define s_TRUE
Definition: def.h:60
void queue_dequeue(queue_t *qs, void *data, int *data_type)
Definition: queue.c:132
struct timeval stream_timer
Definition: task.h:61
task_t g_task_navigate
Definition: task.c:40
#define s_DATA_STRUCT_TYPE_VICTIM
Definition: def.h:69
#define s_CONFIG_STREAM_SIZE
Definition: config.h:89
void task_mission(void)
Definition: task_mission.c:20
long stream_counter
Definition: task.h:60