VAPS XT入门教程15.03:UserIntegration说明

系列索引:VAPS XT入门教程索引

上一篇:VAPS XT入门教程15.02.01:简单界面操作

I/O Buffer是VAPS XT程序标准的通信方式。自定义代码也可以用于通信,只是他们没有为外部特性设计的内置的特性。

为了使用程序和IO Buffer接收发送数据,你可以使用轮询(polling)或者为了更好的性能,使用回调或者其他方式来通知或者获取到通知数据的更新。这种方式叫做UserIntegration。

VAPS XT程序

首先创建一个根工程,叫做UA

根据工程自带的Float50,创建一个新数据结构Position。

数据结构为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE dataDescription>

<dataDescription name="Position">

<field>
<name>lat</name>
<type>float</type>
<cardinality>1</cardinality>
</field>
<field>
<name>alt</name>
<type>float</type>
<cardinality>1</cardinality>
</field>
<field>
<name>height</name>
<type>float</type>
<cardinality>1</cardinality>
</field>

</dataDescription>

此数据结构有三个值,每个都是float,表示一个位置的经纬高。

基于此数据结构创建发送接收Buffers

buffers

Buffer的名称为PositionBuf,记住这个名称,后面要用。

创建一个Format

format

在Format中添加文本框用于显示数据,在添加Buffer接收器。

添加事件处理

TriggerGuardAction
rcvPositionBuf.evUpdatedtextLatValue.DataString = rcvPositionBuf.Value.lat

如果Buffer接收器收到数据更新的信号,就把更新后的数据显示在文本框上。

编译程序,一定要生成*.lib文件。

VS程序

在VAPS XT安装文件夹C:\Presagis\VAPS_XT_4_1\src\Examples\UserIntegration目录下有C/CPP两个文件夹,这是VAPS XT提供的开发模板,本文是简单说明,所以使用比较简单的C版本。

把C文件夹复制到其他位置

vs

打开VS工程,

vs

接下来修改CSampleMain.c文件

GLOBAL CONSTANTS

先添加Buffer的名称

1
static const vxtChar VXT_BUFFER_NAME_POSITION[] = "PositionBuf";

名称要和上面设置的Buffer名称一样。

GLOBAL STRUCTURES

将dd数据结构改为C数据结构

1
2
3
4
5
typedef struct Position{
vxtFloat lat;
vxtFloat alt;
vxtFloat height;
}Position;

名称不重要,变量名不重要,主要的是类型要一样。

GLOBAL VARIABLES

新建一个结构体对象

1
Position *g_pPositin;

GLOBAL FUNCTIONS

回调函数1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void vPositionSendFunction
(
const vxtChar *a_pIOBufferName,
vxtRTIOBufferI *a_pIOBuffer
)
{
vxtUInt Size;
void *pBufferData = vxtRTCUI_pGetDataAddress(a_pIOBuffer, &Size);

//功能部分
int a = ((Position*)pBufferData)->lat;
if(a>=1000){
g_pPosition->lat=0;
}
}

非功能部分是固定的,功能部分比较简单,获取Buffer的数据,提取经纬高中的lat,如果值大于1000就置为0。

Buffer初始化函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void vInitIOBuffersFunction()
{
vxtUInt Size = 0;

/*
** Initialize the global pointers to buffers.
*/

g_pPosition = (Position*)(vxtRTCUI_pGetDataAddress(
vxtRTCUI_pGetIOBuffer(VXT_BUFFER_NAME_POSITION),&Size));

/*
** Initialize the callback functions
*/
vxtRTCUI_vSetDataSendHandler(vxtRTCUI_pGetIOBuffer(VXT_BUFFER_NAME_POSITION),
vPositionSendFunction);
}

先获取Buffer名所在的地址,然后设置此地址对应的回调函数。

VAPS XT一般的刷新频率为60hz,即每17ms刷新一次,刷新会调用update功能,在update之前的回调函数为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void vPreUpdateFunction
(
#if VXT_CFG_TIME_CRITICAL_OBJECTS_SUPPORT
vxtBool a_IsCriticalUpdate
#endif
)
{
#if VXT_CFG_TIME_CRITICAL_OBJECTS_SUPPORT
if(VXT_FALSE == a_IsCriticalUpdate)
#endif
{
g_pPosition->lat++;

vxtRTCUI_vNotifyDataUpdated(vxtRTCUI_pGetIOBuffer(VXT_BUFFER_NAME_POSITION));
}
}

