Esempio n. 1
0
/* Returns 0 if everything is right, -1 if an error occured while sending */
static ssize_t brl_writePacket(BrailleDisplay *brl, const void *packet, size_t size)
{
  const unsigned char *p = packet;
  int lgtho = 1;
  unsigned char obuf[MAXPACKETSIZE];
  const unsigned char *x;
  unsigned char *y = obuf;
  unsigned char chksum=0;
  int i,res;

  *y++ = 02;
  for (x=p; (x-p) < size; x++) {
    chksum ^= *x;
    if ((*x) <= 5) {
      *y = 01;
      y++; lgtho++; 
      *y = ( *x ) | 0x40;
    } else *y = *x;
    y++; lgtho++; 
  }
  if (chksum<=5) {
    *y = 1; y++; lgtho++;  
    chksum |= 0x40;
  }
  *y = chksum; y++; lgtho++; 
  *y = 3; y++; lgtho++; 
  for (i=1; i<=5; i++) {
    if (serialWriteData(serialDevice,obuf,lgtho) != lgtho) continue; /* write failed, retry */
    serialAwaitOutput(serialDevice);
    serialAwaitInput(serialDevice, 1000);
    res = serialReadData(serialDevice,&chksum,1,0,0);
    if ((res==1) && (chksum == 0x04)) return 0;
  }
  return (-1);
}
Esempio n. 2
0
static unsigned char
getByte (void) {
  unsigned char byte;
  while (!serialAwaitInput(serialDevice, 1000000000));
  serialReadData(serialDevice, &byte, 1, 0, 0);
  return byte;
}
Esempio n. 3
0
static int
brl_construct (BrailleDisplay *brl, char **parameters, const char *device) {
  if (!isSerialDevice(&device)) {
     unsupportedDevice(device);
     return 0;
  }

  if ((serialDevice = serialOpenDevice(device))) {
    if (serialRestartDevice(serialDevice, serialBaud)) {
      static const unsigned char request[] = {BNO_DESCRIBE};
      charactersPerSecond = serialBaud / 10;
      if (writePacket(brl, request, sizeof(request)) != -1) {
        while (serialAwaitInput(serialDevice, 100)) {
          ResponsePacket response;
          int size = getPacket(&response);
          if (size) {
            if (response.data.code == BNI_DESCRIBE) {
              statusCells = response.data.values.description.statusCells;
              brl->textColumns = response.data.values.description.textCells;
              brl->textRows = 1;
              brl->keyBindings = "keys";

              if ((statusCells == 5) && (brl->textColumns == 30)) {
                statusCells -= 2;
                brl->textColumns += 2;
              }
              dataCells = brl->textColumns * brl->textRows;
              cellCount = statusCells + dataCells;

              makeOutputTable(dotsTable_ISO11548_1);
              makeInputTable();

              if ((cellBuffer = malloc(cellCount))) {
                memset(cellBuffer, 0, cellCount);
                statusArea = cellBuffer;
                dataArea = statusArea + statusCells;
                refreshCells(brl);
                persistentKeyboardMode = KBM_NAVIGATE;
                temporaryKeyboardMode = persistentKeyboardMode;
                persistentRoutingOperation = BRL_BLK_ROUTE;
                temporaryRoutingOperation = persistentRoutingOperation;
                return 1;
              } else {
                logSystemError("cell buffer allocation");
              }
            } else {
              logUnexpectedPacket(response.bytes, size);
            }
          }
        }
      }
    }
    serialCloseDevice(serialDevice);
    serialDevice = NULL;
  }
  return 0;
}
Esempio n. 4
0
static int
brl_construct (BrailleDisplay *brl, char **parameters, const char *device) {
  if (!isSerialDevice(&device)) {
    unsupportedDevice(device);
    return 0;
  }

  if ((serialDevice = serialOpenDevice(device))) {
    unsigned int baud = 19200;
    charactersPerSecond = baud / 11;

    if (serialRestartDevice(serialDevice, baud)) {
      if (serialSetParity(serialDevice, SERIAL_PARITY_EVEN)) {
        if (writePacket(brl, 4, NULL, 0)) {
          while (serialAwaitInput(serialDevice, 500)) {
            unsigned char response[3];
            int size = readPacket(brl, response, sizeof(response));
            if (size <= 0) break;

            if (response[1] == 4) {
              brl->textColumns = response[2];
              brl->textRows = 1;

              makeOutputTable(dotsTable_ISO11548_1);
              makeInputTable();

              if (!clearBrailleCells(brl)) break;
              if (!clearVisualText(brl)) break;
              if (!writeBrailleCells(brl)) break;

              return 1;
            }
          }
        }
      }
    }

    serialCloseDevice(serialDevice);
    serialDevice = NULL;
  }
  
  return 0;
}
Esempio n. 5
0
static int
identifyDisplay (BrailleDisplay *brl) {
  static const unsigned char identify[] = {'I', CR};

  if (writeBytes(brl, identify, sizeof(identify))) {
    if (serialAwaitInput(serialDevice, 1000)) {
      unsigned char identity[0X100];
      size_t length;

      if (readBytes(identity, sizeof(identity), &length)) {
        static const unsigned char prefix[] = {'b', 'r', 'a', 'u', 'd', 'i', ' '};
        if ((length >= sizeof(prefix)) &&
            (memcmp(identity, prefix, sizeof(prefix)) == 0)) {
          const unsigned char *bytes = memchr(identity, ',', length);
          if (bytes) {
            int count = length - (bytes - identity);
            int cells;

            ++bytes, --count;
            skipCharacter(' ', &bytes, &count);
            if (interpretNumber(&cells, &bytes, &count)) {
              if (!count) {
                logMessage(LOG_INFO, "Detected: %.*s", (int)length, identity);

                brl->textColumns = cells;
                brl->textRows = 1;

                return 1;
              }
            }
          }
        }

        logUnexpectedPacket(identity, length);
      }
    }
  }
  return 0;
}
Esempio n. 6
0
static int
awaitSerialInput (int milliseconds) {
  return serialAwaitInput(serialDevice, milliseconds);
}
Esempio n. 7
0
static int
awaitSerialInput (GioHandle *handle, int timeout) {
  return serialAwaitInput(handle->serial.device, timeout);
}