summaryrefslogtreecommitdiffstats
path: root/Master/Real-Time Systems/mki/test/mkidemo.cpp
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Real-Time Systems/mki/test/mkidemo.cpp
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Real-Time Systems/mki/test/mkidemo.cpp')
-rw-r--r--Master/Real-Time Systems/mki/test/mkidemo.cpp130
1 files changed, 130 insertions, 0 deletions
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;
+}