Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Samp IDL #305

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ bin/
*.cg
*.asm
/bin
/build/builds
/build/builds

.ipynb_checkpoints
.idea
.project
/**/out/
/**/META-INF/
/**/*.iml
Binary file added resources/SAMP-IDL/IDL_JSAMP_Bridge.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ch.fhnw.jsamp;

import org.astrogrid.samp.Message;
import org.astrogrid.samp.client.AbstractMessageHandler;
import org.astrogrid.samp.client.HubConnection;

import java.util.Map;

public class IDL_MessageHandler extends AbstractMessageHandler {
private Call latestCall = null;

public IDL_MessageHandler(String[] mtypes) {
super(mtypes);
}

@Override
public Map processCall(HubConnection hubConnection, String s, Message message) throws Exception {
latestCall = new Call(hubConnection, s, message);
return null; //new Response(new Message(message.getMType()));
}

class Call {
private HubConnection hubConnection;
private String s;
private Message message;
protected Call(HubConnection hubConnection, String s, Message message) {
this.hubConnection = hubConnection;
this.s = s;
this.message = message;
}

public HubConnection getHubConnection() {
return hubConnection;
}

public String getS() {
return s;
}

public Message getMessage() {
return message;
}
}

public Call getLatestCall() {
Call c = this.latestCall;
latestCall = null;
return c;
}
}
32 changes: 32 additions & 0 deletions resources/SAMP-IDL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# README
This folder contains examples on how to send and receive notifications using SAMP in IDL. In order to receive notifications we use the SAMP hub client *JSAMP* which can be accessed using the *IDL-Java bridge*.

Contents:
**idljava.pro**: Functions for setting up and using JSAMP and VSO
**start.pro**: Example usage of *idljava.pro*
**utils.pro**: General help functions e.g. for `datetime` operations
**IDL_JSAMP_Bridge.jar**: Helper class for accessing received notifications, *compiled with JDK 1.8.0_181*
**IDL_JSAMP_Bridge/src/ch/fhnw/jsamp/IDL_MessageHandler.java**: Source code for helper class
**samp.pro**: Example on how to send notifications to the SAMP hub using pure IDL

