1 // (c) Bernhard Tittelbach, 2013
12 pubsub "github.com/tuxychandru/pubsub"
15 //~ func StringArrayToByteArray(ss []string) [][]byte {
16 //~ bb := make([][]byte, len(ss))
17 //~ for index, s := range(ss) {
18 //~ bb[index] = []byte(s)
23 // ---------- Main Code -------------
27 sensorssub_port_ string
29 keylookup_addr_ string
35 fmt.Fprintf(os.Stderr, "Usage: zmq_broker_event_transformer [options]\n")
40 flag.StringVar(&doorsub_addr_, "doorsubaddr", "tcp://torwaechter.realraum.at:4242", "zmq door event publish addr")
41 flag.StringVar(&sensorssub_port_, "sensorsubport", "tcp://*:4243", "zmq public/listen socket addr for incoming sensor data")
42 flag.StringVar(&pub_port_, "pubport", "tcp://*:4244", "zmq port publishing consodilated events")
43 flag.StringVar(&keylookup_addr_, "keylookupaddr", "ipc:///run/tuer/door_keyname.ipc", "address to use for key/name lookups")
44 flag.BoolVar(&use_syslog_, "syslog", false, "log to syslog local2 facility")
50 zmqctx, sub_in_chans, pub_out_socket, keylookup_socket := ZmqsInit(doorsub_addr_, sensorssub_port_, pub_port_, keylookup_addr_)
51 if sub_in_chans != nil {defer sub_in_chans.Close()}
53 if pub_out_socket != nil {defer pub_out_socket.Close()}
54 if keylookup_socket != nil {defer keylookup_socket.Close()}
55 if sub_in_chans == nil || pub_out_socket == nil || keylookup_socket == nil {
56 panic("zmq sockets must not be nil !!")
60 Syslog_, logerr = syslog.NewLogger(syslog.LOG_INFO | (18<<3), 0)
61 //~ Syslog_, logerr = syslog.NewLogger(syslog.LOG_INFO | syslog.LOG_LOCAL2, 0)
62 if logerr != nil { panic(logerr) }
63 Syslog_.Print("started")
64 defer Syslog_.Print("exiting")
68 //~ ticker := time.NewTicker(time.Duration(5) * time.Minute)
69 publish_these_events_chan := ps.Sub("door", "doorcmd", "presence", "sensors", "buttons", "movement")
71 go MetaEventRoutine_Movement(ps, 10, 20, 10)
72 go MetaEventRoutine_Presence(ps)
76 case subin := <- sub_in_chans.In():
77 ParseSocketInputLine(subin, ps, keylookup_socket)
80 case event_interface := <- publish_these_events_chan:
81 data, err := FormatEventForSocket(event_interface)
82 log.Printf("publishing %s",data)
84 if Syslog_ != nil {Syslog_.Print(err)}
87 if err := pub_out_socket.Send(data); err != nil {