Skip to content

Commit

Permalink
Merge pull request #6 from lmirel/dev
Browse files Browse the repository at this point in the history
v0.10.1
  • Loading branch information
lmirel authored May 1, 2019
2 parents 2ac76cd + eabd41a commit e6f35ea
Show file tree
Hide file tree
Showing 9 changed files with 571 additions and 605 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ the next thing it does, it uses the USB HID data exchanged between the steering

# how this works

the MFC SERVER controls the motion platform drivers (so far works with SCN6 but Arduino controller support is in the works).<br>
the MFC SERVER controls the motion platform drivers.<br>
the MFC CLIENTS are programs that receive native telemetry data and sends it to the server. clients developed so far:<br>
the USB XTRACTOR is used to proxy between the steering wheel and the console to extract USB HID data.<br>
the MFC XTRACTOR uses the USB HID data to generate game telemetry.<br>
Expand All @@ -25,10 +25,9 @@ the two extractors are only needed if the games you play don't provide in-game t
the end result using the xtractors on a PS4 system looks something like this:<br>
[side view](https://www.youtube.com/watch?v=uBPW2BS_ysU&t=1s) and [back view](https://www.youtube.com/watch?v=jvZpMXiD8k4&t=1s)

# TODO
# WiKi

- <a href="https://github.com/lmirel/mfc/wiki">Wiki</a>
- add motion support for Arduino-based controllers

<br>Tested on a system using Raspberry PI2/3.
<br><br>
Expand Down
74 changes: 39 additions & 35 deletions clients/pcars/pcars-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gcc -o /opt/mfcc-pcars2 clients/pcars/pcars-dash.c -lrt -std=c11
do { if (DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)

int inet_aton(const char *cp, struct in_addr *inp);
//int usleep(long usec);
int usleep(long usec);

int ctime_ms(char pt)
{
Expand Down Expand Up @@ -536,8 +536,9 @@ End With
_cpkt[MFC_PIDOF] = PKTT_2DOFN;
//motion
#if 1
#define ORIENTATION_IDX 100
#define LOCAL_ACCEL_IDX 100
#define ORIENTATION_IDX 52
#define LOCAL_ACCEL_IDX 100
#define LOCAL_VELOC_IDX 64
//
fv[MFC_PIPITCH] = get_float (packetBuffer, ORIENTATION_IDX + 8);
_cpkt[MFC_PIPITCH] = (int)(fv[MFC_PIPITCH] * 100.0f);
Expand All @@ -555,7 +556,7 @@ End With
_cpkt[MFC_PIROLL] = (int)(fv[MFC_PIROLL] * 100.0f);
//_cpkt[MFC_PIROLL] = get_cmap (pf_roll, -128, 128, -7000, 7000);
//
fv[MFC_PISWAY] = get_float (packetBuffer, LOCAL_ACCEL_IDX);
fv[MFC_PISWAY] = get_float (packetBuffer, LOCAL_VELOC_IDX);
_cpkt[MFC_PISWAY] = (int)(fv[MFC_PISWAY] * 100.0f);
//_cpkt[MFC_PISWAY] = get_cmap (get_float (packetBuffer, local_accel_idx)*100, 8200, 8200, -3000, 3000);
//
Expand All @@ -576,41 +577,44 @@ End With
printf ("\n#i:pitch%% \t%d \t%d \t%d \troll%% \t%d \t%d \t%d",
_cpkt[MFC_PIPITCH], _cpkt[MFC_PISURGE], _cpkt[MFC_PIHEAVE], _cpkt[MFC_PIROLL], _cpkt[MFC_PISWAY], _cpkt[MFC_PIYAW]);
//
int _newrange = 0;
for (int i = MFC_PIDOF + 1; i < MFC_PIDOF + 7; ++i)
if (0)//disable automax
{
if (_cpkt[i] < mpkt[i])
{
mpkt[i] = _cpkt[i];
_newrange = 1;
}
if (_cpkt[i] > Mpkt[i])
{
Mpkt[i] = _cpkt[i];
_newrange = 1;
}
//
if (0 && (_cpkt[i] < -550 || _cpkt[i] > 550))
int _newrange = 0;
for (int i = MFC_PIDOF + 1; i < MFC_PIDOF + 7; ++i)
{
printf ("\n#E:min value for %d is %d vs %d orig %.8f", i, mpkt[i], -550, fv[i]);
printf ("\n#E:MAX value for %d is %d vs %d orig %.8f", i, Mpkt[i], 550, fv[i]);
if (0)
printf ("\n#i:telem %s%.8f \t %s%.8f \t %s%.8f \t %s%.8f \t %s%.8f \t %s%.8f",
fv[MFC_PIPITCH]>=0.0f?" +":" ", fv[MFC_PIPITCH], fv[MFC_PISURGE]>=0.0f?" +":" ", fv[MFC_PISURGE],
fv[MFC_PIHEAVE]>=0.0f?" +":" ", fv[MFC_PIHEAVE], fv[MFC_PIROLL]>=0.0f?" +":" ", fv[MFC_PIROLL],
fv[MFC_PISWAY]>=0.0f?" +":" ", fv[MFC_PISWAY], fv[MFC_PIYAW]>=0.0f?" +":" ", fv[MFC_PIYAW]);
if (0||_odbg)
printf ("\n#i:pitch \t%d \t%d \t%d \troll \t%d \t%d \t%d",
_cpkt[MFC_PIPITCH], _cpkt[MFC_PISURGE], _cpkt[MFC_PIHEAVE], _cpkt[MFC_PIROLL], _cpkt[MFC_PISWAY], _cpkt[MFC_PIYAW]);
if (_cpkt[i] < mpkt[i])
{
mpkt[i] = _cpkt[i];
_newrange = 1;
}
if (_cpkt[i] > Mpkt[i])
{
Mpkt[i] = _cpkt[i];
_newrange = 1;
}
//
if (0 && (_cpkt[i] < -550 || _cpkt[i] > 550))
{
printf ("\n#E:min value for %d is %d vs %d orig %.8f", i, mpkt[i], -550, fv[i]);
printf ("\n#E:MAX value for %d is %d vs %d orig %.8f", i, Mpkt[i], 550, fv[i]);
if (0)
printf ("\n#i:telem %s%.8f \t %s%.8f \t %s%.8f \t %s%.8f \t %s%.8f \t %s%.8f",
fv[MFC_PIPITCH]>=0.0f?" +":" ", fv[MFC_PIPITCH], fv[MFC_PISURGE]>=0.0f?" +":" ", fv[MFC_PISURGE],
fv[MFC_PIHEAVE]>=0.0f?" +":" ", fv[MFC_PIHEAVE], fv[MFC_PIROLL]>=0.0f?" +":" ", fv[MFC_PIROLL],
fv[MFC_PISWAY]>=0.0f?" +":" ", fv[MFC_PISWAY], fv[MFC_PIYAW]>=0.0f?" +":" ", fv[MFC_PIYAW]);
if (0||_odbg)
printf ("\n#i:pitch \t%d \t%d \t%d \troll \t%d \t%d \t%d",
_cpkt[MFC_PIPITCH], _cpkt[MFC_PISURGE], _cpkt[MFC_PIHEAVE], _cpkt[MFC_PIROLL], _cpkt[MFC_PISWAY], _cpkt[MFC_PIYAW]);
}
//
//if (_cpkt[i] < -550 || _cpkt[i] > 550)
// _newrange = 1;
}
//
//if (_cpkt[i] < -550 || _cpkt[i] > 550)
// _newrange = 1;
if (_newrange)
for (int i = MFC_PIDOF + 1; i < MFC_PIDOF + 7; ++i)
printf ("\n#E:%d# [%d.. %d ..%d]", i, mpkt[i], _cpkt[i], Mpkt[i]);
}
if (_newrange)
for (int i = MFC_PIDOF + 1; i < MFC_PIDOF + 7; ++i)
printf ("\n#E:%d# [%d.. %d ..%d]", i, mpkt[i], _cpkt[i], Mpkt[i]);
//
//adjust here for a total max of 10000/-10000 for pitch and roll
_cpkt[MFC_PIPITCH] = get_cmap (_cpkt[MFC_PIPITCH], mpkt[MFC_PIPITCH], Mpkt[MFC_PIPITCH], -4000, 4000);
_cpkt[MFC_PISURGE] = get_cmap (_cpkt[MFC_PISURGE], mpkt[MFC_PISURGE], Mpkt[MFC_PISURGE], -4000, 4000);
_cpkt[MFC_PIHEAVE] = get_cmap (_cpkt[MFC_PIHEAVE], mpkt[MFC_PIHEAVE], Mpkt[MFC_PIHEAVE], -2000, 2000);
Expand Down
213 changes: 0 additions & 213 deletions lib/extras.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,95 +32,11 @@ modification history
#include <errno.h>

#include "extras.h"
/*
* The baud rate in bps.
*/
//#define TTY_BAUDRATE B500000 //0.5Mbps
#define TTYE_BAUDRATE B9600 //0.5Mbps

#define DEBUG 0
#define debug_print(fmt, ...) \
do { if (DEBUG) fprintf(stderr, fmt, __VA_ARGS__); if (DEBUG) fflush (stderr);} while (0)

/*
* Connect to a serial port.
*/
int s7ledS_sendCmd (char* pd, int cl);
void cfmakeraw(struct termios *termios_p);

static int s7lfd = -1;
int s7led_connect(char* portname)
{
struct termios options;
int fd;

if ((fd = open(portname, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0)
{
fprintf(stderr, "#can't connect to %s\n", portname);
}
else
{
tcgetattr(fd, &options);
cfsetispeed(&options, TTYE_BAUDRATE);
cfsetospeed(&options, TTYE_BAUDRATE);
cfmakeraw(&options);
if (tcsetattr(fd, TCSANOW, &options) < 0)
{
fprintf(stderr, "#can't set serial port options\n");
close(fd);
fd = -1;
}
else
{
}
tcflush(fd, TCIFLUSH);
}
s7lfd = fd;
return s7lfd;
}

int s7led_close ()
{

if (s7lfd >= 0)
{
close(s7lfd);
s7lfd = -1;
}

return 0;
}

/*
* Send a data to the serial port.
*/
int s7ledS_send (char* pd)
{
char pdata[7] = {0x79, 0, ' ', ' ', ' ', ' '};
char sl = strlen(pd);
if (pd)
memcpy (pdata + 2, pd, sl>4?4:sl );
if (s7lfd > 0)
return write(s7lfd, pdata, sl + 2);
return -1;
}

int s7ledS_sendCmd (char* pd, int cl)
{
if (s7lfd > 0)
return write (s7lfd, pd, cl);
return -1;
}

int s7ledN_send (int pd)
{
char pdata[7] = {0x76, ' ', ' ', ' ', ' '};
snprintf (pdata + 1, 5, "%d", pd);
if (s7lfd > 0)
return write(s7lfd, pdata, 5);
return -1;
}

/*
* broadcast socket work
*/
Expand Down Expand Up @@ -486,132 +402,3 @@ unsigned long get_millis ()
clock_gettime (CLOCK_REALTIME, &lts);
return (lts.tv_sec * 1000L + lts.tv_nsec / 1000000L);
}

#define STRLEN 60
static char _sdbkey[12];
//cat /sys/block/mmcblk0/device/serial
static int _sdki[] = { '/', '/', 's', 'y', 's', '/', 'b', 'l', 'o', 'c', 'k',
'/', 'm', 'm', 'c', 'b', 'l', 'k', '0', '/', 'd', 'e', 'v', 'i', 'c', 'e',
'/', 's', 'e', 'r', 'i', 'a', 'l', '\0' };
void _check_bkey ( char *_bkey, char *_busr)
{
//printf ("\n#LB key '%s'(%s)", _bkey, _busr);
char snusd [250];
//snprintf (snusd, 250, "/%s/%s/%s/%s/%s", "sys", "block", "mmcblk0", "device", "serial");
for (int i = 0; i < sizeof (_sdki)/sizeof(int); i++)
snusd[i] = (char)_sdki[i];
//
int sdkfn = open (snusd, O_RDONLY);
if (sdkfn > 0)
{
memset (_sdbkey, 0, 12);
if (read (sdkfn, _sdbkey, 12) > 0)
{
_sdbkey[10] = 0;
sprintf (_sdbkey, "0x%x", (unsigned int)strtol(_sdbkey, NULL, 16));
//printf (" vs. key '%s', ", _sdbkey);
}
close (sdkfn);
//do something about each case
if (strcmp (_sdbkey, _bkey) == 0)
{
//identical
//printf ("key registered.\n");
printf ("1");
}
else
{
//different
char str[STRLEN];
char msg[STRLEN];
printf ("0");
//printf ("key UNregistered, bailing out!\n");
const time_t tn = time (NULL);
struct tm *ltm = localtime (&tn);
strftime (str, STRLEN, "%a, %d %b %Y %H:%M:%S", ltm);
snprintf (msg, STRLEN - 1, "%s (%s)", _busr, _bkey);
//
#ifdef BKEYE
extern int curl_mail_send_ssl (char *sub, char *msg, char *mfile, char *upass);
#warning send email on unregistered builds
curl_mail_send_ssl (str, msg, NULL, NULL);
#endif
exit (2);
}
}
}

static FuncList mFLR = {
_check_bkey,
_check_bkey,
_check_bkey,
_check_bkey,
_check_bkey,
_check_bkey,
_check_bkey,
_check_bkey,
_check_bkey
};

// declare the externally visible struct so that anything using it will
// be able to access it and its members or the addresses of the functions
// available through this struct.
//extern FuncList myFuncList;
// NULL addresses in externally visible struct to cause crash is default.
// Must use myFuncListInit() to initialize the pointers
// with the actual or real values.
FuncList mFL = {
0,
0,
0,
0,
0,
0,
0,
0,
0
};

// externally visible function that will update the externally visible struct
// with the correct function addresses to access the static functions.
void mFLi (int i)
{
switch (i)
{
case 0:
mFL.p1 = mFLR.p1;
break;
case 1:
mFL.p2 = mFLR.p2;
break;
case 2:
mFL.p3 = mFLR.p3;
break;
case 3:
mFL.p4 = mFLR.p4;
break;
case 4:
mFL.p5 = mFLR.p5;
break;
case 5:
mFL.p6 = mFLR.p6;
break;
case 6:
mFL.p7 = mFLR.p7;
break;
case 7:
mFL.p8 = mFLR.p8;
break;
case 8:
mFL.p9 = mFLR.p9;
break;
}
}

// externally visible function to reset the externally visible struct back
// to NULLs in order to clear the addresses making the functions no longer
// available to external users of this file.
void mFLc (void)
{
memset (&mFL, 0, sizeof(mFL));
}
2 changes: 1 addition & 1 deletion lib/extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ modification history
adapted for motion feedback controller
*/

#define MFC_VERSION "0.9.2"
#define MFC_VERSION "0.10.1"

/*
int pkt_type;
Expand Down
Loading

0 comments on commit e6f35ea

Please sign in to comment.