You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
263 lines
5.1 KiB
263 lines
5.1 KiB
1 year ago
|
/**
|
||
|
* @file Zusi 3 Antrieb DLL Test
|
||
|
* @author Jonathan Pilborough / jonathanp
|
||
|
*/
|
||
|
|
||
|
#include "antrieb.h"
|
||
|
#include "AntriebModel.h"
|
||
|
|
||
|
#include <windows.h>
|
||
|
#include <shlobj.h>
|
||
|
|
||
|
#include <fstream>
|
||
|
#include <vector>
|
||
|
#include <memory>
|
||
|
#include <cstring>
|
||
|
#include <string>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
static ofstream logOutput;
|
||
|
static vector<AntriebModel*> activeModels;
|
||
|
|
||
|
// Get Path {{Desktop}}\antrieb.log
|
||
|
bool GetLogPath(string& outFile)
|
||
|
{
|
||
|
static char path[MAX_PATH + 1];
|
||
|
if (SHGetSpecialFolderPathA(HWND_DESKTOP, path, CSIDL_DESKTOP, FALSE))
|
||
|
{
|
||
|
outFile.assign(path);
|
||
|
outFile.append("/antrieb.log");
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
void OpenLog()
|
||
|
{
|
||
|
string logPath;
|
||
|
if (GetLogPath(logPath) && !logOutput.is_open())
|
||
|
{
|
||
|
logOutput.open(logPath);
|
||
|
logOutput << "Log Started" << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL,
|
||
|
DWORD fdwReason,
|
||
|
LPVOID lpReserved)
|
||
|
{
|
||
|
switch (fdwReason)
|
||
|
{
|
||
|
case DLL_PROCESS_ATTACH:
|
||
|
break;
|
||
|
|
||
|
case DLL_THREAD_ATTACH:
|
||
|
break;
|
||
|
|
||
|
case DLL_THREAD_DETACH:
|
||
|
break;
|
||
|
|
||
|
case DLL_PROCESS_DETACH:
|
||
|
logOutput << "DLL Unloaded" << endl;
|
||
|
logOutput.close();
|
||
|
for (int i = 0; i < activeModels.size(); ++i)
|
||
|
delete activeModels[i];
|
||
|
break;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void Info()
|
||
|
{
|
||
|
string info;
|
||
|
GetLogPath(info);
|
||
|
info = "Antrieb Test DLL. Logfile: " + info;
|
||
|
MessageBox(NULL, info.c_str(), "Information", MB_ICONINFORMATION);
|
||
|
}
|
||
|
|
||
|
uint16_t AnzahlVarianten()
|
||
|
{
|
||
|
return 2;
|
||
|
}
|
||
|
|
||
|
wchar_t* VariantenName(int32_t index)
|
||
|
{
|
||
|
if (index == 0)
|
||
|
{
|
||
|
return L"Fahrstufe";
|
||
|
}
|
||
|
else if (index == 1)
|
||
|
{
|
||
|
return L"Zugkraft";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return L"Invalid Variant";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* Initialisation */
|
||
|
void* VarianteAktivieren(int32_t index)
|
||
|
{
|
||
|
unique_ptr<AntriebModel> model = std::make_unique<AntriebModel>(index);
|
||
|
activeModels.push_back(model.release());
|
||
|
|
||
|
OpenLog();
|
||
|
logOutput << activeModels.back() << " VarianteAktivieren() " << index << endl;
|
||
|
|
||
|
return activeModels.back();
|
||
|
}
|
||
|
|
||
|
uint8_t LeseAntriebstyp(void* instanz)
|
||
|
{
|
||
|
logOutput << instanz << " LeseAntriebstyp()" << endl;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* Input - Simulation Step */
|
||
|
void Bedienung(void* instanz, AntriebsRenderModus antriebsRenderModus, ProtokollFst* prot, float sp)
|
||
|
{
|
||
|
static ProtokollFst lastProtokoll;
|
||
|
|
||
|
if (prot->rischa.funktion != lastProtokoll.rischa.funktion)
|
||
|
logOutput << instanz << " Input Rischa" << " " << static_cast<uint32_t>(prot->rischa.funktion) << endl;
|
||
|
|
||
|
if (prot->hauptschalter.funktion != lastProtokoll.hauptschalter.funktion)
|
||
|
logOutput << instanz << " Input Hauptschalter" << " " << static_cast<uint32_t>(prot->hauptschalter.funktion) << endl;
|
||
|
|
||
|
if (prot->schaltstufenSteller.parameter != lastProtokoll.schaltstufenSteller.parameter)
|
||
|
logOutput << instanz << " Input Fahrstufe" << " " << prot->schaltstufenSteller.parameter << endl;
|
||
|
|
||
|
if (prot->zugkraftSteller.parameter != lastProtokoll.zugkraftSteller.parameter)
|
||
|
logOutput << instanz << " Input Zugkraft" << " " << prot->zugkraftSteller.parameter << endl;
|
||
|
|
||
|
memcpy(&lastProtokoll, prot, sizeof(ProtokollFst));
|
||
|
|
||
|
static_cast<AntriebModel*>(instanz)->Bedienung(antriebsRenderModus, prot, sp);
|
||
|
}
|
||
|
|
||
|
void Berechnung(void* instanz, double dt, AntriebsRenderModus antriebsRenderModus, Mehrfachtraktionsdaten mehrfachtraktionsdaten)
|
||
|
{
|
||
|
static_cast<AntriebModel*>(instanz)->Berechnung(dt, antriebsRenderModus, mehrfachtraktionsdaten);
|
||
|
}
|
||
|
|
||
|
void VorspanntraktionsdatenSetzen(void* instanz, float sp, float sollLeistungNormiert)
|
||
|
{
|
||
|
static_cast<AntriebModel*>(instanz)->VorspanntraktionsdatenSetzen(sp, sollLeistungNormiert);
|
||
|
}
|
||
|
|
||
|
/* Input - Event Triggers */
|
||
|
void Nullstellungszwang(void* instanz)
|
||
|
{
|
||
|
logOutput << instanz << " Nullstellungszwang()" << endl;
|
||
|
}
|
||
|
|
||
|
void SetzeHauptschalterzustand(void* instanz, uint8_t modus)
|
||
|
{
|
||
|
logOutput << instanz << " SetzeHauptschalterzustand() " << " -> " << static_cast<uint32_t>(modus) << endl;
|
||
|
}
|
||
|
|
||
|
/* Output */
|
||
|
|
||
|
float LeseMaxAntriebskraft(void* instanz, float spAkt)
|
||
|
{
|
||
|
return static_cast<AntriebModel*>(instanz)->LeseMaxAntriebskraft(spAkt);
|
||
|
}
|
||
|
|
||
|
float LeseAntriebskraft(void* instanz)
|
||
|
{
|
||
|
return static_cast<AntriebModel*>(instanz)->LeseAntriebskraft();
|
||
|
}
|
||
|
|
||
|
float LeseAntriebskraftSollNormiert(void* instanz)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
float LeseOberstrom(void* instanz)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
float LeseMotorstrom(void* instanz)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
float LeseMotorspannung(void* instanz)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int32_t LeseAchsen(void* instanz)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
float LeseSollZugkraft(void* instanz)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
float LeseMotordrehzahl(void* instanz)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
float LeseMotormoment(void* instanz)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
float LeseMotorlast(void* instanz)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
float LeseFahrstufe(void* instanz)
|
||
|
{
|
||
|
return static_cast<AntriebModel*>(instanz)->LeseFahrstufe();
|
||
|
}
|
||
|
|
||
|
float LeseZylSolldruck(void* instanz)
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
float PruefeFahrstufe0(void* instanz)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
uint8_t NullstellungszwangAktiv(void* instanz)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
uint8_t HauptschalterWgOLEnde(void* instanz, Fahrleitungstyp fahrlTyp, float spannungsfaktor)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
uint8_t HauptschalterWgOberstrom(void* instanz)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
uint8_t Hauptschalterstatus(void* instanz)
|
||
|
{
|
||
|
return 0; //Hauptschalter ein
|
||
|
}
|
||
|
|
||
|
uint8_t HauptschalterDrin(void* instanz)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
uint8_t DieselmotorLaeuft(void* instanz)
|
||
|
{
|
||
|
return false;
|
||
|
}
|