X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fsball.c;h=e6ff48e2fef147609633cbab6a96370540ce18c0;hb=4ab56d777d7e9e2ae2e69278d18d31bb480d6151;hp=951ff45026b9e393f1c60afd491da21aad1c7aab;hpb=b749ae14b503c3a01d8fcefc22daf561454a3de0;p=sball diff --git a/src/sball.c b/src/sball.c index 951ff45..e6ff48e 100644 --- a/src/sball.c +++ b/src/sball.c @@ -11,6 +11,18 @@ #include #include +#if defined(__i386__) || defined(__ia64__) || defined(WIN32) || \ + (defined(__alpha__) || defined(__alpha)) || \ + defined(__arm__) || \ + (defined(__mips__) && defined(__MIPSEL__)) || \ + defined(__SYMBIAN32__) || \ + defined(__x86_64__) || \ + defined(__LITTLE_ENDIAN__) +#define SBALL_LITTLE_ENDIAN +#else +#define SBALL_BIG_ENDIAN +#endif + #define INP_BUF_SZ 256 enum { @@ -64,13 +76,11 @@ struct sball *sball_open(const char *dev) return 0; } - if(!(sb = malloc(sizeof *sb))) { + if(!(sb = calloc(1, sizeof *sb))) { fprintf(stderr, "sball_open: failed to allocate sball object\n"); goto err; } sb->fd = fd; - sb->flags = 0; - sb->len = 0; stty_save(sb); @@ -224,7 +234,12 @@ static int stty_mag(struct sball *sb) term.c_cc[VERASE] = 0; term.c_cc[VKILL] = 0; - term.c_cflag = CLOCAL | CREAD | CS8 | CSTOPB | HUPCL | CRTSCTS; + term.c_cflag = CLOCAL | CREAD | CS8 | CSTOPB | HUPCL; +#ifdef CCTS_OFLOW + term.c_cflag |= CCTS_OFLOW; +#elif defined(CRTSCTS) + term.c_cflag |= CRTSCTS; +#endif term.c_iflag = IGNBRK | IGNPAR; cfsetispeed(&term, B9600); @@ -294,13 +309,8 @@ static int mag_parsepkt(struct sball *sb, int id, char *data, int len) return -1; } for(i=0; i<6; i++) { -#ifdef SBALL_BIG_ENDIAN - sb->mot[i] = ((((int)data[3] & 0xf) << 12) | (((int)data[2] & 0xf) << 8) | - (((int)data[1] & 0xf) << 4) | (data[0] & 0xf)) - 0x8000; -#else sb->mot[i] = ((((int)data[0] & 0xf) << 12) | (((int)data[1] & 0xf) << 8) | (((int)data[2] & 0xf) << 4) | (data[3] & 0xf)) - 0x8000; -#endif data += 4; } print_state(sb); @@ -370,16 +380,15 @@ static int sball_parsepkt(struct sball *sb, int id, char *data, int len) } #ifndef SBALL_BIG_ENDIAN + rd = data; for(i=0; i<6; i++) { - data += 2; - c = data[0]; - data[0] = data[1]; - data[1] = c; - sb->mot[i] = *(short*)data; + rd += 2; + c = rd[0]; + rd[0] = rd[1]; + rd[1] = c; } -#else - memcpy(sb->mot, data + 2, 12); #endif + memcpy(sb->mot, data + 2, 12); print_state(sb); break; @@ -427,7 +436,7 @@ static int sball_parsepkt(struct sball *sb, int id, char *data, int len) case 'E': fprintf(stderr, "sball: error:"); for(i=0; i