每次刷新之前,将lat的值加1,然后调用函数通知程序数据已更新。

刷新之后的回调函数为

1
2
3
4
5
6
7
8
9
10
11
12
13
void vPostUpdateFunction
(
#if VXT_CFG_TIME_CRITICAL_OBJECTS_SUPPORT
vxtBool a_IsCriticalUpdate
#endif
)
{
#if VXT_CFG_TIME_CRITICAL_OBJECTS_SUPPORT
if(VXT_FALSE == a_IsCriticalUpdate)
#endif
{
}
}

不需要此功能,所以没有内容

错误处理回调函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
vxtBool HandleErrorFunction(vxtUInt a_ErrorCode,  const void* a_Data)
{
vxtChar Buff[255];
sprintf(Buff, "Handle error #%u with the following description:\n", a_ErrorCode);
fprintf(stderr, Buff);

/* The following error code is artificially injected to simulate a warning */
if (VXT_PL_GRAPHICS_ERROR == a_ErrorCode)
{
sprintf(Buff, "\nArtificially injected VXT_PL_GRAPHICS_ERROR error: error handled\n\n");
fprintf(stderr, Buff);

return VXT_TRUE;
}
else
{
return VXT_FALSE;
}
}

未修改

程序退出时回调函数

1
2
3
4
void vOnShutdownFunction()
{
printf("APPLICATION SHUTTING DOWN\n");
}

主函数

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
vxtInt main(vxtInt a_Argc, vxtChar *a_apArgv[])
{
vxtRTCUserIntegrationCallbacksI Callbacks = { 0 };
Callbacks.m_pfInitIOBuffersFunction = &vInitIOBuffersFunction;
Callbacks.m_pfPreUpdateFunction = &vPreUpdateFunction;
Callbacks.m_pfPostUpdateFunction = &vPostUpdateFunction;
Callbacks.m_pfOnShutdownFunction = &vOnShutdownFunction;

vxtRTCUI_vSetCallbacks(&Callbacks);

vxtRTCUI_vSetErrorHandler( &HandleErrorFunction
#if VXT_CFG_DBG_ERROR_MESSAGE_SUPPORT
, &vOutputMessageFunction
, &vEndMessageFunction
#endif
);

printf("APPLICATION STARTS\n");

{
/*
** Create an RT Options object to configure the user integration.
*/
vxtRTOptionsI *pRTOptions = vxtRTCUI_pCreateRTOptions();

vxtStatus UserCodeStatus = UserDefinedParseCommandLine(a_Argc, a_apArgv, pRTOptions);

if (VXT_SUCCESS == UserCodeStatus)
{

vxtRTCUI_vInitialize(pRTOptions);

if (!vxtRTCUI_HasError())
{

vxtRTCUI_vMainLoop();
}

vxtRTCUI_vShutdown();
}

/* Destroy the RT Options object */
vxtRTCUI_vDeleteRTOptions(&pRTOptions);
}

printf("APPLICATION ENDS\n");

return 0;
}

功能上就是设置回调函数。

测试

程序的功能就是:

  • 每次刷新屏幕前将lat加1
  • 将lat数值显示在VAPS XT的文本框中
  • 如果lat>=1000,就将lat置为0

编译程序,可以运行但是看不见任何东西。

我们到编译结果文件夹下执行

1
./CApplication.exe -center -width 800 -height 600

结果为

result

完整工程地址:VAPS_XT下的UA中

说明

  • 此操作基于VAPS XT nCom,那么就只支持Windows和Ubuntu
  • 可以在VS部分代码中实现数据获取解析等等复杂的功能
  • 如果VS编译debug模式,那么VAPS XT也应该编译debug模式,反之亦然

下一篇:VAPS XT入门教程15.04:CodedObject机制

技术交流群,欢迎加入讨论。这个圈子很小,大佬可能没兴趣加这些群聊社区之类的。所以只能带你入门,当然,欢迎大佬指导

qq 672991841


VAPS XT入门教程15.03:UserIntegration说明
https://feater.top/vapsxt/introduction-of-vapst-userintegration/
作者
JackeyLea
发布于
2021年10月27日
许可协议