<commit_before>/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2020 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU Lesser General Public License, as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any
 * later version. Please see the file LICENSE-LGPL for details.
 *
 * Web Page: http://brltty.app/
 *
 * This software is maintained by <NAME> <<EMAIL>>.
 */

#include "prologue.h"

#include <string.h>
#include <errno.h>

#include "log.h"
#include "io_generic.h"
#include "io_usb.h"
#include "ezusb.h"

#define BRL_STATUS_FIELDS sfCursorCoordinates, sfWindowCoordinates
#define BRL_HAVE_STATUS_CELLS
#include "brl_driver.h"
#include "brldefs-fa.h"

#define PROBE_RETRY_LIMIT 2
#define PROBE_INPUT_TIMEOUT 1000

#define MAXIMUM_RESPONSE_SIZE 0X20
#define WRITE_CELLS_LIMIT 62

#define TEXT_CELL_COUNT 80
#define STATUS_CELL_COUNT 4

BEGIN_KEY_NAME_TABLE(navigation)
  BRL_KEY_NAME_ENTRY(FA, NAV, K1, "K1"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K2, "K2"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K3, "K3"),

  BRL_KEY_NAME_ENTRY(FA, NAV, K4, "K4"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K5, "K5"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K6, "K6"),

  BRL_KEY_NAME_ENTRY(FA, NAV, K7, "K7"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K8, "K8"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K9, "K9"),

  BRL_KEY_NAME_ENTRY(FA, NAV, F1, "F1"),
  BRL_KEY_NAME_ENTRY(FA, NAV, F2, "F2"),
  BRL_KEY_NAME_ENTRY(FA, NAV, F3, "F3"),

  BRL_KEY_NAME_ENTRY(FA, NAV, F4, "F4"),
  BRL_KEY_NAME_ENTRY(FA, NAV, F5, "F5"),
  BRL_KEY_NAME_ENTRY(FA, NAV, F6, "F6"),

  BRL_KEY_GROUP_ENTRY(FA, ROUTE, "RoutingKey"),
  BRL_KEY_GROUP_ENTRY(FA, SLIDE, "Slider"),
END_KEY_NAME_TABLE

BEGIN_KEY_NAME_TABLES(all)
  KEY_NAME_TABLE(navigation),
END_KEY_NAME_TABLES

DEFINE_KEY_TABLE(all)

BEGIN_KEY_TABLE_LIST
  &KEY_TABLE_DEFINITION(all),
END_KEY_TABLE_LIST

typedef struct {
  int (*prepare) (BrailleDisplay *brl);
} ProductEntry;

typedef struct {
  size_t length;
  unsigned char buffer[8];
} DeviceResponse;

struct BrailleDataStruct {
  const ProductEntry *product;

  struct {
    KeyNumberSet navigation;
    unsigned char routing[TEXT_CELL_COUNT / 8];
  } keys;

  struct {
    unsigned char rewrite;
    unsigned char cells[TEXT_CELL_COUNT];
  } text;

  struct {
    unsigned char rewrite;
    unsigned char cells[STATUS_CELL_COUNT];
  } status;

  struct {
    DeviceResponse response1;
    DeviceResponse serialNumber[2];
    DeviceResponse response4;
    DeviceResponse response5;
    DeviceResponse response6;
    DeviceResponse response7;
    DeviceResponse response8;
  } device;
};

static UsbDevice *
getDevice (BrailleDisplay *brl) {
  UsbChannel *channel = gioGetResourceObject(brl->gioEndpoint);
  return channel->device;
}

typedef struct {
  UsbDevice *device;
  EzusbAction action;
} RecordProcessingData;

static int
handleRecord (const IhexParsedRecord *record, void *data) {
  const RecordProcessingData *rpd = data;

  {
    int ok = ezusbWriteData(
      rpd->device, rpd->action,
      record->address, record->data, record->count
    );

    if (!ok) return 0;
  }

  {
    int ok = ezusbVerifyData(
      rpd->device, rpd->action,
      record->address, record->data, record->count
    );

    if (!ok) return 0;
  }

  return 1;
}<commit_msg>Frank Audiodata: Make the parsed ihex record handler code look a lot nicer. (ml)<commit_after>/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2020 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU Lesser General Public License, as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any
 * later version. Please see the file LICENSE-LGPL for details.
 *
 * Web Page: http://brltty.app/
 *
 * This software is maintained by <NAME> <<EMAIL>>.
 */

