From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Master/Real-Time Systems/mki/test/mkidemo.cpp | 130 ++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 Master/Real-Time Systems/mki/test/mkidemo.cpp (limited to 'Master/Real-Time Systems/mki/test/mkidemo.cpp') diff --git a/Master/Real-Time Systems/mki/test/mkidemo.cpp b/Master/Real-Time Systems/mki/test/mkidemo.cpp new file mode 100644 index 0000000..e5f8729 --- /dev/null +++ b/Master/Real-Time Systems/mki/test/mkidemo.cpp @@ -0,0 +1,130 @@ +//============================================================================ +// Name: +// mkidemo.cpp +// +// Summary: +// Extremly simple demo program that shows some values +// on the mercedes combi instrument. needs libcanio to work. +// +// Default interface is can0, to change it start the program like this: +// mkidemo -f=can1 +// +// Created on: +// Okt 1, 2010 +// +// Author: +// Christian Steiger +//============================================================================ + + +// includes +#include "../src/mki.h" + +// Function prototypes +const char* const fetchinterface (const int argc, const char* const argv[]); + +// Main function +int main(int argc, char *argv[]) +{ + int mph =0; + int temperatur=40; + int rpm =0; + // get the interface data from the command line + const char* const interface = fetchinterface(argc, argv); + + // create mki object + mki m; + + // connect to interface, stop if we cant connect + if (m.connect(interface) < 0) + return -1; + + //m.getInterface()->disableLoopBack(); + + // set informations we want to display + //m.setLamps(MKI_WARN | MKI_FUEL_LOW | MKI_WARN_BLINK | MKI_ABS); + + //m.setDisplay(MKI_LIMIT | MKI_PERMANENT | MKI_MPH_BLINK ); + m.setDisplay(MKI_LIMIT | MKI_PERMANENT ); + // m.setAlert( MKI_TIRE_PRESSURE ); + + // send the data in an endless loop + // every 50ms or so should be enough, + // use pthreads if you want it out of the way + while (1) { + mph++; + temperatur++; + rpm = rpm + 100; + + m.setMph(mph); + m.setDisplayMph(mph); + m.setRpm(rpm); + m.setCWTemp(temperatur); + + m.sendData(); + usleep(100000); + + if(temperatur >= 130) + temperatur = 40; + + if(mph > 160 ) + mph=0; + + if(rpm>6000) + m.setLamps( MKI_WARN_BLINK ); + + if(rpm > 7000) + { + rpm = 0; + m.setLampsOff(); + } + + } + + // everything ok + return 0; +} + +// quick and dirty hack with code from PeakCanLogger +// to allow the interface to be set via commandline. +const char* const fetchinterface (const int argc, const char* const argv[]) +{ + int i, len; + char* interface = new char(5); + strcpy( interface, "can0" ); + + // go through the argument, ignore the first one + for( i = 1; i < argc; i++ ) + { + // check the arguments first and third char, is it a config parameter? + if ( argv[i][0] == '-' ) + { + // check which config parameter it is + switch( argv[i][1] ) + { + // set can-device + case 'd': + case 'f': + // delete the actual char string + delete interface; + + // get the lenght of the new string + len = strlen(&argv[i][3]); + + // create a new one + interface = new char( len ); + + // set string with zeros + memset( interface, 0, len ); + + // and copy it + strcpy( interface, &argv[i][3] ); + + default: + break; + } + } + } + + return interface; +} -- cgit v1.2.3