Skip to content

Commit

Permalink
Added NewDistSinceDTCClear command (0x31) - distance since last DTC c…
Browse files Browse the repository at this point in the history
…lear

Added mocked responses for Fuel and Speed
  • Loading branch information
Mikspec committed Mar 20, 2019
1 parent 6d1d703 commit 8e577f1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [0.6.0] - 2019-03-20

### Fixed
- issue #18 - commands expect one byte as response - mocked device returned three bytes

### Added
- `NewDistSinceDTCClear` command (0x31) - distance since last DTC clear
- mocked responses for Fuel (0x2F), Speed (0x0D)

## [0.5.1] - 2018-08-15

### Changed
Expand Down
9 changes: 5 additions & 4 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ The library has been built and tested on the following platforms:

The library has been used successfully on the following cars:

| Car | Library version | Tester |
|-------------------------+-----------------+--------------|
| Lexus IS200 Manual 2004 | 0.3.0 | @rzetterberg |
| Ford Ka 2011 | 0.5.0 | @Enrico204 |
| Car | Library version | Tester |
|---------------------------+-----------------+--------------|
| Lexus IS200 Manual 2004 | 0.3.0 | @rzetterberg |
| Ford Ka 2011 | 0.5.0 | @Enrico204 |
| Ford Transit Automat 2019 | 0.6.0 | @mikspec |
30 changes: 30 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,36 @@ func (cmd *Fuel) SetValue(result *Result) error {
return nil
}

// DistSinceDTCClear represents a command that checks distance since last DTC clear
//
// Min: 0
// Max: 65535
type DistSinceDTCClear struct {
BaseCommand
UIntCommand
}

// NewDistSinceDTCClear creates a new commend distance since DTC clear with the correct parameters.
func NewDistSinceDTCClear() *DistSinceDTCClear {
return &DistSinceDTCClear{
BaseCommand{0x31, 2, "dist_since_dtc_clean"},
UIntCommand{},
}
}

// SetValue processes the byte array value into the right uint value.
func (cmd *DistSinceDTCClear) SetValue(result *Result) error {
payload, err := result.PayloadAsUInt16()

if err != nil {
return err
}

cmd.Value = uint32(payload)

return nil
}

// CoolantTemperature represents a command that checks the engine coolant
// temperature in Celsius.
//
Expand Down
5 changes: 5 additions & 0 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestToCommand(t *testing.T) {
assertEqual(t, NewPart1Supported().ToCommand(), "01001")
assertEqual(t, NewEngineLoad().ToCommand(), "01041")
assertEqual(t, NewVehicleSpeed().ToCommand(), "010D1")
assertEqual(t, NewDistSinceDTCClear().ToCommand(), "01311")
}

func TestIsSupported(t *testing.T) {
Expand Down Expand Up @@ -170,6 +171,10 @@ func TestParseOBDResponse(t *testing.T) {
"41 00 01 02 03 04",
},
},
{
NewDistSinceDTCClear(),
[]string{"41 31 02 33"},
},
}

for _, curr := range scenarios {
Expand Down
4 changes: 4 additions & 0 deletions mockdevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func mockMode1Outputs(subcmd string) []string {
return []string{
"41 0D 4B",
}
} else if strings.HasPrefix(subcmd, "31") {
return []string{
"41 31 02 0C",
}
}

return []string{"NOT SUPPORTED"}
Expand Down

0 comments on commit 8e577f1

Please sign in to comment.