summaryrefslogtreecommitdiffstats
path: root/Usb-Driver/test-mocca.c
diff options
context:
space:
mode:
authorChristian Gromm <christian.gromm@microchip.com>2016-06-21 14:14:04 +0200
committerChristian Gromm <christian.gromm@microchip.com>2016-06-21 14:14:04 +0200
commit860b3c0ccfb2756b8ed77523048952011b74a212 (patch)
treee0672fb5cf923dcf0a4a48a62a69011e1b72976a /Usb-Driver/test-mocca.c
parent742bace60b9c0a0f583d8afe1097d029f468fa03 (diff)
src: can-lin: initial source import
This patch adds the sources needed for the HVAC and iDrive applications. Change-Id: I53148a5d11c34787dd11295939bbaf8702c64dcb Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Diffstat (limited to 'Usb-Driver/test-mocca.c')
-rw-r--r--Usb-Driver/test-mocca.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/Usb-Driver/test-mocca.c b/Usb-Driver/test-mocca.c
new file mode 100644
index 0000000..70c4760
--- /dev/null
+++ b/Usb-Driver/test-mocca.c
@@ -0,0 +1,68 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <pthread.h>
+
+uint8_t relayOn[] = {
+ 0x04, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x13,
+ 0x02, 0x0b, 0x70, 0x07, 0x00, 0x00, 0x01, 0x00
+};
+
+uint8_t relayOff[] = {
+ 0x04, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x13,
+ 0x02, 0x0b, 0x70, 0x07, 0x00, 0x00, 0x00, 0x00
+};
+
+uint8_t readBuffer[1024];
+
+static int32_t repeat = 10;
+static pthread_t readingThread;
+static bool allowRun = true;
+static int fd = -1;
+
+void* executeReading ( void* arg )
+{
+ uint32_t bytesRead;
+ uint32_t i;
+
+ while ( allowRun ) {
+ bytesRead = read ( fd, readBuffer, sizeof ( readBuffer ) );
+ if ( bytesRead > 0 ) {
+ printf ( "Received bytes (hex): " );
+ for ( i = 0; i < bytesRead; i++ ) {
+ printf ( "%02X ", readBuffer[i] );
+ }
+ printf ( "\n" );
+ }
+ }
+ pthread_exit ( 0 );
+}
+
+int main ( int argc, char* argv[] )
+{
+ int ret;
+ if ( ( fd = open ( "/dev/mocca0", O_RDWR|O_SYNC ) ) < 0 ) {
+ printf ( "Failed to open mocca0 device\n" );
+ exit ( -4 );
+ }
+ ret = pthread_create ( &readingThread, NULL, executeReading, NULL );
+ if ( ret ) {
+ printf ( "Failed to start reader thread\n" );
+ } else {
+ while ( --repeat >= 0 ) {
+ write ( fd, relayOn, sizeof ( relayOn ) );
+ usleep ( 1000000 );
+ write ( fd, relayOff, sizeof ( relayOff ) );
+ usleep ( 1000000 );
+ }
+ }
+ allowRun = false;
+
+ close ( fd );
+ return 0;
+}