diff options
Diffstat (limited to 'src/winclientlib')
-rwxr-xr-x | src/winclientlib/stdafx.cpp | 8 | ||||
-rwxr-xr-x | src/winclientlib/stdafx.h | 32 | ||||
-rwxr-xr-x | src/winclientlib/winclientlib.cpp | 276 | ||||
-rwxr-xr-x | src/winclientlib/winclientlib.h | 59 | ||||
-rwxr-xr-x | src/winclientlib/winclientlib.sln | 20 | ||||
-rwxr-xr-x | src/winclientlib/winclientlib.vcproj | 260 |
6 files changed, 655 insertions, 0 deletions
diff --git a/src/winclientlib/stdafx.cpp b/src/winclientlib/stdafx.cpp new file mode 100755 index 0000000..62e53b6 --- /dev/null +++ b/src/winclientlib/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes
+// WwinClientLib.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file
diff --git a/src/winclientlib/stdafx.h b/src/winclientlib/stdafx.h new file mode 100755 index 0000000..a13982c --- /dev/null +++ b/src/winclientlib/stdafx.h @@ -0,0 +1,32 @@ +// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef WINVER // Allow use of features specific to Windows XP or later.
+#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
+#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
+#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
+#endif
+
+#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
+#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE.
+#endif
+
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+// Windows Header Files:
+#include <windows.h>
+
+
+
+// TODO: reference additional headers your program requires here
diff --git a/src/winclientlib/winclientlib.cpp b/src/winclientlib/winclientlib.cpp new file mode 100755 index 0000000..7d67f14 --- /dev/null +++ b/src/winclientlib/winclientlib.cpp @@ -0,0 +1,276 @@ +/******************************************************************************* +** ** +** SRC-MODULE: winclientLib.cpp ** +** ** +** TARGET : Windows ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/ + +/******************************************************************************* +** Revision Control History ** +*******************************************************************************/ + +/* + * $LastChangedRevision$ + * $LastChangedDate$ + * $LastChangedBy$ + */ + +// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib + +// Disable C4995 and C4996 Warnings +#pragma warning(disable : 4995) +#pragma warning(disable : 4996) + +#include "stdafx.h" + +#include <winsock2.h> +#include <ws2tcpip.h> +#include <stdlib.h> +#include <stdio.h> +#include <windows.h> +#include <strsafe.h> +#include <io.h> + +#include <string> +#include <iostream> + +#include "winclientlib.h" +#include "dlt_client.h" + +// Function prototypes +DWORD WINAPI MyThreadFunction( LPVOID lpParam ); +void ErrorHandler(LPTSTR lpszFunction); + +// Variables +static DWORD dwThreadId; +static HANDLE hThread; +static HANDLE hEvent; + +static DltClient windltclient; + +#ifdef _MANAGED +#pragma managed(push, off) +#endif + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + { + break; + } + } + return TRUE; +} + +#ifdef _MANAGED +#pragma managed(pop) +#endif + +using namespace std; + +/* +Some helper functions +*/ + +DWORD WINAPI MyThreadFunction( LPVOID lpParam ) +{ + // Enter Main Loop + dlt_client_main_loop(&windltclient, NULL, 0); + + // Send event about thread termination + SetEvent(hEvent); + + ExitThread(0); +} + +void ErrorHandler(LPTSTR lpszFunction) +{ + // Retrieve the system error message for the last-error code. + LPVOID lpMsgBuf; + LPVOID lpDisplayBuf; + + DWORD dw = GetLastError(); + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, + 0, NULL ); + + // Display the error message. + lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, + (lstrlen((LPCTSTR) lpMsgBuf) + lstrlen((LPCTSTR) lpszFunction) + 40) * sizeof(TCHAR)); + StringCchPrintf((LPTSTR)lpDisplayBuf, + LocalSize(lpDisplayBuf) / sizeof(TCHAR), + TEXT("%s failed with error %d: %s"), + lpszFunction, dw, lpMsgBuf); + + MessageBox(NULL, (LPCTSTR) lpDisplayBuf, TEXT("Error"), MB_OK); + + // Free error-handling buffer allocations. + LocalFree(lpMsgBuf); + LocalFree(lpDisplayBuf); +} + +/*** +The interface functions +****/ + +WWINCLIENTLIB_API void Dlt_RegisterMessageCallback(int (*registerd_callback) (DltMessage *message, void *data)) +{ + dlt_client_register_message_callback(registerd_callback); +} + +WWINCLIENTLIB_API int Dlt_StartClient(char* server_address) +{ + WSADATA wsaData; + int iResult; + + if ((server_address==0) || (server_address[0]=='\0')) + { + return 0; + } + + // Create event, used for thread termination + hEvent = CreateEvent(NULL,FALSE,FALSE,(LPCWSTR)"Test"); + + // Initialize Winsock + iResult = WSAStartup(MAKEWORD(2,2), &wsaData); + if (iResult) + { + printf("winclientlib: WSAStartup failed: %d\n", iResult); + return -1; + } + + /* Initialize DLT Client */ + if (dlt_client_init(&windltclient, 0)==-1) + { + ErrorHandler(TEXT("dlt_client_init()")); + + Dlt_ExitClient(); + + return -1; + } + + /* Setup parameters of DltClient */ + windltclient.sock = -1; + windltclient.serial_mode = 0; /* TCP connection: + In Windows (with Visual C++), + only TCP connection is allowed! */ + windltclient.servIP = server_address; /* IP address */ + + + /* Connect to TCP socket */ + if (dlt_client_connect(&windltclient, 0)==-1) + { + ErrorHandler(TEXT("dlt_client_connect()")); + + Dlt_ExitClient(); + + return -1; + } + + // Create the thread to begin execution on its own. + hThread = CreateThread( + NULL, // default security attributes + 0, // use default stack size + MyThreadFunction, // thread function name + 0,//(LPVOID)address, // argument to thread function + 0, // use default creation flags + &dwThreadId); // returns the thread identifier + + // Check the return value for success. + // If CreateThread fails, terminate execution. + // This will automatically clean up threads and memory. + if (hThread==0) + { + ErrorHandler(TEXT("CreateThread()")); + + // Cleanup WSA + WSACleanup(); + + return -1; + } + + return 0; +} + +WWINCLIENTLIB_API int Dlt_InjectCall( char appID[4], char contID[4], uint32_t serviceID, uint8_t *buf, uint32_t buf_len ) +{ + return dlt_client_send_inject_msg(&windltclient, appID, contID, serviceID, buf, buf_len); +} + +WWINCLIENTLIB_API int Dlt_ExitClient() +{ + printf("winclientlib: exiting ...\n"); + + // Terminate thread and close handles + if (windltclient.sock!=-1) + { + if (windltclient.serial_mode==1) + { + close(windltclient.sock); + } + else + { + closesocket(windltclient.sock); + } + windltclient.sock = -1; + + WaitForSingleObject(hEvent,INFINITE); + } + + CloseHandle(hEvent); + CloseHandle(hThread); + + // Dlt Client Cleanup + if (dlt_client_cleanup(&windltclient,0)==-1) + { + printf("winclientlib: closing error.\n"); + } + else + { + printf("winclientlib: closed.\n"); + } + + // Cleanup WSA + WSACleanup(); + + exit(0); +} diff --git a/src/winclientlib/winclientlib.h b/src/winclientlib/winclientlib.h new file mode 100755 index 0000000..15c69fb --- /dev/null +++ b/src/winclientlib/winclientlib.h @@ -0,0 +1,59 @@ +/******************************************************************************* +** ** +** SRC-MODULE: winClientLib.h ** +** ** +** TARGET : Windows ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/ + +/******************************************************************************* +** Revision Control History ** +*******************************************************************************/ + +/* + * $LastChangedRevision$ + * $LastChangedDate$ + * $LastChangedBy$ + */ + +#include "dlt_common.h" // for DltMessage + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the WWINCLIENTLIB_EXPORTS +// symbol defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// WWINCLIENTLIB_API functions as being imported from a DLL, whereas this DLL sees symbols +// defined with this macro as being exported. +#ifdef WINCLIENTLIB_EXPORTS +#define WWINCLIENTLIB_API __declspec(dllexport) +#else +#define WWINCLIENTLIB_API __declspec(dllimport) +#endif + +WWINCLIENTLIB_API int Dlt_StartClient(char* server_address); +WWINCLIENTLIB_API int Dlt_ExitClient(); +WWINCLIENTLIB_API int Dlt_InjectCall( char appID[4], char contID[4], uint32_t serviceID, uint8_t *buf, uint32_t buf_len ); +WWINCLIENTLIB_API void Dlt_RegisterMessageCallback(int (*registerd_callback) (DltMessage *message, void *data)); diff --git a/src/winclientlib/winclientlib.sln b/src/winclientlib/winclientlib.sln new file mode 100755 index 0000000..c5343d9 --- /dev/null +++ b/src/winclientlib/winclientlib.sln @@ -0,0 +1,20 @@ +
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual C++ Express 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winclientlib", "winclientlib.vcproj", "{F3674DAE-F85A-428C-85FE-3529671DF6ED}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {F3674DAE-F85A-428C-85FE-3529671DF6ED}.Debug|Win32.ActiveCfg = Debug|Win32
+ {F3674DAE-F85A-428C-85FE-3529671DF6ED}.Debug|Win32.Build.0 = Debug|Win32
+ {F3674DAE-F85A-428C-85FE-3529671DF6ED}.Release|Win32.ActiveCfg = Release|Win32
+ {F3674DAE-F85A-428C-85FE-3529671DF6ED}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/src/winclientlib/winclientlib.vcproj b/src/winclientlib/winclientlib.vcproj new file mode 100755 index 0000000..6729bb2 --- /dev/null +++ b/src/winclientlib/winclientlib.vcproj @@ -0,0 +1,260 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9,00"
+ Name="winclientlib"
+ ProjectGUID="{F3674DAE-F85A-428C-85FE-3529671DF6ED}"
+ RootNamespace="winclientlib"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\include;..\..\include\dlt;..\.."
+ PreprocessorDefinitions="WINCLIENTLIB_EXPORTS;_CRT_SECURE_NO_WARNINGS;WIN32;__WIN32__;_DEBUG"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="mswsock.lib Ws2_32.lib"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ EntryPointSymbol="DllMain"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories="..\include;..\..\include\dlt;..\.."
+ PreprocessorDefinitions="WINCLIENTLIB_EXPORTS;_CRT_SECURE_NO_WARNINGS;WIN32;__WIN32__;NDEBUG"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="mswsock.lib Ws2_32.lib"
+ GenerateDebugInformation="true"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Quelldateien"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="..\lib\dlt_client.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\lib\dlt_common.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\winclientlib.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Headerdateien"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath="..\..\include\dlt\dlt_client.h"
+ >
+ </File>
+ <File
+ RelativePath="..\include\dlt_common.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\include\dlt\dlt_protocol.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\include\dlt\msvc_stdint.h"
+ >
+ </File>
+ <File
+ RelativePath=".\stdafx.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\stdafx.h"
+ >
+ </File>
+ <File
+ RelativePath=".\winclientlib.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Ressourcendateien"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
|