From e66efbbe8df2dd4e7de0a1e9bd129cf92e00f92f Mon Sep 17 00:00:00 2001 From: vikle012 Date: Wed, 11 Sep 2019 13:57:14 +0200 Subject: Initializes repo. --- .../ClientServerApp/matlabClient/matlabClient.cpp | 400 +++++++++++++++++++++ .../matlabClient/matlabClient.vcproj | 178 +++++++++ .../matlabClient/matlabClient.vcxproj | 158 ++++++++ .../ClientServerApp/matlabClient/stdafx.cpp | 8 + Kod/display/ClientServerApp/matlabClient/stdafx.h | 15 + .../ClientServerApp/matlabClient/targetver.h | 13 + 6 files changed, 772 insertions(+) create mode 100644 Kod/display/ClientServerApp/matlabClient/matlabClient.cpp create mode 100644 Kod/display/ClientServerApp/matlabClient/matlabClient.vcproj create mode 100644 Kod/display/ClientServerApp/matlabClient/matlabClient.vcxproj create mode 100644 Kod/display/ClientServerApp/matlabClient/stdafx.cpp create mode 100644 Kod/display/ClientServerApp/matlabClient/stdafx.h create mode 100644 Kod/display/ClientServerApp/matlabClient/targetver.h (limited to 'Kod/display/ClientServerApp/matlabClient') diff --git a/Kod/display/ClientServerApp/matlabClient/matlabClient.cpp b/Kod/display/ClientServerApp/matlabClient/matlabClient.cpp new file mode 100644 index 0000000..8f811b9 --- /dev/null +++ b/Kod/display/ClientServerApp/matlabClient/matlabClient.cpp @@ -0,0 +1,400 @@ +//============================================================================ +// Name : matlabClient.cpp +// Author : Erik Hellström, hellstrom@isy.liu.se, 2008-12-14 +// Modified : Emil Larsson, lime@isy.liu.se, 2012-01-13 +// Modified : Emil Larsson, lime@isy.liu.se, 2012-09-04 +// Data from LCD is written to the shared memory. By request, the +// data is copied to a local Matlab variable. +// +// Description : The client requests data to be sent by the server. +// +//============================================================================ + + +#include +#include +#include "ComConduit.h" +//#ifdef _CHAR16T +//#define CHAR16_T +//#endif +#include "mex.h" + +int send_communication(bool doShutdown,wchar_t* input_string,int buflen,int flag){ + // Conduit object + ComConduit Link; + // Key + KeyType key[KEY_LEN] = COM_KEY; + // Work variables + wchar_t data[COMSTR_LEN]; + wchar_t dataFromLCD[COMSTR_LEN]; + WaitResult wr; + + int retval, ii; + + + // Initialize data + retval = 0; + data[0] = '\0'; + + // strcpy((char*) data,input_string); + // wcscpy_s(&data[0],COMSTR_LEN, input_string); + + /* Copy data from input_string to data */ + for (ii=0; ii 0){ + flag = (int)*mxGetPr(prhs[0]); + }; + + plhs[1] = mxCreateDoubleMatrix(0,0,mxREAL); + // ptr_out = mxGetPr(plhs[1]); + + //if( (nrhs < 4) && (nrhs > 0)){ + // flag = (int)*mxGetPr(prhs[0]); + //}; + + + + if(flag==3){ + /* If no error, call send_communication */ + doShutdown = true; + } + + /* Do some checks of input arguments */ + if (nrhs > 0){ + if (!mxIsDouble(prhs[0])) { + mexPrintf("\nThe first input argument is not a double.\n"); + retval = 1; + } + else if (flag==4) { + mexPrintf("\nMatlab Client\n"); + mexPrintf("=============\n"); + mexPrintf("Version: %4.2f.\n", ver); + mexPrintf("Date: %s.\n", date); + retval = 4; + } + else if (!(mxGetN(prhs[0]) == 1) || !(mxGetM(prhs[0]) == 1)) { + mexPrintf("\nThe first input argument is not a scalar.\n"); + retval = 1; + } + else if (!(flag == 1 || flag == 2 || flag == 3)) { + mexPrintf("\nWrong numerical value of the first argument.\n"); + retval = 1; + } + else if (flag == 1 && nrhs < 2) { + mexPrintf("\nTo few input arguments.\n"); + retval = 1; + } + } + else{ + mexPrintf("\nTo few input arguments\n"); + retval = 1; + } + + if (nrhs > 1){ + if (!(flag == 1) || !mxIsDouble(prhs[1])) { + mexPrintf("\nFirst and second argument mismatch.\n"); + flag = 1; + retval = 1; + } + // if (!mxIsDouble(prhs[1])) { + // retval = 1; + // mexPrintf("The second argument is not a double vector.\n"); + // } + } + + if (nrhs > 2){ + mexPrintf("\nTo many input arguments\n"); + retval = 1; + } + + + /* Save output argument */ + if ((retval == 1) || (retval == 4)){ + plhs[0] = mxCreateDoubleMatrix(1,1, mxREAL); + *(mxGetPr(plhs[0])) = retval; + } + + + + if ((nrhs > 0) && (retval == 0)){ + /* Get the length of the input string. */ + // buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1; + + // mexPrintf("\nbuflen: %d \n", buflen); + + + /* Allocate memory for input and output strings. */ + // input_buf=(char *) mxCalloc(buflen, sizeof(char)); + // external_buf=(wchar_t *) mxCalloc(buflen+1, sizeof(wchar_t)); + + /* Copy the string data from prhs[0] into a C string + * input_buf. */ + // status = mxGetString(prhs[0], input_buf, buflen); + + // if (status != 0) + // mexWarnMsgTxt("Not enough space. String will be truncated."); + + + // unsigned char *start_of_pr; + // size_t bytes_to_copy; + + + /* get the length of the input vector and pointer to data*/ + if (nrhs > 1) { + nx = mxGetN(prhs[1]); + mx = mxGetM(prhs[1]); + prtData = mxGetPr(prhs[1]); + } + else { + nx = 1; + mx = 1; + prtData = mxGetPr(prhs[0]); + } + + + /* check if the argument is a row or col vector */ + if (nx > mx) + n = nx; + else + n = mx; + + + /* Check length of buffer */ + if ((n > COMSTR_LEN) && (retval == 0) && (nrhs > 1)){ + mexPrintf("\nToo long data package.\n"); + retval = 1; + } + else if ((n < 4) && (retval == 0) && (nrhs > 1)) { + mexPrintf("\nToo short data package.\n"); + retval = 1; + } + + /* Check length of data package */ + if ((int) prtData[1] != n-3 && (nrhs > 1)) { + mexPrintf("\nIncorrect data package.\n"); + retval = 1; + } + /* Check if the package starts with DC1 or DC2 */ + else if (((int) prtData[0] != 17) && ((int) prtData[0] != 18) && (nrhs > 1)) { + mexPrintf("\nIncorrect data package.\n"); +// mexPrintf("\nIncorrect data package. %d\n", (int) prtData[0]); + retval = 1; + } + + /* Copy the double input vector to a wchar_t-string */ + unsigned short int x_short[COMSTR_LEN]; + ii = 0; + for (ii=0; ii < n; ii++) + { + x_short[ii] = (unsigned short int) prtData[ii]; + + /* Calculate checksum bcc */ + if (ii < n-1) + bcc = bcc + x_short[ii]; + + /* Check if the element is too large */ + if((x_short[ii] > 255) && (retval == 0)) { + mexPrintf("Vector element %d is larger then 255.\n", ii+1); + retval = 1; + break; + } + + /* Copy each element */ + x_short_w[ii] = (wchar_t) x_short[ii]; + // mexPrintf("\nx_short[%d]: %d \n", ii, x_short[ii]); + + } + /* Stop with a "null" char */ + x_short_w[ii] = (wchar_t) '\0'; + + /* Compare the checksum bcc with the last element */ + if ((x_short[n-1] != bcc) && (retval == 0) && (nrhs > 1)) { + mexPrintf("\nIncorrect data package.\n"); + // mexPrintf("\nChecksum %d mismatch. \n", x_short[n-1]); + //printf("\nChecksum %d mismatch. \n", x_short[n-1]); + retval = 1; + } + + /* If no error, call send_communication */ + if (retval == 0){ + retval = send_communication(doShutdown,x_short_w,n,flag); + } + + /* Save output argument */ + plhs[0] = mxCreateDoubleMatrix(1,1, mxREAL); + *(mxGetPr(plhs[0])) = retval; + + /* Receive data from shared memory */ + if (flag == 2){ + + /* Length of Buffer */ + int lenBuf = (int) x_short_w[1]; + + //mexPrintf("\nHere: lenBuf %d: \n", lenBuf); + + /* Save in Shared memory */ + // int saveInSHM = 1; + + if ((x_short_w[1] == 1) && (x_short_w[2])){ + saveInSHM = 1; + } + else if ((x_short_w[1] == 1) && (x_short_w[2] == 21)){ + saveInSHM = 1; + } + else { + /* calculate checksum */ + bcc = 0; + for (ii=3; ii < (mwSize) x_short_w[4]+5; ii++){ + + /* Calculate checksum bcc */ + bcc = bcc + x_short_w[ii]; + } +// mexPrintf("\nHere: Checksum bcc %d: \n", bcc); + + /* Compare the checksum bcc with the last element */ + if (x_short_w[ii] != bcc){ +// mexPrintf("\nHere: Checksum %d mismatch. \n", x_short_w[lenBuf+1]); + retval = 1; + + saveInSHM = 0; + } + else { + saveInSHM = 1; + } + } + + + + if (saveInSHM == 1){ + + /* Save output argument */ + double *ptr_out; + plhs[1] = mxCreateDoubleMatrix(1,lenBuf,mxREAL); + ptr_out = mxGetPr(plhs[1]); + + for (ii=2; ii < (mwSize) lenBuf+2; ii++){ + ptr_out[ii-2] = (double) x_short_w[ii]; + // mexPrintf("\nx_short_w[%d]: %f \n", ii, ptr_out[ii-1]); + } + } + } + + } + +} + + + + + + + diff --git a/Kod/display/ClientServerApp/matlabClient/matlabClient.vcproj b/Kod/display/ClientServerApp/matlabClient/matlabClient.vcproj new file mode 100644 index 0000000..336b1f0 --- /dev/null +++ b/Kod/display/ClientServerApp/matlabClient/matlabClient.vcproj @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Kod/display/ClientServerApp/matlabClient/matlabClient.vcxproj b/Kod/display/ClientServerApp/matlabClient/matlabClient.vcxproj new file mode 100644 index 0000000..715e944 --- /dev/null +++ b/Kod/display/ClientServerApp/matlabClient/matlabClient.vcxproj @@ -0,0 +1,158 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {3094F281-B0A8-4B46-B1CC-A4B8B5CC596A} + matlabClient + Win32Proj + + + + StaticLibrary + Unicode + true + + + StaticLibrary + Unicode + true + + + StaticLibrary + NotSet + + + StaticLibrary + NotSet + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(Configuration)\ + false + false + + + + Disabled + C:\Program Files %28x86%29\MATLAB\R2011b\extern\include;C:\stuff\svn\TFYY51\Code\Display\ClientServerApp\Common;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + EditAndContinue + + + + + Disabled + C:\Program Files %28x86%29\MATLAB\R2011b\extern\include;C:\stuff\svn\TFYY51\Code\Display\ClientServerApp\Common;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + ProgramDatabase + + + + + MaxSpeed + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level3 + ProgramDatabase + C:\Program Files %28x86%29\MATLAB\R2011b\extern\include;..\Common + + + true + Console + true + true + MachineX86 + C:\Program Files %28x86%29\MATLAB\R2011b\extern\include;%(AdditionalLibraryDirectories) + libmx.lib;libmex.lib;libmat.lib;%(AdditionalDependencies) + + + + + MaxSpeed + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level3 + ProgramDatabase + C:\Program Files\MATLAB\R2011b\extern\include;..\Common + + + true + Console + true + true + C:\Program Files %28x86%29\MATLAB\R2011b\extern\include;%(AdditionalLibraryDirectories) + libmx.lib;libmex.lib;libmat.lib;%(AdditionalDependencies) + + + + + + + + {8c1e78f5-0564-498a-958d-37a997bbfe49} + false + + + + + + \ No newline at end of file diff --git a/Kod/display/ClientServerApp/matlabClient/stdafx.cpp b/Kod/display/ClientServerApp/matlabClient/stdafx.cpp new file mode 100644 index 0000000..1d98a62 --- /dev/null +++ b/Kod/display/ClientServerApp/matlabClient/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// matlabClient.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/Kod/display/ClientServerApp/matlabClient/stdafx.h b/Kod/display/ClientServerApp/matlabClient/stdafx.h new file mode 100644 index 0000000..47a0d02 --- /dev/null +++ b/Kod/display/ClientServerApp/matlabClient/stdafx.h @@ -0,0 +1,15 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#include +#include + + + +// TODO: reference additional headers your program requires here diff --git a/Kod/display/ClientServerApp/matlabClient/targetver.h b/Kod/display/ClientServerApp/matlabClient/targetver.h new file mode 100644 index 0000000..a38195a --- /dev/null +++ b/Kod/display/ClientServerApp/matlabClient/targetver.h @@ -0,0 +1,13 @@ +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// 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 _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + -- cgit v1.2.1