go-linux-386 clean
#go-linux-386 build
#strip ${PWD:t}
-go-linux-386 build -ldflags "-s" && rsync -v ${PWD:t} wuzzler.realraum.at:/flash/tuer/
+go-linux-386 build -ldflags "-s" && rsync -v --progress ${PWD:t} wuzzler.realraum.at:/flash/tuer/
go-linux-386 clean
#go-linux-386 build
#strip ${PWD:t}
-go-linux-386 build -ldflags "-s" && rsync -v ${PWD:t} wuzzler.realraum.at:/flash/tuer/
+go-linux-386 build -ldflags "-s" && rsync -v --progress ${PWD:t} wuzzler.realraum.at:/flash/tuer/
serial.WriteString(totty)
serial.Sync()
}
+ close(serial)
}
func serialReader(out chan <- [][]byte, serial * os.File) {
go-linux-386 clean
#go-linux-386 build
#strip ${PWD:t}
-go-linux-386 build -ldflags "-s" && rsync -v ${PWD:t} wuzzler.realraum.at:/flash/tuer/
+go-linux-386 build -ldflags "-s" && rsync -v --progress ${PWD:t} wuzzler.realraum.at:/flash/tuer/
--- /dev/null
+// (c) Bernhard Tittelbach, 2013
+
+package main
+
+import "os"
+import "log"
+import "log/syslog"
+
+type NullWriter struct {}
+func (n *NullWriter) Write(p []byte) (int, error) {return len(p),nil}
+
+var (
+ Syslog_ *log.Logger
+ Debug_ *log.Logger
+)
+
+func init() {
+ Syslog_ = log.New(&NullWriter{}, "", 0)
+ Debug_ = log.New(&NullWriter{}, "", 0)
+}
+
+func LogEnableSyslog() {
+ var logerr error
+ Syslog_, logerr = syslog.NewLogger(syslog.LOG_INFO | (18<<3), 0)
+ if logerr != nil { panic(logerr) }
+}
+
+func LogEnableDebuglog() {
+ Syslog_ = log.New(os.Stdout, "", log.LstdFlags)
+ Debug_ = log.New(os.Stderr, "DEBUG ", log.LstdFlags)
+}
\ No newline at end of file
--- /dev/null
+// (c) Bernhard Tittelbach, 2013
+
+package main
+
+import (
+ "flag"
+)
+
+
+// ---------- Main Code -------------
+
+var (
+ tty_dev_ string
+ pub_addr string
+ use_syslog_ bool
+)
+
+func init() {
+ flag.StringVar(&pub_addr, "brokeraddr", "tcp://torwaechter.realraum.at:4244", "zmq address to send stuff to")
+ flag.StringVar(&tty_dev_, "ttydev", "", "path do tty uc device")
+ flag.BoolVar(&use_syslog_, "syslog", false, "log to syslog local1 facility")
+ //~ flag.Usage = flag.PrintDefaults
+ flag.Parse()
+}
+
+func main() {
+ zmqctx, pub_sock := ZmqsInit(pub_addr)
+ defer zmqctx.Close()
+ defer pub_sock.Close()
+
+ if use_syslog_ {
+ LogEnableSyslog()
+ Syslog_.Print("started")
+ }
+
+ serial_wr, serial_rd, err := OpenAndHandleSerial(tty_dev_)
+ if err != nil { panic(err) }
+ defer close(serial_wr)
+
+ for incoming_ser_line := range(serial_rd) {
+ Syslog_.Printf("%s",incoming_ser_line)
+ if err := pub_sock.Send(incoming_ser_line); err != nil { panic(err) }
+ }
+}
--- /dev/null
+#!/bin/zsh
+export GO386=387
+export CGO_ENABLED=1
+go-linux-386 clean
+go-linux-386 build -ldflags "-s" && rsync -v --progress ${PWD:t} gw.realraum.at:/flash/home/realraum/
--- /dev/null
+// (c) Bernhard Tittelbach, 2013
+
+package main
+
+import (
+ "bufio"
+ "bytes"
+ "os"
+ "svn.spreadspace.org/realraum/go.svn/termios"
+)
+
+
+// ---------- Serial TTY Code -------------
+
+func openTTY(name string) (*os.File, error) {
+ file, err := os.OpenFile(name,os.O_RDWR, 0600) // For read access.
+ if err != nil {
+ Syslog_.Print(err.Error())
+ return nil, err
+ }
+ termios.Ttyfd(file.Fd())
+ termios.SetRaw()
+ return file, nil
+}
+
+func serialWriter(in <- chan string, serial * os.File) {
+ for totty := range(in) {
+ serial.WriteString(totty)
+ serial.Sync()
+ }
+ serial.Close()
+}
+
+func serialReader(out chan <- [][]byte, serial * os.File) {
+ linescanner := bufio.NewScanner(serial)
+ linescanner.Split(bufio.ScanLines)
+ for linescanner.Scan() {
+ if err := linescanner.Err(); err != nil {
+ panic(err.Error())
+ }
+ text := bytes.Fields([]byte(linescanner.Text()))
+ if len(text) == 0 {
+ continue
+ }
+ out <- text
+ }
+}
+
+func OpenAndHandleSerial(filename string) (chan string, chan [][]byte, error) {
+ serial, err :=openTTY(filename)
+ if err != nil {
+ return nil, nil, err
+ }
+ wr := make(chan string, 1)
+ rd := make(chan [][]byte, 20)
+ go serialWriter(wr, serial)
+ go serialReader(rd, serial)
+ return wr, rd, nil
+}
--- /dev/null
+// (c) Bernhard Tittelbach, 2013
+
+package main
+
+import (
+ zmq "github.com/vaughan0/go-zmq"
+ )
+
+// ---------- ZeroMQ Code -------------
+
+func ZmqsInit(pub_addr string) (ctx *zmq.Context, pub_sock *zmq.Socket) {
+ var err error
+ ctx, err = zmq.NewContext()
+ if err != nil {
+ panic(err)
+ }
+ //close only on later panic, otherwise leave open:
+ defer func(){ if r:= recover(); r != nil { ctx.Close(); panic(r) } }()
+
+ if len(pub_addr) > 0 {
+ pub_sock, err = ctx.Socket(zmq.Pub)
+ if err != nil {
+ panic(err)
+ }
+ defer func() { if r:= recover(); r != nil { pub_sock.Close(); panic(r) } }()
+
+ if err = pub_sock.Connect(pub_addr); err != nil {
+ panic(err)
+ }
+ } else {
+ pub_sock = nil
+ }
+
+ return
+}
+
+func zmqsHandleError(chans *zmq.Channels) {
+ for error := range(chans.Errors()) {
+ chans.Close()
+ panic(error)
+ }
+}