Exemplo n.º 1
0
// Close the connection and release the console device
void telnetRelease(JsNetwork *net) {
  if (!(tnSrv.sock && tnSrv.cliSock)) return;
  printf("tnSrv: released console from sock %d\n", tnSrv.cliSock);
  netCloseSocket(net, tnSrv.cliSock);
  tnSrv.cliSock = 0;
  jsiSetConsoleDevice( DEFAULT_CONSOLE_DEVICE );
}
Exemplo n.º 2
0
// Close the connection and release the console device
void telnetRelease(JsNetwork *net) {
  if (!(tnSrv.sock && tnSrv.cliSock)) return;
  printf("tnSrv: released console from sock %d\n", tnSrv.cliSock);
  netCloseSocket(net, tnSrv.cliSock);
  tnSrv.cliSock = 0;
  if (!jsiIsConsoleDeviceForced()) jsiSetConsoleDevice(tnSrv.oldConsole, false);
}
Exemplo n.º 3
0
/**@brief Function for the Application's S110 SoftDevice event handler.
 *
 * @param[in] p_ble_evt S110 SoftDevice event.
 */
static void on_ble_evt(ble_evt_t * p_ble_evt) {
    uint32_t                         err_code;
    
    switch (p_ble_evt->header.evt_id) {
      case BLE_GAP_EVT_TIMEOUT:
        // the timeout for sd_ble_gap_adv_start expired - kick it off again
        jswrap_nrf_bluetooth_startAdvertise();
        break;

      case BLE_GAP_EVT_CONNECTED:
        m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        ble_is_sending = false; // reset state - just in case
        jsiSetConsoleDevice( EV_BLUETOOTH );
        break;

      case BLE_GAP_EVT_DISCONNECTED:
        m_conn_handle = BLE_CONN_HANDLE_INVALID;
        jsiSetConsoleDevice( DEFAULT_CONSOLE_DEVICE );
        break;

      case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
        // Pairing not supported
        err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
        APP_ERROR_CHECK(err_code);
        break;

      case BLE_GATTS_EVT_SYS_ATTR_MISSING:
        // No system attributes have been stored.
        err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
        APP_ERROR_CHECK(err_code);
        break;

      case BLE_EVT_TX_COMPLETE:
        // UART Transmit finished - we can try and send more data
        ble_is_sending = false;
        jswrap_nrf_transmit_string();
        break;

      default:
          // No implementation needed.
          break;
    }
}
Exemplo n.º 4
0
// Close the connection and release the console device
void telnetRelease(JsNetwork *net) {
  if (!(tnSrv.sock && tnSrv.cliSock)) return;
  printf("tnSrv: released console from sock %d\n", tnSrv.cliSock-1);
  netCloseSocket(net, tnSrv.cliSock-1);
  tnSrv.cliSock = 0;
  IOEventFlags console = jsiGetConsoleDevice();
  // only switch away from telnet if the current console is TELNET, this allows the current
  // console to be set to something else while connected via telnet and then not have it
  // switched again when disconnecting from telnet
  if (console == EV_TELNET && !jsiIsConsoleDeviceForced())
    jsiSetConsoleDevice(tnSrv.oldConsole, false);
}
Exemplo n.º 5
0
// Attempt to accept a connection, returns true if it did something
bool telnetAccept(JsNetwork *net) {
  // we're gonna do a single accept per idle iteration for now
  if (tnSrv.sock == 0) return false;
  int sock = netAccept(net, tnSrv.sock);
  if (sock < 0) return false; // nothing

  // if we already have a client, then disconnect it
  if (tnSrv.cliSock != 0) {
    netCloseSocket(net, tnSrv.cliSock);
  }
  jsiSetConsoleDevice(EV_TELNET);

  tnSrv.cliSock = sock;
  printf("tnSrv: accepted console on sock=%d\n", sock);
  return true;
}
Exemplo n.º 6
0
// Attempt to accept a connection, returns true if it did something
bool telnetAccept(JsNetwork *net) {
  // we're gonna do a single accept per idle iteration for now
  if (tnSrv.sock == 0) return false;
  int sock = netAccept(net, tnSrv.sock);
  if (sock < 0) return false; // nothing

  // if we already have a client, then disconnect it
  if (tnSrv.cliSock != 0) {
    netCloseSocket(net, tnSrv.cliSock);
  }
  // if the console is not already telnet, then change it
  IOEventFlags console = jsiGetConsoleDevice();
  if (console != EV_TELNET) {
    tnSrv.oldConsole = console;
    if (!jsiIsConsoleDeviceForced()) jsiSetConsoleDevice(EV_TELNET, false);
  }

  tnSrv.cliSock = sock;
  printf("tnSrv: accepted console on sock=%d\n", sock);
  return true;
}
Exemplo n.º 7
0
/**@brief Function for the application's SoftDevice event handler.
 *
 * @param[in] p_ble_evt SoftDevice event.
 */
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t                         err_code;
    
    switch (p_ble_evt->header.evt_id) {
      case BLE_GAP_EVT_TIMEOUT:
        // the timeout for sd_ble_gap_adv_start expired - kick it off again
        jswrap_nrf_bluetooth_startAdvertise();
        break;

      case BLE_GAP_EVT_CONNECTED:
        m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        bleStatus &= ~BLE_IS_SENDING; // reset state - just in case
        jsiSetConsoleDevice( EV_BLUETOOTH );
        break;

      case BLE_GAP_EVT_DISCONNECTED:
        m_conn_handle = BLE_CONN_HANDLE_INVALID;
        jsiSetConsoleDevice( DEFAULT_CONSOLE_DEVICE );
        // restart advertising after disconnection
        jswrap_nrf_bluetooth_startAdvertise();
        break;

      case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
        // Pairing not supported
        err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
        APP_ERROR_CHECK(err_code);
        break;

      case BLE_GATTS_EVT_SYS_ATTR_MISSING:
        // No system attributes have been stored.
        err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
        APP_ERROR_CHECK(err_code);
        break;

      case BLE_EVT_TX_COMPLETE:
        // UART Transmit finished - we can try and send more data
        bleStatus &= ~BLE_IS_SENDING;
        jswrap_nrf_transmit_string();
        break;

      case BLE_GAP_EVT_ADV_REPORT: {
        // Advertising data received
        const ble_gap_evt_adv_report_t *p_adv = &p_ble_evt->evt.gap_evt.params.adv_report;

        JsVar *evt = jsvNewObject();
        if (evt) {
          jsvObjectSetChildAndUnLock(evt, "rssi", jsvNewFromInteger(p_adv->rssi));
          jsvObjectSetChildAndUnLock(evt, "addr", jsvVarPrintf("%02x:%02x:%02x:%02x:%02x:%02x",
              p_adv->peer_addr.addr[5],
              p_adv->peer_addr.addr[4],
              p_adv->peer_addr.addr[3],
              p_adv->peer_addr.addr[2],
              p_adv->peer_addr.addr[1],
              p_adv->peer_addr.addr[0]));
          JsVar *data = jsvNewStringOfLength(p_adv->dlen);
          if (data) {
            jsvSetString(data, p_adv->data, p_adv->dlen);
            JsVar *ab = jsvNewArrayBufferFromString(data, p_adv->dlen);
            jsvUnLock(data);
            jsvObjectSetChildAndUnLock(evt, "data", ab);
          }
          jsiQueueObjectCallbacks(execInfo.root, BLE_SCAN_EVENT, &evt, 1);
          jsvUnLock(evt);
        }
        break;
        }

      default:
          // No implementation needed.
          break;
    }
}