#  -*- mode: org -*-

* Specification at scanner initialization

SDO requests are registered in the scanner configuration

The section <sdorequests> is parsed to the configuration structures

Example:

<sdorequests>
  <sdo name="DOX Settings Ch. 1" slave="EA1.11" index="0x8000" >
    <sdoentry description="Voltage Output" subindex="0x8" bit_length="8" 
              asynparameter="voltage"/>
  </sdo>
</sdorequests>

* SDO size supported

The Ethercat specification supports any size SDO.
This implementation limits the support to 32-bit entries, because of
the use of asynInt32 parameters in the EPICS side.

For example, the table below shows the types of SDOS in the EL2595
and the range supported.

| type         | bit_length | supported (Y/N) |
|--------------+------------+-----------------|
| type 0000    | 0 bit      | Y               |
| bool         | 1 bit      | Y               |
| type 0000    | 2 bit      | Y               |
| type 0000    | 3 bit      | Y               |
| type 0000    | 4 bit      | Y               |
| type 0000    | 5 bit      | Y               |
| type 0000    | 7 bit      | Y               |
| uint8        | 8 bit      | Y               |
| string       | 16 bit     | Y               |
| uint32       | 32 bit     | Y               |
| string       | 48 bit     | NO              |
| uint64       | 64 bit     | NO              |
| octet_string | 224 bit    | NO              |

* Scanner to EPICS communications

These message types are used:

MSG_SDO_REQ    a read request from the client (EPICS)
MSG_SDO_WRITE  a write request from the client (EPICS)
MSG_SDO_READ   an answer from the scanner

The request can be in one of these states (ethercat library's
ec_requets_state_t)

    EC_REQUEST_UNUSED, /**< Not requested. */
    EC_REQUEST_BUSY, /**< Request is being processed. */
    EC_REQUEST_SUCCESS, /**< Request was processed successfully. */
    EC_REQUEST_ERROR, /**< Request processing failed. */

* Read request

An EPICS record is processed for a read request.

e.g.
record(longin, "DEVICE:OUTPUT_VOLTAGE")
{
   field(DTYP, "asynInt32")
   field(INP, "@asyn(ERIO.1)voltage")
   field(SCAN, "1 second")
}

record(mbbi, "DEVICE:OUTPUT_VOLTAGE:STAT")
{
    field(DTYP, "asynInt32")
    field(INP, "@asyn(ERIO.1)voltage_stat)
    field(SCAN, "1 second")
    field("ONVL", "0")
    field("TWVL", "1")
    field("THVL", "2")
    field("FRVL", "3")
    field("ONST", "UNUSED")
    field("TWST", "BUSY")
    field("THST", "SUCCESS")
    field("FRST", "ERROR")
}

* Write request

Example EPICS record for read/write.

record(longout, "DEVICE:OUTPUT_VOLTAGE")
{
   field(DTYP, "asynInt32")
   field(INP, "@asyn(ERIO.1)voltage")
   field(OMSL, "supervisory")
}



* read request in cyclic_task

The cyclic task in the scanner will retrieve the status of the sdo
requests on every tick (function gather_sdo_states)

The function gather_sdo_states also marks a flag for requests for
which the state has changed. These should generate an answer from the
scanner, which is an MSG_SDO_READ message to return to the clients.

When a MSG_SDO_REQ message arrives, the request will be registered in
using the process_sdo_read_request function that will issue a read
request only when the associated state for the request is not busy.


* use of the "flag" in the sdoentry structure

The sdoentry structure keeps the current state of the request (state
field) and the old state of the request.

The flag is used to register that a request to read this sdo has been
received.

* write sdo requests from IOC

The IOC "engine" has two methods

** ioc_send/pdo_data
   These functions process messages from the receive buffer, that is
   packets sent by the scanner.
   For SDOs these will be replies from the scanner about status of
   the read request and a value.

** ioc_receive
   This function add messages to the writeq, from the send_buffer.
   For SDOs, these will be the read requests and write requests.

* Separate asyn port class for SDO requests

The class ecSdoAsyn implements the blocking port for the sdo
read/write requests.

An instance will be created by its parent ecAsyn port class if there
are sdos registered for that port (sdos > 0). (Implementation in
readConfig function in ecAsyn.cpp)

The class instance receives messages from the scanner.
All instances are registered in the list sdo_observers list and
implement the on_sdo_message method.

TODO: 
1. read method to send a SDO_REQ_MESSAGE in ecSdoAsyn
2. write method to send a SDO_WRITE_MESSAGE in ecSdoAsyn
3. callback part that queues SDO_READ_MESSAGE to send back from
ecSdoAsyn to EPICS


