File: main.cc

package info (click to toggle)
libgnatcoll 1.7gpl2015-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,280 kB
  • ctags: 1,124
  • sloc: ada: 134,072; python: 4,017; cpp: 1,397; ansic: 1,234; makefile: 368; sh: 152; xml: 31; sql: 6
file content (425 lines) | stat: -rw-r--r-- 7,570 bytes parent folder | download | duplicates (2)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425



#define POSIX_SOURCE

#include "Cins.h"

#include "CGetParam.h"

#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <fstream>

#ifdef __cplusplus
#define EXT_C_DECL extern "C"
#else
#define  EXT_C_DECL
#endif

// cycle times in seconds for threads
#define C_INS_BITDATA_CYCLETIME  5
#define C_INS_READPOSITIONDATA_CYCLETIME 60
#define C_Max_Roll_Before_Out_Of_Level (1.0 * C_DEG_TO_RAD)

// define global variables that hold the local values

bool g_request_antenna_orientation=false;
bool g_request_new_antenna_orientation=false;
bool g_turn_antenna_to_orp=false;

bool g_override_ins=false;


bool g_insDruNeedsZeroVelocityUpdate=false;
bool g_insGetDruNeedsPositionUpdate=false;
bool g_insGetBitMalFunction=false;
bool g_insGetDruAlert=false;
bool g_insGetDruFailure=false;
bool g_insGetVmsFailure=false;
bool g_insGetVmsDriveFailure=false;

bool g_insLinkError=false;


float g_azim; //radians
float g_tilt; //radians
float g_roll; //radians

float g_vazim; //radians/s
float g_vtilt; //radians/s
float g_vroll; //radians/s


float g_new_azim; //radians
float g_new_tilt; //radians
float g_new_roll; //radians


float g_orp_azim=0.0; //radians
float g_orp_tilt=0.0; //radians


float g_conv_azim;
float g_conv_tilt;
float g_conv_new_azim;


char g_insdevice[30];


bool g_bStartINSPosThread=true;
bool g_bStartINSAttThread=true;
bool g_bStartINSBitThread=true;
bool g_bSendIPC=true;
bool g_bdelta_mode=false;
bool g_bRoll_ok=true;

bool g_bLogInsDataToFile=false;


// debug definitions
#define C_ECOM_COM 0
#define C_ECOM_PLUS 1
#define C_ECOM_20HZ_LOOP 2
#define C_ECOM_OVERRUN 3
#define C_INS 4
#define C_TTU 5
#define C_THREAD_STATE 6
#define C_HANGUP 7

bool trace_level[C_MAX_NO_OF_TRACE_LEVELS];
m_trace_levels_menu trace_menu;
int g_INSPositionData_State=0;
int g_INSBITStatusData_State=0;
int g_INSAttitudeData_State=0;

//File for logging of ant ori
ofstream logInsDataFile;


bool g_antInUprightPosition = false;


struct thread_data{
   void *alpha;
   void *bravo;
   void *charlie;
};



static int readmutex;

static int sendMessage_mutex;



EXT_C_DECL float convertAzim(float x, float x1)
{
  float retval;

  retval = x - x1;

  if (trace_level[C_ECOM_20HZ_LOOP])
      printf("main::convertAzim retval1=%f ", retval);

  if ((x1 >= 0.0) && (x1 <= C_PI)) {
    if (retval >  C_PI) retval=retval-C_TWO_PI;
  } else {
    if (retval < -C_PI) retval=retval+C_TWO_PI;
  }

  if (trace_level[C_ECOM_20HZ_LOOP])
      printf("- x=%f, x.orp=%f, retval2=%f\n", x, x1, retval);

  return retval;

}

EXT_C_DECL float convertTilt(float x)
{
  float retval;

  retval = C_PI_HALF - x;

  if (trace_level[C_ECOM_PLUS])
      printf("main::convertTilt x=%f, retval=%f\n", x, retval);

  return retval;

}





///////////////////////////////////////////
//
//   This thread ask INS for the status and
//
///////////////////////////////////////
EXT_C_DECL void *INSReadStatus(void *pvalue)
{
  Cins *pins;
  bool newVal;
  bool gotData;

  pins=(Cins *)pvalue;

  while(1)
    {
      g_INSBITStatusData_State = 1;

      if (trace_level[C_ECOM_COM] || trace_level[C_ECOM_PLUS])
	{
	  printf("main::Calling INS_GetBitData\n");
	}
      g_INSBITStatusData_State = 2;
      gotData = pins->INS_GetBitData();

      if (gotData)
        {
          g_INSBITStatusData_State = 3;
          newVal=pins->INS_GetDruNeedsZeroVelocityUpdate();

        }
      else
        {
          // Did not receive any attitude data
          if (trace_level[C_ECOM_PLUS])
            printf("Bit Data not found\n");

        }
    }
}




