| | |
| | | if (context->user_context != NULL) { |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->io) { |
| | | return (netconn_write(u->io, data, len, NETCONN_NOCOPY) == ERR_OK) ? len : 0; |
| | | return (netconn_write(u->io, data, len, NETCONN_COPY) == ERR_OK) ? len : 0; |
| | | } |
| | | } |
| | | return 0; |
| | |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->control_io) { |
| | | snprintf(b, sizeof (b), "SRQ%d\r\n", val); |
| | | return netconn_write(u->control_io, b, strlen(b), NETCONN_NOCOPY) == ERR_OK ? SCPI_RES_OK : SCPI_RES_ERR; |
| | | return netconn_write(u->control_io, b, strlen(b), NETCONN_COPY) == ERR_OK ? SCPI_RES_OK : SCPI_RES_ERR; |
| | | } |
| | | } |
| | | return SCPI_RES_OK; |
| | |
| | | } |
| | | } |
| | | |
| | | static int processIoListen(user_data_t * user_data) { |
| | | static int processIoListen(scpi_t * context, user_data_t * user_data) { |
| | | struct netconn *newconn; |
| | | |
| | | if (netconn_accept(user_data->io_listen, &newconn) == ERR_OK) { |
| | |
| | | netconn_delete(newconn); |
| | | } else { |
| | | /* connection established */ |
| | | SCPI_Event_DeviceConnected(NULL, newconn); |
| | | SCPI_Event_DeviceConnected(context, newconn); |
| | | ip_set_option(newconn->pcb.tcp, SOF_KEEPALIVE); |
| | | newconn->pcb.tcp->keep_idle = SCPI_KEEP_IDLE; // Override TCP_KEEPIDLE_DEFAULT for this connection. |
| | | newconn->pcb.tcp->keep_intvl = SCPI_KEEP_INTVL; // Override TCP_KEEPINTVL_DEFAULT for this connection. |
| | | newconn->pcb.tcp->keep_cnt = SCPI_KEEP_CNT; // Override TCP_KEEPCNT_DEFAULT for this connection. |
| | | user_data->io = newconn; |
| | | } |
| | | } |
| | |
| | | return 0; |
| | | } |
| | | |
| | | static int processSrqIoListen(user_data_t * user_data) { |
| | | static int processSrqIoListen(scpi_t * context, user_data_t * user_data) { |
| | | struct netconn *newconn; |
| | | |
| | | if (netconn_accept(user_data->control_io_listen, &newconn) == ERR_OK) { |
| | |
| | | netconn_delete(newconn); |
| | | } else { |
| | | /* control connection established */ |
| | | SCPI_Event_ControlConnected(NULL, newconn); |
| | | SCPI_Event_ControlConnected(context, newconn); |
| | | ip_set_option(newconn->pcb.tcp, SOF_KEEPALIVE); |
| | | newconn->pcb.tcp->keep_idle = SCPI_KEEP_IDLE; // Override TCP_KEEPIDLE_DEFAULT for this connection. |
| | | newconn->pcb.tcp->keep_intvl = SCPI_KEEP_INTVL; // Override TCP_KEEPINTVL_DEFAULT for this connection. |
| | | newconn->pcb.tcp->keep_cnt = SCPI_KEEP_CNT; // Override TCP_KEEPCNT_DEFAULT for this connection. |
| | | user_data->control_io = newconn; |
| | | } |
| | | } |
| | |
| | | return 0; |
| | | } |
| | | |
| | | static void closeIo(user_data_t * user_data) { |
| | | static void closeIo(scpi_t * context, user_data_t * user_data) { |
| | | /* connection closed */ |
| | | SCPI_Event_DeviceDisconnected(NULL, user_data->io); |
| | | SCPI_Event_DeviceDisconnected(context, user_data->io); |
| | | netconn_close(user_data->io); |
| | | netconn_delete(user_data->io); |
| | | user_data->io = NULL; |
| | | } |
| | | |
| | | static void closeSrqIo(user_data_t * user_data) { |
| | | static void closeSrqIo(scpi_t * context, user_data_t * user_data) { |
| | | /* control connection closed */ |
| | | SCPI_Event_ControlDisconnected(NULL, user_data->io); |
| | | SCPI_Event_ControlDisconnected(context, user_data->io); |
| | | netconn_close(user_data->control_io); |
| | | netconn_delete(user_data->control_io); |
| | | user_data->control_io = NULL; |
| | |
| | | } |
| | | |
| | | if ((user_data.io_listen != NULL) && (evt.cmd == SCPI_MSG_IO_LISTEN)) { |
| | | processIoListen(&user_data); |
| | | processIoListen(&scpi_context, &user_data); |
| | | } |
| | | |
| | | if ((user_data.control_io_listen != NULL) && (evt.cmd == SCPI_MSG_CONTROL_IO_LISTEN)) { |
| | | processSrqIoListen(&user_data); |
| | | processSrqIoListen(&scpi_context, &user_data); |
| | | } |
| | | |
| | | if ((user_data.io != NULL) && (evt.cmd == SCPI_MSG_IO)) { |
| | | processIo(&user_data); |
| | | processIo(&scpi_context, &user_data); |
| | | } |
| | | |
| | | if ((user_data.control_io != NULL) && (evt.cmd == SCPI_MSG_CONTROL_IO)) { |
| | | processSrqIo(&user_data); |
| | | processSrqIo(&scpi_context, &user_data); |
| | | } |
| | | |
| | | if (evt.cmd == SCPI_MSG_SET_ESE_REQ) { |
| | |
| | | |
| | | /* Called by processIoListen() for additional reporting. Override on demand. */ |
| | | void __attribute__((weak)) SCPI_Event_DeviceConnected(scpi_t * context, struct netconn * conn) { |
| | | iprintf("***Connection established %s\r\n", inet_ntoa(newconn->pcb.ip->remote_ip)); |
| | | iprintf("***Connection established %s\r\n", inet_ntoa(newconn->pcb.ip->remote_ip)); |
| | | /* Remote or Eth LED ON */ |
| | | } |
| | | |
| | | /* Called by closeIO() for additional reporting. Override on demand. */ |
| | | void __attribute__((weak)) SCPI_Event_DeviceDisconnected(scpi_t * context, struct netconn * conn) { |
| | | iprintf("***Connection closed\r\n"); |
| | | iprintf("***Connection closed\r\n"); |
| | | /* Remote or Eth LED OFF */ |
| | | } |
| | | |
| | | /* Called by processIoListen() for additional reporting. Override on demand. */ |
| | | void __attribute__((weak)) SCPI_Event_ControlConnected(scpi_t * context, struct netconn * conn) { |
| | | iprintf("***Control Connection established %s\r\n", inet_ntoa(newconn->pcb.ip->remote_ip)); |
| | | iprintf("***Control Connection established %s\r\n", inet_ntoa(newconn->pcb.ip->remote_ip)); |
| | | } |
| | | |
| | | /* Called by closeIO() for additional reporting. Override on demand. */ |
| | | void __attribute__((weak)) SCPI_Event_ControlDisconnected(scpi_t * context, struct netconn * conn) { |
| | | iprintf("***Control Connection closed\r\n"); |
| | | iprintf("***Control Connection closed\r\n"); |
| | | } |
| | | |
| | | /* Called by SCPI_Error() for reporting. Override on demand. */ |
| | | void __attribute__((weak)) SCPI_Event_ErrorIndicatorOn(scpi_t * context, int_fast16_t err) { |
| | | iprintf("**ERROR: %ld, \"%s\"\r\n", (int32_t) err, SCPI_ErrorTranslate(err)); |
| | | iprintf("**ERROR: %ld, \"%s\"\r\n", (int32_t) err, SCPI_ErrorTranslate(err)); |
| | | /* New error : BEEP, Error LED ON */ |
| | | } |
| | | |
| | | /* Called by SCPI_Error() for reporting. Override on demand. */ |
| | | void __attribute__((weak)) SCPI_Event_ErrorIndicatorOff(scpi_t * context, int_fast16_t err) { |
| | | iprintf("**ERROR: %ld, \"%s\"\r\n", (int32_t) err, SCPI_ErrorTranslate(err)); |
| | | iprintf("**ERROR: %ld, \"%s\"\r\n", (int32_t) err, SCPI_ErrorTranslate(err)); |
| | | /* No more errors in the queue : Error LED OFF */ |
| | | } |