-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_class.cpp
More file actions
109 lines (69 loc) · 1.92 KB
/
main_class.cpp
File metadata and controls
109 lines (69 loc) · 1.92 KB
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
#include "main_class.h"
#include "version.h"
#include "ipc.h"
#include <unistd.h>
CMain::CMain() {
}
CMain::~CMain() {
OscDestroy();
}
OSC_ERR CMain::Init(int argc, char ** argv) {
OSC_ERR err;
/******* Create the framework **********/
if((err=OscCreate(
&OscModule_log,
&OscModule_sup,
&OscModule_bmp,
&OscModule_cam,
&OscModule_vis,
&OscModule_gpio
))!=SUCCESS)
return(err);
OscLogSetConsoleLogLevel(INFO);
OscLogSetFileLogLevel(WARN);
OscGpioConfigSensorLedOut(true);
#if defined(OSC_HOST) || defined(OSC_SIM)
{
void * hFileNameReader;
if((err=OscFrdCreateConstantReader(&hFileNameReader, TEST_IMAGE_FN))!=SUCCESS)
return(err);
if((err=OscCamSetFileNameReader(hFileNameReader))!=SUCCESS)
return(err);
}
#endif /* OSC_HOST or OSC_SIM */
/* init the camera */
if((err=m_camera.Init(ROI(), 2))!=SUCCESS)
return(err);
m_camera.setAutoExposure(true);
char* osc_version;
OscGetVersionString(&osc_version);
string welcome_msg="### "APP_NAME" "+getAppVersion().toStr()+" OSCAR "+osc_version+" ###\n";
OscLog(INFO, welcome_msg.c_str());
return(SUCCESS);
}
OSC_ERR CMain::MainLoop() {
OSC_ERR err=SUCCESS;
CIPC ipc(m_camera);
err=ipc.Init();
OscSimInitialize();
/* read one image ahead */
m_camera.CapturePicture();
m_camera.ReadPicture();
uint32 startCyc=OscSupCycGet();
while(err==SUCCESS) { /* infinite loop if no error occurs */
err=ipc.handleIpcRequests();
/* Allow other processes to run. Due to kernel tick rate of 250Hz this
* call will return in 4ms. */
usleep(500);
/* Advance the simulation step counter. */
OscSimStep();
uint32 delta_time_us=OscSupCycToMicroSecs(OscSupCycGet() - startCyc);
if(delta_time_us/1000 > 1000) {
startCyc=OscSupCycGet();
if(ipc.img_count > 0)
printf("Sent %i images in %i ms\n", ipc.img_count, (int) delta_time_us/1000);
ipc.img_count=0;
}
}
return(err);
}