Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangMau committed Jan 20, 2018
0 parents commit d668b91
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .circleci/circleci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.9
working_directory: /go/src/github.com/WolfgangMau/chamg
steps:
- checkout
- run: make
- store_artifacts:
path: ./build
release:
docker:
- image: circleci/golang:1.9
working_directory: /go/src/github.com/WolfgangMau/chamg
steps:
- checkout
- run: make package
- run: go get github.com/aktau/github-release
- run: github-release info --user ${CIRCLE_PROJECT_USERNAME} --repo ${CIRCLE_PROJECT_REPONAME}
- run: github-release release --user ${CIRCLE_PROJECT_USERNAME} --repo ${CIRCLE_PROJECT_REPONAME} --tag ${CIRCLE_TAG} --name ${CIRCLE_TAG} --description ${CIRCLE_TAG} --pre-release
- run: for f in build/*.tar.gz; do github-release upload --user ${CIRCLE_PROJECT_USERNAME} --repo ${CIRCLE_PROJECT_REPONAME} --tag ${CIRCLE_TAG} --name `basename ${f}` --file ${f}; done
- run: github-release edit --user ${CIRCLE_PROJECT_USERNAME} --repo ${CIRCLE_PROJECT_REPONAME} --tag ${CIRCLE_TAG} --name ${CIRCLE_TAG} --description ${CIRCLE_TAG}

workflows:
version: 2
build_and_release:
jobs:
- build:
filters:
tags:
only: /.*/
- release:
requires:
- build
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
branches:
ignore: /.*/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/github.com/tarm/serial"]
path = vendor/github.com/tarm/serial
url = https://github.com/tarm/serial
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
SHELL := /bin/bash

# The destination for binaries
BUILD_DIR = build

# The name of the executable (default is current directory name)
TARGET := $(shell echo $${PWD\#\#*/})
.DEFAULT_GOAL: $(TARGET)

# These will be provided to the target
VERSION :=0.9.0-rc1
BUILD := `git rev-parse HEAD`

# Use linker flags to provide version/build settings to the target
LDFLAGS=-ldflags "-X=main.Version=$(VERSION) -X=main.Build=$(BUILD)"

# go source files, ignore vendor directory
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")

.PHONY: all build clean install uninstall fmt simplify check run

all: check compile

$(TARGET): $(SRC)
@go build $(LDFLAGS) -o $(TARGET)

compile: check goxcompile

goxcompile: export CGO_ENABLED=1
goxcompile: dependencies
gox -arch amd64 -os 'darwin linux' -osarch 'windows/386' -output "$(BUILD_DIR)/{{.OS}}/$(NAME)/${TARGET}" .

clean:
@rm -f $(TARGET)
@rm -rf $(BUILD_DIR)

install: dependencies
@go install $(LDFLAGS)

uninstall: clean
@rm -f $$(which ${TARGET})

fmt:
@gofmt -l -w $(SRC)

simplify:
@gofmt -s -l -w $(SRC)

package: compile
@for d in $$(ls build); do tar -czf $(BUILD_DIR)/${TARGET}-$${d}.tar.gz -C $(BUILD_DIR)/$${d} .; done

check: dependencies
@test -z $(shell gofmt -l ${TARGET}.go | tee /dev/stderr) || echo "[WARN] Fix formatting issues with 'make fmt'"
@for d in $$(go list ./... | grep -v /vendor/); do golint $${d}; done
@go tool vet ${SRC}

run: install
@$(TARGET)

dependencies:
go get github.com/mitchellh/gox
go get github.com/jstemmer/go-junit-report
go get github.com/golang/lint/golint
git submodule update --init --recursive
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# chamgo
69 changes: 69 additions & 0 deletions chamgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package main

import (
"bufio"
"fmt"
"github.com/tarm/serial"
"log"
"os"
"strings"
)

var ui = ""

func main() {
argCount := len(os.Args[1:])
if argCount != 1 {
fmt.Printf("Usage: %s <serial-port>\ne.g.:\n\t%s com5 (on windows)\n\t%s /dev/ttyUSB0 (on linux)\n\t%s /dev/cu.usbmodem1411 (on osx)\n", os.Args[0], os.Args[0], os.Args[0], os.Args[0])
os.Exit(0)
}
c := &serial.Config{Name: os.Args[1], Baud: 9600}
s, err := serial.OpenPort(c)
if err != nil {
log.Fatal(err)
}

//for _, c := range Commands {
//log.Printf("%s", sendCmd(Commands[0], s))
//}
for {
ui = getUserInput()
if ui == "exit" || ui == "quit" {
os.Exit(0)
}

rb := sendCmd(ui, s)
fmt.Print(string(rb))
}
}

/**
* sending cmds to serial
* returns {bytes} responde from device
**/
func sendCmd(cmd string, port *serial.Port) (returnmessage []byte) {
cmd += "\r"
n, err := port.Write([]byte(cmd))
if err != nil {
log.Fatal(err)
}

buf := make([]byte, 256)
n, err = port.Read(buf)
if err != nil {
log.Fatal(err)
}

return buf[0:n]
}

/**
* for receiving user input
* returns {string} with no newline (|n)
**/
func getUserInput() string {
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan() // use `for scanner.Scan()` to keep reading
line := scanner.Text()
return strings.Replace(string(line), "\n", "", -1)
}
1 change: 1 addition & 0 deletions vendor/github.com/tarm/serial
Submodule serial added at eaafce

0 comments on commit d668b91

Please sign in to comment.