-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SocketCAN Support for Telemetry (#37)
* Initial commit, WIPX * - Added socketcan as another input - Changed serial's input flags to no longer default to /dev/ttyUSB0 - Tested to work on the car * Updated startup script to start can0 using PCAN dongles * Undid changes made during testing to the fake.go file * Added new line to fake.go to match original version
- Loading branch information
Showing
6 changed files
with
75 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package socketcan | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/linklayer/go-socketcan/pkg/socketcan" | ||
"os" | ||
|
||
"github.com/uw-midsun/telemetry/pkg/msgs" | ||
"github.com/uw-midsun/telemetry/pkg/pubsub" | ||
|
||
log "github.com/golang/glog" | ||
) | ||
|
||
// Run starts reading canPacket from the specified serial port and serving those on bus. | ||
func Run(port string, bus *pubsub.MessageBus) { | ||
log.Infof("SocketCAN %s", port) | ||
device, err := socketcan.NewRawInterface(port) | ||
|
||
if err != nil { | ||
fmt.Printf("could not open interface %s: %v\n", | ||
port, err) | ||
os.Exit(1) | ||
} | ||
|
||
defer device.Close() | ||
|
||
for { | ||
frame, err := device.RecvFrame() | ||
if err != nil { | ||
fmt.Printf("error receiving frame: %v", err) | ||
os.Exit(1) | ||
} | ||
//dataStr := dataToString(frame.Data) | ||
//dataInt, _ := strconv.ParseInt(string(frame.Data), 10, 64) | ||
//fmt.Printf(" %s\t%03X\t[%d]\t%s\n", device.IfName, frame.ArbId, frame.Dlc, dataStr) | ||
//log.Infof("Device: %s, Data: %i, DLC: %s\n", frame.ArbId, dataInt, frame.Dlc) | ||
data := binary.LittleEndian.Uint64(frame.Data) | ||
bus.Publish("CAN", msgs.NewCAN(frame.ArbId, uint64(data), uint8(frame.Dlc))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters