summaryrefslogtreecommitdiffstats
path: root/Master/Masterarbeit/src/XorayaTestPlugin/xoraya_test_plugin.cpp
blob: c2b016590250387e8f58460e3f2bcb5bdb535ab5 (plain)
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
/*
 * xoraya_test_plugin.cpp
 *
 *  Created on: 31.08.2011
 *      Author: Eisenhauer
 */

#include "plugin_api.h"
#include "global.h"
#include "interface_manager.h"

class XorayaTestPlugin : public IPlugin
{
private:
	IInterfaceManager& m_xInterfaceManager;
	int32_t m_i32InterfaceHandle;
	uint32_t m_u32TxMsgId;
	tCanTxMessageList m_axCanTxMessages;
	uint32_t m_u32PluginId;
	uint32_t m_u32Loopcounter;

	static uint32_t su32InstanceCount;

public:

	XorayaTestPlugin( IInterfaceManager& xIfMan,
			int32_t i32Interface,
			uint32_t u32PluginId
			)
	:m_xInterfaceManager( xIfMan ),
	 m_i32InterfaceHandle( i32Interface ),
	 m_u32TxMsgId(0x100*(1+XorayaTestPlugin::su32InstanceCount)),
	 m_u32PluginId(u32PluginId),
	 m_u32Loopcounter(0)
	{
		DEBUG_PRINT("constructor");
		boost::shared_ptr<tstCanTxMessage> pstCanMsg1(new tstCanTxMessage);
		pstCanMsg1->u32CanId = m_u32TxMsgId+2;
		pstCanMsg1->u8Dlc = 5;
		pstCanMsg1->u32TxCycleMilliseconds = 500;
		pstCanMsg1->u32MillisecondCounter = 0;
		pstCanMsg1->au8Data = {0,0,0,0,0,0,0,0};
		m_axCanTxMessages.push_back(pstCanMsg1);
		boost::shared_ptr<tstCanTxMessage> pstCanMsg2(new tstCanTxMessage);
		pstCanMsg2->u32CanId = m_u32TxMsgId+1;
		pstCanMsg2->u8Dlc = 5;
		pstCanMsg2->u32TxCycleMilliseconds = 1000;
		pstCanMsg2->u32MillisecondCounter = 0;
		pstCanMsg2->au8Data = {0,0,0,0,0,0,0,0};
		m_axCanTxMessages.push_back(pstCanMsg2);
		boost::shared_ptr<tstCanTxMessage> pstCanMsg3(new tstCanTxMessage);
		pstCanMsg3->u32CanId = m_u32TxMsgId;
		pstCanMsg3->u8Dlc = 5;
		pstCanMsg3->u32TxCycleMilliseconds = 500;
		pstCanMsg3->u32MillisecondCounter = 0;
		pstCanMsg3->au8Data = {0,0,0,0,0,0,0,0};
		m_axCanTxMessages.push_back(pstCanMsg3);
		DEBUG_PRINT("Plg Id: %d msg 1: 0x%X", m_u32PluginId, (uint32_t) pstCanMsg1.get());
		DEBUG_PRINT("Plg Id: %d msg 2: 0x%X", m_u32PluginId, (uint32_t) pstCanMsg2.get());
		DEBUG_PRINT("Plg Id: %d msg 3: 0x%X", m_u32PluginId, (uint32_t) pstCanMsg3.get());
		XorayaTestPlugin::su32InstanceCount++;
	}

	virtual ~XorayaTestPlugin()
	{
		DEBUG_PRINT("destructor");
		XorayaTestPlugin::su32InstanceCount--;
	}



	virtual void vRun( void )
	{
//		DEBUG_PRINT("entry");
		m_u32Loopcounter++;
		tCanTxMessageList::iterator xMsgIter;
		for( xMsgIter = m_axCanTxMessages.begin(); xMsgIter != m_axCanTxMessages.end(); xMsgIter++ )
		{
			tpstCanTxMessage pxMsg = *xMsgIter;
			pxMsg->au8Data[0] = m_u32PluginId;
			if( xMsgIter == m_axCanTxMessages.begin() )
			{
				pxMsg->au8Data[4] = (uint8_t) (m_u32Loopcounter>>24);
				pxMsg->au8Data[3] = (uint8_t) (m_u32Loopcounter>>16);
				pxMsg->au8Data[2] = (uint8_t) (m_u32Loopcounter>>8);
				pxMsg->au8Data[1] = (uint8_t) m_u32Loopcounter;
			}
			else
			{
				pxMsg->au8Data[1] = (uint8_t) (m_u32Loopcounter>>24);
				pxMsg->au8Data[2] = (uint8_t) (m_u32Loopcounter>>16);
				pxMsg->au8Data[3] = (uint8_t) (m_u32Loopcounter>>8);
				pxMsg->au8Data[4] = (uint8_t) m_u32Loopcounter;
			}
		}
//		DEBUG_PRINT("exit");
	}

	virtual tCanTxMessageList& xGetCanTxMessages( void )
	{
		return m_axCanTxMessages;
	}

	virtual int32_t i32GetCanInterfaceHandle( void )
	{
		return m_i32InterfaceHandle;
	}
};

uint32_t XorayaTestPlugin::su32InstanceCount = 0;

extern "C" IPlugin* pxCreatePlugin(
		IInterfaceManager& xIfMan,
		int32_t i32Interface,
		uint32_t u32PluginId
		)
{
	DEBUG_PRINT("entry");
	return new XorayaTestPlugin(xIfMan, i32Interface, u32PluginId);
}

extern "C" void vDestroyPlugin(IPlugin* pxPlugin)
{
	DEBUG_PRINT("entry");
	delete pxPlugin;
	DEBUG_PRINT("exit");
}