### Navigation

- index
- modules |
- next |
- previous |
- JSON Link 0.9.2a documentation »

# json_link Package

## `json_link` Module

### json_link

A python package for GridLAB-D data (JSON) link handshaking (over UDP and TCP)

Core Classes:

- `MasterLink`
- `SlaveLink`

Related Functions:

Notes:

- Should work with Python 2.6+ and 3.x. Tested with 2.7.2 and 3.3
- Currently only supports IPv4
- The SLAVE will handle connections from any number of masters, BUT since the code is only single threaded each processing (including delay) are blocking. Hence, the SLAVE may miss packets if it is busy processing (or waiting to send) a different reply.

@author: Bryan Palmintier, NREL 2013

class `json_link.json_link.``MasterLink`(in_schema=None, out_schema=None, schema_to_send='', **Other_args)

  Bases: `json_link.json_link._BaseLink`

  Implements a GridLAB-D JSON Link Master/client state machine

  `INIT_RECHECK_DELAY` = 1
  `beginState`(old_state)

    beginState state

  `decideInSchema`(old_state)

    decideInSchema state

  `decideOutSchema`(old_state)

    decideOutSchema state

  `description_dict` = {'application': 'Generic_JSON_Link_Master', 'modelname': '/usr/local/bin/sphinx-build', 'version': '0.9.5a'}
  `go`()

    Begin JSON link Master state machine execution

  `in_schema` = {'y0': 'double test_0.y', 'y1': 'double test_1.y', 'clock': 'timestamp global.clock'}
  `local_data` = None
  `out_schema` = {'x1': 'random test_1.y', 'x0': 'random test_0.x', 'clock': 'timestamp global.clock'}
  `remote_data` = None
  `response_str_in` = 'result'
  `response_str_out` = 'method'
  `runDoMaster`(old_state)

    Internal Process for master. This version simply fills the schema with dummy data

  `runState`(old_state)

    Run internal process and sync with remote

  `runWaitSyncReplyState`(old_state)

    (Master) wait for remote to reply with sync data

  `sendAndWait`(action, out_data_type=None, in_data_type='__SAME__', to_send=None, max_retry=1, retry_msg='')

    Waits for slave reply and handles errors and retry

  `send_in_schema` = False
  `send_out_schema` = False
  `waitInSchemaReplyState`(old_state)

    waitInSchemaReplyState state

  `waitInitReplyState`(old_state)

    waitInitReplyState state

  `waitOutSchemaReplyState`(old_state)

    waitOutSchemaReplyState state

  `waitStartReplyState`(old_state)

    waitStartReplyState state

  `waitTermReplyState`(old_state)

    waitTermReplyState state

class `json_link.json_link.``SlaveLink`(in_schema=None, out_schema=None, **other_args)

  Bases: `json_link.json_link._BaseLink`

  Implements a GridLAB-D JSON Link Slave/server state machine

  `beginState`(old_state)

    beginState state

  `description_dict` = {'remote': 'Generic JSON Link Slave/Server', 'version': '0.9.5a'}
  `go`()

    Begin JSON link Slave state machine execution

  `in_schema` = None
  `out_schema` = None
  `preInitState`(old_state)

    preInitState state

  `remote_data` = None
  `response_str_in` = 'method'
  `response_str_out` = 'result'
  `runDoSlave`(old_state)

    Internal Process for slave. This version simply fills the schema with dummy data

  `runState`(old_state)

    Run internal process and sync with remote

  `runWaitSyncState`(old_state)

    sync data with remote

  `rxIgnoreErr`()

    Robust message receive that ignores timeouts and other errors

  `waitStartState`(old_state)

    waitStartState state

exception `json_link.json_link.``JsonLinkError`

  Bases: `builtins.OSError`

  Base class for exceptions in the gld_json_link module

  `code` = 2000

exception `json_link.json_link.``JsonLinkTimeoutError`

  Bases: `json_link.json_link.JsonLinkError`

  Timeout waiting for reply

  `code` = 2001

exception `json_link.json_link.``JsonLinkNoDataError`

  Bases: `json_link.json_link.JsonLinkError`

  Expected data is empty

  `code` = 2002

exception `json_link.json_link.``JsonLinkBadWrapperError`

  Bases: `json_link.json_link.JsonLinkError`

  Malformed wrapper

  `code` = 2003

exception `json_link.json_link.``JsonLinkRemoteError`

  Bases: `json_link.json_link.JsonLinkError`

  received a (reasonably) well formed error packet from the remote machine

  `code` = 2004

exception `json_link.json_link.``JsonLinkOldMsgError`

  Bases: `json_link.json_link.JsonLinkError`

  Received a message with id older than a previously processed message

  `code` = 2005

exception `json_link.json_link.``JsonLinkActionMismatchError`

  Bases: `json_link.json_link.JsonLinkError`

  Incorrect handshaking order

  `code` = 2006

`json_link.json_link.``dummyData`(schema)

  Build up dummy json data package based on the provided schema

`json_link.json_link.``loadJsonStrOrFile`(in_str)

  Examines a string to see if it is a valid JSON string, if not it assumes the string corresponds to a filename and attempts to load it and process its contents as JSON

  First attempts to unquote the string for improved command line processing support

  Note that the terminal may do some pre-processing of the command line, including stripping embedded double quotes. As a result this function attempts to put double quotes around names and non-numeric values

## Subpackages

- bin Package
  - `json_link_tester` Module
    - json_link_tester
      - Basic UDP slave
      - Basic UDP master
      - Additional Options
        - Transfer Setup
        - Debugging Information Display
        - Run timing
      - Notes
- faults Package
  - `fault_inject` Module
    - Fault Inject
- test Package
- xchg Package
  - `raw_xchg` Module

### Navigation

- index
- modules |
- next |
- previous |
- JSON Link 0.9.2a documentation »