Bitcoin Forum

Economy => Marketplace => Topic started by: Frozenlock on May 31, 2011, 12:29:41 AM



Title: [15 BTC bounty] A tutorial for simple functions in Clojure (and BACnet)
Post by: Frozenlock on May 31, 2011, 12:29:41 AM
Here's the deal: I want to be able to create some input/output with some descriptions in BACnet. (http://en.wikipedia.org/wiki/BACnet (http://en.wikipedia.org/wiki/BACnet))
For this, I want to use Clojure. My devices are located in my LAN (so any Ethernet implementation should work, but feel free to use IP if needed).

There's already some libraries written for BACnet, such as this one http://sourceforge.net/projects/bacnet4j/ (http://sourceforge.net/projects/bacnet4j/) in java (which, as I understand, should be easy to use with Clojure), and this one http://sourceforge.net/projects/bacnet/ (http://sourceforge.net/projects/bacnet/) in C.

So the goal is: I put an input in a Clojure function, it creates my input and I then can add a description.
However I'm pretty sure you don't have BACnet devices laying around, so a simple proof of concept from one function to another is sufficient.

What's the catch?
I'm awful.
This means I require a tutorial:
  • Start the project with Leiningen
  • How to include the existing library
  • How to find the required functions
  • Write the Clojure functions
  • Test them
  • Creating an independent .jar would be nice..

That's it.

I would like if you could use Emacs, but I left this as a choice.

I will post the accepted tutorial here, available for all. You can post it on your own blog if you want, although I would appreciate if you could say I financed it and put this Bitcoin address for any thanks: 1nZJ4JJTxwt4XZ7N39j3EHaVojBHMvZVK
[/list]


Title: Re: [PENDING-20 BTC bounty] A tutorial for simple functions in Clojure (and BACnet)
Post by: Frozenlock on June 18, 2011, 12:27:51 AM
Hello all!

A great fellow sent me a quick draft.
It didn't fully fulfill my desires, but I still sent him 5 BTC. The bounty is now [15 BTC]!

Here is what I have so far:

Quote
1. Install leiningen. That is, download the script from
   https://github.com/technomancy/leiningen
   and run 'lein self-install'

2. Create a project, for example:
   lein new clj-bacnet
   to create a project skeleton in clj-bacnet directory

3. Add bacnet4j as dependency.
   Leiningen prefers to obtain its dependencies from a maven repository.
   Since I didn't find any, I took the liberty of adding a copy of bacnet4j
   to the clojars.org repository.

   After adding the bacnet dependency your project.clj should look like this:

(defproject clj-bacnet "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.2.1"]
                 [org.clojars.jarpiain/bacnet4j "1.2.0"]
                 [org.clojars.jarpiain/sero-utils "1.0.0."]])

4. Run 'lein deps' to download the bacnet jars (and a copy of clojure)
   to your project directory

Now you can run 'lein repl' and start playing with bacnet4j objects

For example,

(com.serotonin.bacnet4j.Network. 1 (byte-array (map byte [127 0 0 1])))

creates a new Network object
#<Network Network(networkNumber=1, networkAddress=[7f,0,0,1])>

and

(.getNetworkAddress *1)

calls the getNetworkAddress method on it.

To avoid typing the package name, enter e.g.

(import '[com.serotonin.bacnet4j Network LocalDevice RemoteDevice])

in the REPL. Then the previous example would look like
(Network. 1 (byte-array (map byte [127 0 0 1])))

Leiningen created a src/clj_bacnet/core.clj in the project
and you can add the import declaration

(ns clj.bacnet.core
  (:import [com.serotonin.bacnet4j Network LocalDevice RemoteDevice]))

to use the short names in your code.

With emacs and SLIME you can add lein-swank as a dependency and start
a swank server with 'lein swank' and then connect from emacs as explained in
http://data-sorcery.org/2009/12/22/lein-swank/

Please note that it took me quite a while to wrap my head around this; I really need things to be explained in details.

The next step should be to create and test the clojure functions. This is where a BACnet knowledge could be handy, if you have any.

Godspeed!


Title: Re: [15 BTC bounty] A tutorial for simple functions in Clojure (and BACnet)
Post by: rx7yt on June 18, 2011, 12:26:58 PM
 i can finish this if need be.  i will start working on it now and you will get a finished copy by the end of the day


Title: Re: [15 BTC bounty] A tutorial for simple functions in Clojure (and BACnet)
Post by: Frozenlock on June 26, 2011, 04:01:25 AM
The bounty is still available!