From 0ae7860ca033f98cfb98721ebb0d4b2b42700d40 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Sat, 5 Oct 2013 00:41:24 +0000 Subject: [PATCH] more proper import --- go/r3-eventbroker_zmq/main.go | 2 +- go/r3-eventbroker_zmq/metamovement.go | 2 +- go/r3-eventbroker_zmq/presence.go | 2 +- go/r3-eventbroker_zmq/r3events/basicevents.go | 56 -------------- go/r3-eventbroker_zmq/r3events/marshal_events.go | 88 ---------------------- go/r3-eventbroker_zmq/r3events/metaevents.go | 13 ---- go/r3-eventbroker_zmq/smallbrain.go | 2 +- go/r3-eventbroker_zmq/sockettoevent.go | 2 +- go/r3-netstatus/main.go | 2 +- go/r3-netstatus/webstatus.go | 2 +- go/r3events/basicevents.go | 56 ++++++++++++++ go/r3events/marshal_events.go | 88 ++++++++++++++++++++++ go/r3events/metaevents.go | 13 ++++ 13 files changed, 164 insertions(+), 164 deletions(-) delete mode 100644 go/r3-eventbroker_zmq/r3events/basicevents.go delete mode 100644 go/r3-eventbroker_zmq/r3events/marshal_events.go delete mode 100644 go/r3-eventbroker_zmq/r3events/metaevents.go create mode 100644 go/r3events/basicevents.go create mode 100644 go/r3events/marshal_events.go create mode 100644 go/r3events/metaevents.go diff --git a/go/r3-eventbroker_zmq/main.go b/go/r3-eventbroker_zmq/main.go index 10c87dc..0495edd 100644 --- a/go/r3-eventbroker_zmq/main.go +++ b/go/r3-eventbroker_zmq/main.go @@ -8,7 +8,7 @@ import ( "flag" //~ "time" pubsub "github.com/tuxychandru/pubsub" - r3events "svn.spreadspace.org/realraum/go.svn/r3-eventbroker_zmq/r3events" + r3events "svn.spreadspace.org/realraum/go.svn/r3events" ) //~ func StringArrayToByteArray(ss []string) [][]byte { diff --git a/go/r3-eventbroker_zmq/metamovement.go b/go/r3-eventbroker_zmq/metamovement.go index ecde4cb..b274092 100644 --- a/go/r3-eventbroker_zmq/metamovement.go +++ b/go/r3-eventbroker_zmq/metamovement.go @@ -7,7 +7,7 @@ import ( //~ "./brain" pubsub "github.com/tuxychandru/pubsub" "container/ring" - r3events "svn.spreadspace.org/realraum/go.svn/r3-eventbroker_zmq/r3events" + r3events "svn.spreadspace.org/realraum/go.svn/r3events" ) diff --git a/go/r3-eventbroker_zmq/presence.go b/go/r3-eventbroker_zmq/presence.go index a879332..d65788d 100644 --- a/go/r3-eventbroker_zmq/presence.go +++ b/go/r3-eventbroker_zmq/presence.go @@ -6,7 +6,7 @@ import ( "time" //~ "./brain" pubsub "github.com/tuxychandru/pubsub" - r3events "svn.spreadspace.org/realraum/go.svn/r3-eventbroker_zmq/r3events" + r3events "svn.spreadspace.org/realraum/go.svn/r3events" ) func MetaEventRoutine_Presence(ps *pubsub.PubSub) { diff --git a/go/r3-eventbroker_zmq/r3events/basicevents.go b/go/r3-eventbroker_zmq/r3events/basicevents.go deleted file mode 100644 index 73776cb..0000000 --- a/go/r3-eventbroker_zmq/r3events/basicevents.go +++ /dev/null @@ -1,56 +0,0 @@ -// (c) Bernhard Tittelbach, 2013 - -package r3events - - -type DoorLockUpdate struct { - Locked bool - Ts int64 -} - -type DoorAjarUpdate struct { - Shut bool - Ts int64 -} - -type BackdoorAjarUpdate struct { - Shut bool - Ts int64 -} - -type DoorCommandEvent struct { - Command string - Using string - Who string - Ts int64 -} - -type DoorProblemEvent struct { - Severity int - Ts int64 -} - -type BoreDoomButtonPressEvent struct { - Ts int64 -} - -type TempSensorUpdate struct { - Sensorindex int - Value float64 - Ts int64 -} - -type IlluminationSensorUpdate struct { - Sensorindex int - Value int64 - Ts int64 -} - -type TimeTick struct { - Ts int64 -} - -type MovementSensorUpdate struct { - Sensorindex int - Ts int64 -} \ No newline at end of file diff --git a/go/r3-eventbroker_zmq/r3events/marshal_events.go b/go/r3-eventbroker_zmq/r3events/marshal_events.go deleted file mode 100644 index 830ff6b..0000000 --- a/go/r3-eventbroker_zmq/r3events/marshal_events.go +++ /dev/null @@ -1,88 +0,0 @@ -// (c) Bernhard Tittelbach, 2013 - -package r3events - -import ( - "encoding/json" - "fmt" - "errors" - "strings" - ) - -func NameOfStruct(evi interface{}) (name string) { - etype := fmt.Sprintf("%T", evi) - etype_lastsep := strings.LastIndex(etype,".") - return etype[etype_lastsep+1:] //works in all cases for etype_lastsep in range -1 to len(etype)-1 -} - -func MarshalEvent2ByteByte(event_interface interface{}) (data [][]byte, err error) { - var msg []byte - //~ fmt.Printf("%T%+v\n", event_interface, event_interface) - msg, err = json.Marshal(event_interface) - if err != nil { - return - } - data = [][]byte{[]byte(NameOfStruct(event_interface)), msg} //works in all cases for etype_lastsep in range -1 to len(etype)-1 - return -} - -func UnmarshalByteByte2Event(data [][]byte) (event interface{}, category string, err error) { - if len(data) != 2 { - return nil, "", errors.New("not a r3event message") - } - switch string(data[0]) { - case "DoorLockUpdate": - event = DoorLockUpdate{} - err = json.Unmarshal(data[1],&event) - category = "door" - case "DoorAjarUpdate": - event := DoorAjarUpdate{} - err = json.Unmarshal(data[1], &event) - category = "door" - case "BackdoorAjarUpdate": - event := DoorAjarUpdate{} - err = json.Unmarshal(data[1], &event) - category = "door" - case "DoorCommandEvent": - event := DoorCommandEvent{} - err = json.Unmarshal(data[1], &event) - category = "door" - case "DoorProblemEvent": - event := DoorProblemEvent{} - err = json.Unmarshal(data[1], &event) - category = "door" - case "BoreDoomButtonPressEvent": - event := BoreDoomButtonPressEvent{} - err = json.Unmarshal(data[1], &event) - category = "buttons" - case "TempSensorUpdate": - event := TempSensorUpdate{} - err = json.Unmarshal(data[1], &event) - category = "sensors" - case "IlluminationSensorUpdate": - event := IlluminationSensorUpdate{} - err = json.Unmarshal(data[1], &event) - category = "sensors" - case "TimeTick": - event := TimeTick{} - err = json.Unmarshal(data[1], &event) - category = "time" - case "MovementSensorUpdate": - event := MovementSensorUpdate{} - err = json.Unmarshal(data[1], &event) - category = "movement" - case "PresenceUpdate": - event := PresenceUpdate{} - err = json.Unmarshal(data[1], &event) - category = "presence" - case "SomethingReallyIsMoving": - event := SomethingReallyIsMoving{} - err = json.Unmarshal(data[1], &event) - category = "movement" - default: - event = nil - err = errors.New("cannot unmarshal unknown type") - category = "" - } - return -} diff --git a/go/r3-eventbroker_zmq/r3events/metaevents.go b/go/r3-eventbroker_zmq/r3events/metaevents.go deleted file mode 100644 index c22a79d..0000000 --- a/go/r3-eventbroker_zmq/r3events/metaevents.go +++ /dev/null @@ -1,13 +0,0 @@ -// (c) Bernhard Tittelbach, 2013 - -package r3events - -type PresenceUpdate struct { - Present bool - Ts int64 -} - -type SomethingReallyIsMoving struct { - Movement bool - Ts int64 -} \ No newline at end of file diff --git a/go/r3-eventbroker_zmq/smallbrain.go b/go/r3-eventbroker_zmq/smallbrain.go index c8ef95a..4a7cdeb 100644 --- a/go/r3-eventbroker_zmq/smallbrain.go +++ b/go/r3-eventbroker_zmq/smallbrain.go @@ -4,7 +4,7 @@ package main import ( zmq "github.com/vaughan0/go-zmq" - r3events "svn.spreadspace.org/realraum/go.svn/r3-eventbroker_zmq/r3events" + r3events "svn.spreadspace.org/realraum/go.svn/r3events" ) type hippocampus map[string]interface{} diff --git a/go/r3-eventbroker_zmq/sockettoevent.go b/go/r3-eventbroker_zmq/sockettoevent.go index 37686b8..3836580 100644 --- a/go/r3-eventbroker_zmq/sockettoevent.go +++ b/go/r3-eventbroker_zmq/sockettoevent.go @@ -9,7 +9,7 @@ import ( //~ "./brain" pubsub "github.com/tuxychandru/pubsub" zmq "github.com/vaughan0/go-zmq" - r3events "svn.spreadspace.org/realraum/go.svn/r3-eventbroker_zmq/r3events" + r3events "svn.spreadspace.org/realraum/go.svn/r3events" ) var ( diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index 0a4b0c9..0af7ef8 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -9,7 +9,7 @@ import ( "time" "fmt" //~ "./brain" - r3events "svn.spreadspace.org/realraum/go.svn/r3-eventbroker_zmq/r3events" + r3events "svn.spreadspace.org/realraum/go.svn/r3events" ) type SpaceState struct { diff --git a/go/r3-netstatus/webstatus.go b/go/r3-netstatus/webstatus.go index 53ff92d..d29fe02 100644 --- a/go/r3-netstatus/webstatus.go +++ b/go/r3-netstatus/webstatus.go @@ -9,7 +9,7 @@ import ( "net/http" "net/url" "time" - r3events "svn.spreadspace.org/realraum/go.svn/r3-eventbroker_zmq/r3events" + r3events "svn.spreadspace.org/realraum/go.svn/r3events" ) diff --git a/go/r3events/basicevents.go b/go/r3events/basicevents.go new file mode 100644 index 0000000..73776cb --- /dev/null +++ b/go/r3events/basicevents.go @@ -0,0 +1,56 @@ +// (c) Bernhard Tittelbach, 2013 + +package r3events + + +type DoorLockUpdate struct { + Locked bool + Ts int64 +} + +type DoorAjarUpdate struct { + Shut bool + Ts int64 +} + +type BackdoorAjarUpdate struct { + Shut bool + Ts int64 +} + +type DoorCommandEvent struct { + Command string + Using string + Who string + Ts int64 +} + +type DoorProblemEvent struct { + Severity int + Ts int64 +} + +type BoreDoomButtonPressEvent struct { + Ts int64 +} + +type TempSensorUpdate struct { + Sensorindex int + Value float64 + Ts int64 +} + +type IlluminationSensorUpdate struct { + Sensorindex int + Value int64 + Ts int64 +} + +type TimeTick struct { + Ts int64 +} + +type MovementSensorUpdate struct { + Sensorindex int + Ts int64 +} \ No newline at end of file diff --git a/go/r3events/marshal_events.go b/go/r3events/marshal_events.go new file mode 100644 index 0000000..830ff6b --- /dev/null +++ b/go/r3events/marshal_events.go @@ -0,0 +1,88 @@ +// (c) Bernhard Tittelbach, 2013 + +package r3events + +import ( + "encoding/json" + "fmt" + "errors" + "strings" + ) + +func NameOfStruct(evi interface{}) (name string) { + etype := fmt.Sprintf("%T", evi) + etype_lastsep := strings.LastIndex(etype,".") + return etype[etype_lastsep+1:] //works in all cases for etype_lastsep in range -1 to len(etype)-1 +} + +func MarshalEvent2ByteByte(event_interface interface{}) (data [][]byte, err error) { + var msg []byte + //~ fmt.Printf("%T%+v\n", event_interface, event_interface) + msg, err = json.Marshal(event_interface) + if err != nil { + return + } + data = [][]byte{[]byte(NameOfStruct(event_interface)), msg} //works in all cases for etype_lastsep in range -1 to len(etype)-1 + return +} + +func UnmarshalByteByte2Event(data [][]byte) (event interface{}, category string, err error) { + if len(data) != 2 { + return nil, "", errors.New("not a r3event message") + } + switch string(data[0]) { + case "DoorLockUpdate": + event = DoorLockUpdate{} + err = json.Unmarshal(data[1],&event) + category = "door" + case "DoorAjarUpdate": + event := DoorAjarUpdate{} + err = json.Unmarshal(data[1], &event) + category = "door" + case "BackdoorAjarUpdate": + event := DoorAjarUpdate{} + err = json.Unmarshal(data[1], &event) + category = "door" + case "DoorCommandEvent": + event := DoorCommandEvent{} + err = json.Unmarshal(data[1], &event) + category = "door" + case "DoorProblemEvent": + event := DoorProblemEvent{} + err = json.Unmarshal(data[1], &event) + category = "door" + case "BoreDoomButtonPressEvent": + event := BoreDoomButtonPressEvent{} + err = json.Unmarshal(data[1], &event) + category = "buttons" + case "TempSensorUpdate": + event := TempSensorUpdate{} + err = json.Unmarshal(data[1], &event) + category = "sensors" + case "IlluminationSensorUpdate": + event := IlluminationSensorUpdate{} + err = json.Unmarshal(data[1], &event) + category = "sensors" + case "TimeTick": + event := TimeTick{} + err = json.Unmarshal(data[1], &event) + category = "time" + case "MovementSensorUpdate": + event := MovementSensorUpdate{} + err = json.Unmarshal(data[1], &event) + category = "movement" + case "PresenceUpdate": + event := PresenceUpdate{} + err = json.Unmarshal(data[1], &event) + category = "presence" + case "SomethingReallyIsMoving": + event := SomethingReallyIsMoving{} + err = json.Unmarshal(data[1], &event) + category = "movement" + default: + event = nil + err = errors.New("cannot unmarshal unknown type") + category = "" + } + return +} diff --git a/go/r3events/metaevents.go b/go/r3events/metaevents.go new file mode 100644 index 0000000..c22a79d --- /dev/null +++ b/go/r3events/metaevents.go @@ -0,0 +1,13 @@ +// (c) Bernhard Tittelbach, 2013 + +package r3events + +type PresenceUpdate struct { + Present bool + Ts int64 +} + +type SomethingReallyIsMoving struct { + Movement bool + Ts int64 +} \ No newline at end of file -- 1.7.10.4