json_link
A python package for GridLAB-D data (JSON) link handshaking (over UDP and TCP)
Core Classes:
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)[source]
Bases: json_link.json_link._BaseLink
Implements a GridLAB-D JSON Link Master/client state machine
-
INIT_RECHECK_DELAY = 1
-
beginState(old_state)[source]
beginState state
-
decideInSchema(old_state)[source]
decideInSchema state
-
decideOutSchema(old_state)[source]
decideOutSchema state
-
description_dict = {'application': 'Generic_JSON_Link_Master', 'modelname': '/usr/local/bin/sphinx-build', 'version': '0.9.5a'}
-
go()[source]
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)[source]
Internal Process for master. This version simply fills the schema with dummy data
-
runState(old_state)[source]
Run internal process and sync with remote
-
runWaitSyncReplyState(old_state)[source]
(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)[source]
waitInSchemaReplyState state
-
waitInitReplyState(old_state)[source]
waitInitReplyState state
-
waitOutSchemaReplyState(old_state)[source]
waitOutSchemaReplyState state
-
waitStartReplyState(old_state)[source]
waitStartReplyState state
-
waitTermReplyState(old_state)[source]
waitTermReplyState state
-
class json_link.json_link.SlaveLink(in_schema=None, out_schema=None, **other_args)[source]
Bases: json_link.json_link._BaseLink
Implements a GridLAB-D JSON Link Slave/server state machine
-
beginState(old_state)[source]
beginState state
-
description_dict = {'remote': 'Generic JSON Link Slave/Server', 'version': '0.9.5a'}
-
go()[source]
Begin JSON link Slave state machine execution
-
in_schema = None
-
out_schema = None
-
preInitState(old_state)[source]
preInitState state
-
remote_data = None
-
response_str_in = 'method'
-
response_str_out = 'result'
-
runDoSlave(old_state)[source]
Internal Process for slave. This version simply fills the schema with dummy data
-
runState(old_state)[source]
Run internal process and sync with remote
-
runWaitSyncState(old_state)[source]
sync data with remote
-
rxIgnoreErr()[source]
Robust message receive that ignores timeouts and other errors
-
waitStartState(old_state)[source]
waitStartState state
-
exception json_link.json_link.JsonLinkError[source]
Bases: builtins.OSError
Base class for exceptions in the gld_json_link module
-
code = 2000
-
exception json_link.json_link.JsonLinkTimeoutError[source]
Bases: json_link.json_link.JsonLinkError
Timeout waiting for reply
-
code = 2001
-
exception json_link.json_link.JsonLinkNoDataError[source]
Bases: json_link.json_link.JsonLinkError
Expected data is empty
-
code = 2002
-
exception json_link.json_link.JsonLinkBadWrapperError[source]
Bases: json_link.json_link.JsonLinkError
Malformed wrapper
-
code = 2003
-
exception json_link.json_link.JsonLinkRemoteError[source]
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[source]
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[source]
Bases: json_link.json_link.JsonLinkError
Incorrect handshaking order
-
code = 2006
-
json_link.json_link.dummyData(schema)[source]
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