### Setup IDL-Java Bridge
1. Download *JSAMP* from their [Official website](http://www.star.bristol.ac.uk/~mbt/jsamp) or from [GitHub](https://github.com/mbtaylor/jsamp)
1. If your IDL is using JRE 1.8 or higher you can use the distributed *IDL_JSAMP_Bridge.jar*. Otherwise you have to tell IDL to use a different JRE (see [IDL-Java Bridge configuration](#idl-java-bridge-configuration)), or you have to compile the class manually using the JDK that matches your IDL's JRE (or lower).
*note: prior to IDL 8.7.1 the default JRE distributed was 1.7*
1. Make sure IDL knows where to find the two .jar files:

Option 1: Set the environment variable `CLASSPATH` **before** IDL initializes the IDL-Java Bridge (currently done in `initialize_IDL_Java_Bridge`)

Option 2: Adjust your IDL-Java Bridge configuration file (see [IDL-Java Bridge configuration](#idl-java-bridge-configuration))

For more informations see [Official reference](https://www.harrisgeospatial.com/docs/initializingtheidl-javabridge.html).

### IDL-Java Bridge configuration
*The configuration file for the IDL-Java Bridge is located in <IDL_DEFAULT>/resource/bridges/import/java* and is called *.idljavabrc* on linux and *idljavabrc* on Windows. If you're using 32-bit IDL on a 64-bit Windows, the file is called *idljavabrc.32*.

The configuration file contains:
* The **JVM Classpath** which should contain all the .jar files you wish to use
* The **JVM LibLocation** which defines the path to the JRE that IDL uses.

These variables can also be overwriten using `SETENV` as it is currently donein `initialize_IDL_Java_Bridge`
For more information see [Official reference](https://www.harrisgeospatial.com/docs/initializingtheidl-javabridge.html) as well as [Changing the Java version used with IDL](https://www.harrisgeospatial.com/Support/Self-Help-Tools/Help-Articles/Help-Articles-Detail/ArtMID/10220/ArticleID/16290/Changing-the-Java-version-used-with-the-IDL-8-Workbench)
110 changes: 110 additions & 0 deletions resources/SAMP-IDL/idljava.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
; how to set up IDL-Java Bridge (https://www.harrisgeospatial.com/docs/initializingtheidl-javabridge.html):
;
; 1. Download JSAMP from http://www.star.bristol.ac.uk/~mbt/jsamp (or Github: https://github.com/mbtaylor/jsamp)
; 2. Adjust jar-file paths for JSAMP and IDL_JSAMP_Bridge (in initialize_IDL_Java_Bridge)
; Remember that this routine needs to be called before anything else is done regarding java
;
; Alternatively to step 2:
; - Go to <IDL_DEFAULT>/resource/bridges/import/java
; - Open your config file (.idljavabrc | idljavabrc | idljavabrc.32), and
; Overwrite the example .jar in the JVM Classpath with the JSAMP .jar
; - (re) start IDL
;
; Attention: if you build IDL_SAMP_Bridge.jar by yourself, make sure your IDL uses the JRE that corresponds to your JDK!
; If you use a newer JDK, change your IDL configuration file (see above) accordingly!
; see also: https://www.harrisgeospatial.com/Support/Self-Help-Tools/Help-Articles/Help-Articles-Detail/ArtMID/10220/ArticleID/16290/Changing-the-Java-version-used-with-the-IDL-8-Workbench


@utils.pro


; IMPORTANT: this needs to be executed before the IDL-JAVA Bridge is loaded, hence before any java class is invoked!
pro initialize_IDL_Java_Bridge
path_to_jsamp = 'C:\Projects\JHV\JHelioviewer\resources\SAMP-IDL\jsamp-1.3.5_signed.jar
path_to_jsamp = path_to_jsamp + ';C:\Projects\JHV\JHelioviewer\resources\SAMP-IDL\IDL_JSAMP_Bridge.jar'
setenv, 'CLASSPATH=' + getenv('CLASSPATH') + path_to_jsamp
end

; create hub client and connect
function start_idljava
initialize_IDL_JAVA_Bridge

jDCP = OBJ_NEW('IDLjavaObject$Static$DEFAULTCLIENTPROFILE', 'org.astrogrid.samp.client.DefaultClientProfile')
jSampHub = OBJ_NEW('IDLjavaObject$JAVA_OASC_HUBCONNECTOR', 'org.astrogrid.samp.client.HubConnector', jDCP->getProfile())
obj_destroy, jDCP

jSampHub->setActive, 1 ; connect to hub

jMsgHandler = OBJ_NEW('IDLjavaObject$MessageHandler', 'ch.fhnw.jsamp.IDL_MessageHandler', ["jhv.vso.load"])
jSampHub->addMessageHandler, jMsgHandler
jSampHub->declareSubscriptions, jSampHub->computeSubscriptions()

return, Hash('hub', jSampHub, 'msgHandler', jMsgHandler)
end

; convert java wrapper object to IDL object
function convert_java_idl, obj
case typename(obj) of ; contrary to switch, case does not need break statements
'IDLJAVAOBJECT$JAVA_LANG_STRING': return, obj->toString()
'IDLJAVAOBJECT$JAVA_UTIL_ARRAYLIST': begin
a = []
foreach elem, obj->toArray() do begin
a = [a, convert_java_idl(elem)]
endforeach
return, a
end
'IDLJAVAOBJECT$JAVA_UTIL_HASHMAP': begin
h = hash()
foreach node, (obj->entrySet())->toArray() do begin
h[(node->getKey())->toString()] = convert_java_idl(node->getValue())
endforeach
return, h
end
endcase

print, "cannot convert object of type '", obj, "': ", obj->toString()
return, !null
end

; check for notifications
function check_notifications, msgHandler
result = !null

jCall = msgHandler->getLatestCall()
if jCall ne !null then begin
msg = jCall->getMessage()
if msg->getMType() eq 'jhv.vso.load' then result = convert_java_idl(msg->getParams())
obj_destroy, msg
endif
obj_destroy, jCall

return, result
end

; blocking, waits until SAMP-HUB sends a notification and returns it
function wait_for_notification, msgHandler
while 1 do begin
n = check_notifications(msgHandler)
if n ne !null then return, n
wait, 0.1
endwhile
return, !null
end

; download images given the timestamp from the layer HASH-object in the time range +- 2 minutes
; usually there is an image every 3 minutes
function get_vso_img, layer
range = date_add(layer['timestamp'], m=-2) + ' - ' + date_add(layer['timestamp'], m=2)
meta = vso_search(date=range, inst=layer['instrument'], wave=layer['measurement']) ; provider=layer['observatory']
img = vso_get(meta[0]) ; downloads first image into cwd
AIA_LCT, wavelnth=LONG(layer['measurement']), /LOAD

return, img
end

; destroy IDL Java-Wrapper objects
; also keep in mind you might want to manually remove the images that were downloaded to the current directory of your IDL Console
pro cleanup_idljava, jSampHub, jMsgHandler
jSampHub->setActive, 0 ; disconnect from hub
obj_destroy, jSampHub, jMsgHandler
end
Loading