EXT_C_DECL void *INSPositionData(void *pvalue)
{

  Cins *pins;


  unsigned short int Spheroid=0;
  short int Hemisphere=0;
  unsigned int Easting=0;
  unsigned int Northing=0;
  short int Altitude=0;
  bool gotData;


  pins=(Cins *)pvalue;

  while(1)
    {
      g_INSPositionData_State = 1;

      if (trace_level[C_ECOM_COM] || trace_level[C_ECOM_PLUS])
	{
	  printf("main::Calling INS_GetPositionData\n");
	}
      g_INSPositionData_State = 2;
      gotData=pins->INS_GetPositionData(&Spheroid,&Hemisphere,&Easting,&Northing,&Altitude);

    }
}



EXT_C_DECL void *LoopData(void *threadarg)
{

  struct thread_data *my_data;

  my_data = (struct thread_data *) threadarg;

  void *temp_a, *temp_b, *temp_c;
  temp_a = my_data->alpha;
  temp_b = my_data->bravo;
  temp_c = my_data->charlie;

  int i=0;
  char *buf;

  int NumToDB=0;
  int NumToMTT=0;

  bool send_offset_msg = false;
  double delta_tetta;
  bool gotData;
  Cins *pins;

  double gotDataTime;

  pins=(Cins *)temp_a;



  // Goto decl/body works here
  pins->INS_SetDebug(trace_level[C_INS]);
  pins->INS_SetDebugHangup(trace_level[C_HANGUP]);


  while (1)
    {
      i++;
      if (i > 10000)
	{
	  i=0;
	}
      if (trace_level[C_ECOM_20HZ_LOOP])
	{
	  printf("INS loop tick %d\n",i);
	}

      g_INSAttitudeData_State = 1;


      g_INSAttitudeData_State = 2;

      // Goto decl/body doesn't work here
      gotData = pins->INS_GetPointingDeviceAttitudeData(&g_azim,&g_tilt,&g_roll);
      //gotData = pins-
    } //While(1)
}




EXT_C_DECL int main(void)
{

  int value;
  Cins* pins;


  /*pthread_t TTUReadCommandId;
  pthread_t ReadFromDPUId;
  pthread_t INSReadStatusId;
  pthread_t TTUSendStatusReqId;
  pthread_t INSPositionDataId;
  pthread_t LoopDataId;*/

  bool ttuComErrorReported=false;
  bool insComErrorReported=false;

  for(int i = 0; i < C_MAX_NO_OF_TRACE_LEVELS; i++)
    {
      trace_level[i]=false;
    }



  // initialize the mutexes
  /*pthread_mutex_init(&readmutex,NULL);
  pthread_mutex_init(&sendMessage_mutex, NULL);*/



  pins = new Cins(g_insdevice,false, &readmutex);

  thread_data Thread_data_main;

  Thread_data_main.alpha=pins;
  Thread_data_main.bravo=pins;
  Thread_data_main.charlie=pins;



  if(g_bStartINSBitThread)
    {
      //value=pthread_create(&INSReadStatusId,NULL,INSReadStatus,pins);
      if (value!=0) printf("main::Error in pthread_create INSReadStatus, value %d\n",value);
    }

  if(g_bStartINSPosThread)
    {
      //value=pthread_create(&INSPositionDataId,NULL,INSPositionData,pins);
      if (value!=0) printf("main::Error in pthread_create INSPositionData, value %d\n",value);
    }

  if(g_bStartINSAttThread)
    {
      //value=pthread_create(&LoopDataId,NULL,LoopData,(void *) &Thread_data_main);
      if (value!=0) printf("main::Error in pthread_create LoopData, value %d\n",value);
    }


  while (true) // loop forever
    {
      //sleep(1); // avoid high load

      int retval;
      m_ant_ttu_inactive tmp1;
      M_ANTENNA_IDENT tmp2;
      m_req_ant_position_status tmp3;
      m_ins_attitude_data tmp4;
      int rt, rp, ra;

      t_position_status tmp5;
      t_position_status tmp6 = raising_or_folding;
      m_ant_position_status tmp7;

      t_weapon_type w;

      CGetParam *myParam = new CGetParam("file.dat");


      myParam->GetString("GetString");

      myParam->GetString("GetString", false);

      retval = myParam->do_antenna(tmp1);

      retval = myParam->do_antenna(tmp2);

      retval = myParam->do_antenna(tmp3, rt, rp, ra);

      retval = myParam->do_antenna(tmp4);




      // Problems with Xref menu below
      // typedef struct
      tmp4.ant_ori.azim = 1;
      tmp4.time.min = 2;

      // typedef enum
      tmp5 = raising_or_folding;
      tmp7.position_status = tmp6;





      switch ( w.weapon_class )
	{
	  case tube       : break;
	  case rocket     : break;
	  case mortar     : break;
	  case small_arms : break;
	  case manual     : break;
	  default         : break;
	}











      delete myParam;


    }

}