HowTo: Create an Example using Microsoft Visual Studio
- Introduction
- 1. Download and Install the Apparatus Framework
- 2. Compile the Apparatus Framework Library
- 3. Create Files
- 4. Create a Visual Studio Project
- 5. Add the necessary files
- 6. Settings the include directory
- 7. Add the ApFw library
- 8. Compile it
Introduction
This page is a step by step guide to install, compile the Apparatus Framework and set up a demo project on Windows. All you need
to run the example is Visual Studio installed and the Apparatus Framework install file.
1. Download and Install the Apparatus Framework
Download the framework from this website, install it by running the msi. The installation is step by step documented in the (Documentation - Installation) section of this page.
2. Compile the Apparatus Framework Library
Open the Apparatus Framework Config tool in the start menu of Windows (Programs - bbv Apparatus Framework - Configuration Tool). Store a project file and name it EXAMPLE_PRJ.acc at some location like z:\EXAMPLE_PATH. Some changes are necessary to build for Windows:
- Remove {Build tool gcc} in (Build - Packages)
- Add {Build tool cl} in (Build - Packages)
- In (Tools - Paths) adjust the path (Build Tools) to C:\Program Files\Microsoft Visual Studio\VC98\Bin or where ever the cl.exe from your visual studio is installed to.
- In (Tools - Paths) adjust the path (User Tools) c:\cygwin\bin or where ever cygwin is installed on your machine.
Compile it now.
Sub directories EXAMPLE_PRJ_build and EXAMPLE_PRJ_install will be created along with EXAMPLE_PRJ.acc
3. Create Files
Create the following files in the same directory as the EXAMPLE_PRJ.acc is located.
test.cpp
#include "ApparatusFramework/KernelServices/Kernel.h"
#include "ApparatusFramework/KernelServices/Task.h"
#include "ApparatusFramework/DiagnosticServices/Logger.h"
#include "PingPongTask.h"
#include "PingPongMsg.h"
void main()
{
Logger::Create();
Kernel::Create(10);
Logger::Default()->printLogText("PingPongMain Start\n");
Kernel::Default()->startKernel();
// Create Tasks
PingPongTask task1(task1Id, task1Priority, taskName1);
PingPongTask task2(task2Id, task2Priority, taskName2);
// Start Tasks (Please start all the tasks after you have constructed them.)
task1.startTask();
task2.startTask();
Msg* pMsg = new PingPongMsg;
pMsg->m_msgId = 0;
Task::sendMsgToTask(&task1, pMsg);
for (;;)
{
Kernel::Default()->delayFor(1000);
}
}
PingPongTask.h
#ifndef PING_PONG_TASK_H
#define PING_PONG_TASK_H
#include "ApparatusFramework/KernelServices/Kernel.h"
#include "ApparatusFramework/KernelServices/Task.h"
const TaskId task1Id = 11;
const TaskPriority task1Priority = 11;
const char taskName1[] = "task1";
const TaskId task2Id = 12;
const TaskPriority task2Priority = 12;
const char taskName2[] = "task2";
class PingPongTask : public Task
{
public:
PingPongTask(const TaskId taskId, const TaskPriority taskPriority, const char taskName[]);
virtual void runBody();
private:
static int msgCounter;
};
#endif //#define PING_PONG_TASK_H
PingPongTask.cpp
#include "ApparatusFramework/KernelServices/Task.h"
#include "ApparatusFramework/DiagnosticServices/Logger.h"
#include "ApparatusFramework/KernelServices/apfw_assert.h"
#include "PingPongTask.h"
#include "PingPongMsg.h"
int PingPongTask::msgCounter=0;
PingPongTask::PingPongTask(const TaskId taskId, const TaskPriority taskPriority, const char taskName[]) :
Task(taskId, taskPriority, 0, 10, taskName)
{
}
void PingPongTask::runBody()
{
int id=taskId();
Task* task;
if(id==task1Id)
task=Kernel::Default()->getTaskWithId(task2Id);
else
task=Kernel::Default()->getTaskWithId(task1Id);
Msg* pMsg;
for(;;)
{
pMsg = waitMsg();
APFW_ASSERT(pMsg!=0);
pMsg->Release(pMsg);
Logger::Default()->printLogText("PingPong: Task nr. %d receive message nr. %d \n",id,msgCounter);
delayFor(100);
pMsg = new PingPongMsg;
pMsg->m_msgId = ++msgCounter;
sendMsg(task, pMsg);
}
}
PingPongMsg.h
#ifndef PING_PONG_H
#define PING_PONG_H
#include "ApparatusFramework/KernelServices/Msg.h"
class PingPongMsg : public Msg
{
public:
Msg* clone(){return new PingPongMsg(*this);};
void dump() const {Logger::Default()->printLogText("<PingPongMsg>\n");};
};
#endif //PING_PONG_H
4. Create a Visual Studio Project
Create a dsp and dsw project file for Visual Studio. The easiest way is to open test.cpp in Visual Studio and click build. The build will not succeed because several settings are not yet correct. But at least the project files test.dsp and test.dsw will be created.
5. Add the necessary files
Add the other files to the visual studio project:
- PingPongTask.cpp
- PingPongTask.h
- PingPongMsg.h
6. Settings the include directory
In Visual Studio click (Project - Settings)
Tab (C/C++)
Choose (Preprocessor) in Category
Add .\EXAMPLE_PRJ_install\include in (Additional include directories)
7. Add the ApFw library
In Visual Studio click (Project - Settings)
Tab (Link)
Choose (Input) in Category
Add .\EXAMPLE_PRJ_install\lib in (Additional library path)
Add libApFw.a in (Object/library modules)
8. Compile it
Finally everything is ready to compile and run. Have fun!