#include "prologue.h"

#include <string.h>
#include <errno.h>

#include "log.h"
#include "io_generic.h"
#include "io_usb.h"
#include "ezusb.h"

#define BRL_STATUS_FIELDS sfCursorCoordinates, sfWindowCoordinates
#define BRL_HAVE_STATUS_CELLS
#include "brl_driver.h"
#include "brldefs-fa.h"

#define PROBE_RETRY_LIMIT 2
#define PROBE_INPUT_TIMEOUT 1000

#define MAXIMUM_RESPONSE_SIZE 0X20
#define WRITE_CELLS_LIMIT 62

#define TEXT_CELL_COUNT 80
#define STATUS_CELL_COUNT 4

BEGIN_KEY_NAME_TABLE(navigation)
  BRL_KEY_NAME_ENTRY(FA, NAV, K1, "K1"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K2, "K2"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K3, "K3"),

  BRL_KEY_NAME_ENTRY(FA, NAV, K4, "K4"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K5, "K5"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K6, "K6"),

  BRL_KEY_NAME_ENTRY(FA, NAV, K7, "K7"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K8, "K8"),
  BRL_KEY_NAME_ENTRY(FA, NAV, K9, "K9"),

  BRL_KEY_NAME_ENTRY(FA, NAV, F1, "F1"),
  BRL_KEY_NAME_ENTRY(FA, NAV, F2, "F2"),
  BRL_KEY_NAME_ENTRY(FA, NAV, F3, "F3"),

  BRL_KEY_NAME_ENTRY(FA, NAV, F4, "F4"),
  BRL_KEY_NAME_ENTRY(FA, NAV, F5, "F5"),
  BRL_KEY_NAME_ENTRY(FA, NAV, F6, "F6"),

  BRL_KEY_GROUP_ENTRY(FA, ROUTE, "RoutingKey"),
  BRL_KEY_GROUP_ENTRY(FA, SLIDE, "Slider"),
END_KEY_NAME_TABLE

BEGIN_KEY_NAME_TABLES(all)
  KEY_NAME_TABLE(navigation),
END_KEY_NAME_TABLES

DEFINE_KEY_TABLE(all)

BEGIN_KEY_TABLE_LIST
  &KEY_TABLE_DEFINITION(all),
END_KEY_TABLE_LIST

typedef struct {
  int (*prepare) (BrailleDisplay *brl);
} ProductEntry;

typedef struct {
  size_t length;
  unsigned char buffer[8];
} DeviceResponse;

struct BrailleDataStruct {
  const ProductEntry *product;

  struct {
    KeyNumberSet navigation;
    unsigned char routing[TEXT_CELL_COUNT / 8];
  } keys;

  struct {
    unsigned char rewrite;
    unsigned char cells[TEXT_CELL_COUNT];
  } text;

  struct {
    unsigned char rewrite;
    unsigned char cells[STATUS_CELL_COUNT];
  } status;

  struct {
    DeviceResponse response1;
    DeviceResponse serialNumber[2];
    DeviceResponse response4;
    DeviceResponse response5;
    DeviceResponse response6;
    DeviceResponse response7;
    DeviceResponse response8;
  } device;
};

static UsbDevice *
getDevice (BrailleDisplay *brl) {
  UsbChannel *channel = gioGetResourceObject(brl->gioEndpoint);
  return channel->device;
}

typedef struct {
  UsbDevice *device;
  EzusbAction action;
} RecordProcessingData;

static int
handleRecord (const IhexParsedRecord *record, void *data) {
  const RecordProcessingData *rpd = data;

  UsbDevice *const device = rpd->device;
  const EzusbAction action = rpd->action;

  const IhexAddress address = record->address;
  const IhexByte *const bytes = record->data;
  const IhexCount count = record->count;

  if (!ezusbWriteData(device, action, address, bytes, count)) return 0;
  if (!ezusbVerifyData(device, action, address, bytes, count)) return 0;

  return 1;
}
{'fraction_non_alphanumeric': 0.10832979776552114, 'fraction_numerical': 0.018384952623391317, 'mean_word_length': 4.572892040977147, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2479533', 'n_tokens_mistral': 2721, 'n_tokens_neox': 2585, 'n_words': 668}