Add initial JVS pass through
This commit is contained in:
parent
a5f14ba9dd
commit
1eaa3c4092
@ -3,11 +3,25 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <linux/serial.h>
|
||||
#include <termios.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/serial.h>
|
||||
|
||||
#include "baseboard.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "jvs.h"
|
||||
#include "serial.h"
|
||||
|
||||
#define SERIAL_STRING "FE11-X018012022X"
|
||||
|
||||
@ -55,6 +69,7 @@ unsigned int sharedMemoryIndex = 0;
|
||||
uint8_t sharedMemory[1024 * 32] = {0};
|
||||
|
||||
int selectReply = -1;
|
||||
int jvsFileDescriptor = -1;
|
||||
|
||||
int initBaseboard()
|
||||
{
|
||||
@ -75,6 +90,16 @@ int initBaseboard()
|
||||
|
||||
fseek(sram, 0, SEEK_SET);
|
||||
|
||||
if (getConfig()->emulateJVS == 0 && strcmp(getConfig()->jvsPath, "none") != 0)
|
||||
{
|
||||
jvsFileDescriptor = open(getConfig()->jvsPath, O_RDWR | O_NOCTTY | O_SYNC | O_NDELAY);
|
||||
if (jvsFileDescriptor < 0)
|
||||
{
|
||||
printf("Error: Failed to open %s for JVS\n", getConfig()->jvsPath);
|
||||
}
|
||||
setSerialAttributes(jvsFileDescriptor, B115200);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -174,8 +199,32 @@ int baseboardIoctl(int fd, unsigned int request, void *data)
|
||||
jvsCommand.destAddress = _data[3];
|
||||
jvsCommand.destSize = _data[4];
|
||||
memcpy(inputBuffer, &sharedMemory[jvsCommand.srcAddress], jvsCommand.srcSize);
|
||||
if (getConfig()->emulateJVS)
|
||||
{
|
||||
processPacket();
|
||||
}
|
||||
else if (jvsFileDescriptor >= 0)
|
||||
{
|
||||
write(jvsFileDescriptor, inputBuffer, jvsCommand.srcSize);
|
||||
for (int i = 0; i < jvsCommand.srcSize; i++)
|
||||
printf("%X ", inputBuffer[i]);
|
||||
printf("\n");
|
||||
|
||||
for (int i = 0; i < jvsCommand.srcSize; i++)
|
||||
{
|
||||
if (inputBuffer[i] == 0xF0)
|
||||
{
|
||||
printf("SENSE LINE 3\n");
|
||||
setSenseLine(3);
|
||||
}
|
||||
else if (inputBuffer[i] == 0xF1)
|
||||
{
|
||||
setSenseLine(1);
|
||||
printf("SENSE LINE 1\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BASEBOARD_GET_SENSE_LINE:
|
||||
@ -212,11 +261,23 @@ int baseboardIoctl(int fd, unsigned int request, void *data)
|
||||
break;
|
||||
|
||||
case BASEBOARD_PROCESS_JVS:
|
||||
{
|
||||
if (getConfig()->emulateJVS)
|
||||
{
|
||||
memcpy(&sharedMemory[jvsCommand.destAddress], outputBuffer, outputPacket.length + 3);
|
||||
_data[2] = jvsCommand.destAddress;
|
||||
_data[3] = outputPacket.length + 3;
|
||||
}
|
||||
else if (jvsFileDescriptor >= 0)
|
||||
{
|
||||
int count = read(jvsFileDescriptor, &sharedMemory[jvsCommand.destAddress], 255);
|
||||
_data[2] = jvsCommand.destAddress;
|
||||
_data[3] = count;
|
||||
for (int i = 0; i < count; i++)
|
||||
printf("%X ", sharedMemory[jvsCommand.destAddress + i]);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -136,7 +136,10 @@ int initConfig()
|
||||
config.fullscreen = 0;
|
||||
strcpy(config.eepromPath, "eeprom.bin");
|
||||
strcpy(config.sramPath, "sram.bin");
|
||||
strcpy(config.jvsPath, "/dev/ttyUSB0");
|
||||
strcpy(config.jvsPath, "none");
|
||||
strcpy(config.driveboardPath, "none");
|
||||
strcpy(config.motionboardPath, "none");
|
||||
strcpy(config.rideboardPath, "none");
|
||||
config.width = 1024;
|
||||
config.height = 768;
|
||||
if (detectGame() != 0)
|
||||
|
@ -19,6 +19,9 @@ typedef struct
|
||||
char eepromPath[MAX_PATH_LENGTH];
|
||||
char sramPath[MAX_PATH_LENGTH];
|
||||
char jvsPath[MAX_PATH_LENGTH];
|
||||
char rideboardPath[MAX_PATH_LENGTH];
|
||||
char motionboardPath[MAX_PATH_LENGTH];
|
||||
char driveboardPath[MAX_PATH_LENGTH];
|
||||
int width;
|
||||
int height;
|
||||
Game game;
|
||||
|
@ -638,3 +638,7 @@ int setAnalogue(JVSInput channel, int value)
|
||||
io.state.analogueChannel[channel] = value;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void setSenseLine(int _senseLine) {
|
||||
senseLine = _senseLine;
|
||||
}
|
||||
|
@ -235,6 +235,7 @@ extern JVSPacket inputPacket, outputPacket;
|
||||
extern unsigned char outputBuffer[JVS_MAX_PACKET_SIZE], inputBuffer[JVS_MAX_PACKET_SIZE];
|
||||
|
||||
int getSenseLine();
|
||||
void setSenseLine(int senseLine);
|
||||
|
||||
JVSCapabilities *getCapabilities();
|
||||
JVSState *getState();
|
||||
|
66
src/lindbergh/serial.c
Normal file
66
src/lindbergh/serial.c
Normal file
@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <linux/serial.h>
|
||||
#include <termios.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/serial.h>
|
||||
|
||||
|
||||
#include "serial.h"
|
||||
|
||||
int setSerialAttributes(int fd, int myBaud)
|
||||
{
|
||||
struct termios options;
|
||||
int status;
|
||||
tcgetattr(fd, &options);
|
||||
|
||||
cfmakeraw(&options);
|
||||
cfsetispeed(&options, myBaud);
|
||||
cfsetospeed(&options, myBaud);
|
||||
|
||||
options.c_cflag |= (CLOCAL | CREAD);
|
||||
options.c_cflag &= ~PARENB;
|
||||
options.c_cflag &= ~CSTOPB;
|
||||
options.c_cflag &= ~CSIZE;
|
||||
options.c_cflag |= CS8;
|
||||
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
options.c_oflag &= ~OPOST;
|
||||
|
||||
options.c_cc[VMIN] = 10;
|
||||
options.c_cc[VTIME] = 10; // One seconds (10 deciseconds)
|
||||
|
||||
tcsetattr(fd, TCSANOW, &options);
|
||||
|
||||
ioctl(fd, TIOCMGET, &status);
|
||||
|
||||
status |= TIOCM_DTR;
|
||||
status |= TIOCM_RTS;
|
||||
|
||||
ioctl(fd, TIOCMSET, &status);
|
||||
|
||||
usleep(100 * 1000); // 10mS
|
||||
|
||||
struct serial_struct serial_settings;
|
||||
|
||||
ioctl(fd, TIOCGSERIAL, &serial_settings);
|
||||
|
||||
serial_settings.flags |= ASYNC_LOW_LATENCY;
|
||||
ioctl(fd, TIOCSSERIAL, &serial_settings);
|
||||
|
||||
tcflush(fd, TCIOFLUSH);
|
||||
usleep(100 * 1000); // Required to make flush work, for some reason
|
||||
|
||||
return 0;
|
||||
}
|
2
src/lindbergh/serial.h
Normal file
2
src/lindbergh/serial.h
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
int setSerialAttributes(int fd, int myBaud);
|
Loading…
Reference in New Issue
Block a user