{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.IoTFleetWise.Types.ObdSignal
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoTFleetWise.Types.ObdSignal where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Information about signal messages using the on-board diagnostics (OBD)
-- II protocol in a vehicle.
--
-- /See:/ 'newObdSignal' smart constructor.
data ObdSignal = ObdSignal'
  { -- | The number of bits to mask in a message.
    ObdSignal -> Maybe Natural
bitMaskLength :: Prelude.Maybe Prelude.Natural,
    -- | The number of positions to shift bits in the message.
    ObdSignal -> Maybe Natural
bitRightShift :: Prelude.Maybe Prelude.Natural,
    -- | The length of the requested data.
    ObdSignal -> Natural
pidResponseLength :: Prelude.Natural,
    -- | The mode of operation (diagnostic service) in a message.
    ObdSignal -> Natural
serviceMode :: Prelude.Natural,
    -- | The diagnostic code used to request data from a vehicle for this signal.
    ObdSignal -> Natural
pid :: Prelude.Natural,
    -- | A multiplier used to decode the message.
    ObdSignal -> Double
scaling :: Prelude.Double,
    -- | Indicates where data appears in the message.
    ObdSignal -> Double
offset :: Prelude.Double,
    -- | Indicates the beginning of the message.
    ObdSignal -> Natural
startByte :: Prelude.Natural,
    -- | The length of a message.
    ObdSignal -> Natural
byteLength :: Prelude.Natural
  }
  deriving (ObdSignal -> ObdSignal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ObdSignal -> ObdSignal -> Bool
$c/= :: ObdSignal -> ObdSignal -> Bool
== :: ObdSignal -> ObdSignal -> Bool
$c== :: ObdSignal -> ObdSignal -> Bool
Prelude.Eq, ReadPrec [ObdSignal]
ReadPrec ObdSignal
Int -> ReadS ObdSignal
ReadS [ObdSignal]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ObdSignal]
$creadListPrec :: ReadPrec [ObdSignal]
readPrec :: ReadPrec ObdSignal
$creadPrec :: ReadPrec ObdSignal
readList :: ReadS [ObdSignal]
$creadList :: ReadS [ObdSignal]
readsPrec :: Int -> ReadS ObdSignal
$creadsPrec :: Int -> ReadS ObdSignal
Prelude.Read, Int -> ObdSignal -> ShowS
[ObdSignal] -> ShowS
ObdSignal -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ObdSignal] -> ShowS
$cshowList :: [ObdSignal] -> ShowS
show :: ObdSignal -> String
$cshow :: ObdSignal -> String
showsPrec :: Int -> ObdSignal -> ShowS
$cshowsPrec :: Int -> ObdSignal -> ShowS
Prelude.Show, forall x. Rep ObdSignal x -> ObdSignal
forall x. ObdSignal -> Rep ObdSignal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ObdSignal x -> ObdSignal
$cfrom :: forall x. ObdSignal -> Rep ObdSignal x
Prelude.Generic)

-- |
-- Create a value of 'ObdSignal' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'bitMaskLength', 'obdSignal_bitMaskLength' - The number of bits to mask in a message.
--
-- 'bitRightShift', 'obdSignal_bitRightShift' - The number of positions to shift bits in the message.
--
-- 'pidResponseLength', 'obdSignal_pidResponseLength' - The length of the requested data.
--
-- 'serviceMode', 'obdSignal_serviceMode' - The mode of operation (diagnostic service) in a message.
--
-- 'pid', 'obdSignal_pid' - The diagnostic code used to request data from a vehicle for this signal.
--
-- 'scaling', 'obdSignal_scaling' - A multiplier used to decode the message.
--
-- 'offset', 'obdSignal_offset' - Indicates where data appears in the message.
--
-- 'startByte', 'obdSignal_startByte' - Indicates the beginning of the message.
--
-- 'byteLength', 'obdSignal_byteLength' - The length of a message.
newObdSignal ::
  -- | 'pidResponseLength'
  Prelude.Natural ->
  -- | 'serviceMode'
  Prelude.Natural ->
  -- | 'pid'
  Prelude.Natural ->
  -- | 'scaling'
  Prelude.Double ->
  -- | 'offset'
  Prelude.Double ->
  -- | 'startByte'
  Prelude.Natural ->
  -- | 'byteLength'
  Prelude.Natural ->
  ObdSignal
newObdSignal :: Natural
-> Natural
-> Natural
-> Double
-> Double
-> Natural
-> Natural
-> ObdSignal
newObdSignal
  Natural
pPidResponseLength_
  Natural
pServiceMode_
  Natural
pPid_
  Double
pScaling_
  Double
pOffset_
  Natural
pStartByte_
  Natural
pByteLength_ =
    ObdSignal'
      { $sel:bitMaskLength:ObdSignal' :: Maybe Natural
bitMaskLength = forall a. Maybe a
Prelude.Nothing,
        $sel:bitRightShift:ObdSignal' :: Maybe Natural
bitRightShift = forall a. Maybe a
Prelude.Nothing,
        $sel:pidResponseLength:ObdSignal' :: Natural
pidResponseLength = Natural
pPidResponseLength_,
        $sel:serviceMode:ObdSignal' :: Natural
serviceMode = Natural
pServiceMode_,
        $sel:pid:ObdSignal' :: Natural
pid = Natural
pPid_,
        $sel:scaling:ObdSignal' :: Double
scaling = Double
pScaling_,
        $sel:offset:ObdSignal' :: Double
offset = Double
pOffset_,
        $sel:startByte:ObdSignal' :: Natural
startByte = Natural
pStartByte_,
        $sel:byteLength:ObdSignal' :: Natural
byteLength = Natural
pByteLength_
      }

-- | The number of bits to mask in a message.
obdSignal_bitMaskLength :: Lens.Lens' ObdSignal (Prelude.Maybe Prelude.Natural)
obdSignal_bitMaskLength :: Lens' ObdSignal (Maybe Natural)
obdSignal_bitMaskLength = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObdSignal' {Maybe Natural
bitMaskLength :: Maybe Natural
$sel:bitMaskLength:ObdSignal' :: ObdSignal -> Maybe Natural
bitMaskLength} -> Maybe Natural
bitMaskLength) (\s :: ObdSignal
s@ObdSignal' {} Maybe Natural
a -> ObdSignal
s {$sel:bitMaskLength:ObdSignal' :: Maybe Natural
bitMaskLength = Maybe Natural
a} :: ObdSignal)

-- | The number of positions to shift bits in the message.
obdSignal_bitRightShift :: Lens.Lens' ObdSignal (Prelude.Maybe Prelude.Natural)
obdSignal_bitRightShift :: Lens' ObdSignal (Maybe Natural)
obdSignal_bitRightShift = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObdSignal' {Maybe Natural
bitRightShift :: Maybe Natural
$sel:bitRightShift:ObdSignal' :: ObdSignal -> Maybe Natural
bitRightShift} -> Maybe Natural
bitRightShift) (\s :: ObdSignal
s@ObdSignal' {} Maybe Natural
a -> ObdSignal
s {$sel:bitRightShift:ObdSignal' :: Maybe Natural
bitRightShift = Maybe Natural
a} :: ObdSignal)

-- | The length of the requested data.
obdSignal_pidResponseLength :: Lens.Lens' ObdSignal Prelude.Natural
obdSignal_pidResponseLength :: Lens' ObdSignal Natural
obdSignal_pidResponseLength = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObdSignal' {Natural
pidResponseLength :: Natural
$sel:pidResponseLength:ObdSignal' :: ObdSignal -> Natural
pidResponseLength} -> Natural
pidResponseLength) (\s :: ObdSignal
s@ObdSignal' {} Natural
a -> ObdSignal
s {$sel:pidResponseLength:ObdSignal' :: Natural
pidResponseLength = Natural
a} :: ObdSignal)

-- | The mode of operation (diagnostic service) in a message.
obdSignal_serviceMode :: Lens.Lens' ObdSignal Prelude.Natural
obdSignal_serviceMode :: Lens' ObdSignal Natural
obdSignal_serviceMode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObdSignal' {Natural
serviceMode :: Natural
$sel:serviceMode:ObdSignal' :: ObdSignal -> Natural
serviceMode} -> Natural
serviceMode) (\s :: ObdSignal
s@ObdSignal' {} Natural
a -> ObdSignal
s {$sel:serviceMode:ObdSignal' :: Natural
serviceMode = Natural
a} :: ObdSignal)

-- | The diagnostic code used to request data from a vehicle for this signal.
obdSignal_pid :: Lens.Lens' ObdSignal Prelude.Natural
obdSignal_pid :: Lens' ObdSignal Natural
obdSignal_pid = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObdSignal' {Natural
pid :: Natural
$sel:pid:ObdSignal' :: ObdSignal -> Natural
pid} -> Natural
pid) (\s :: ObdSignal
s@ObdSignal' {} Natural
a -> ObdSignal
s {$sel:pid:ObdSignal' :: Natural
pid = Natural
a} :: ObdSignal)

-- | A multiplier used to decode the message.
obdSignal_scaling :: Lens.Lens' ObdSignal Prelude.Double
obdSignal_scaling :: Lens' ObdSignal Double
obdSignal_scaling = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObdSignal' {Double
scaling :: Double
$sel:scaling:ObdSignal' :: ObdSignal -> Double
scaling} -> Double
scaling) (\s :: ObdSignal
s@ObdSignal' {} Double
a -> ObdSignal
s {$sel:scaling:ObdSignal' :: Double
scaling = Double
a} :: ObdSignal)

-- | Indicates where data appears in the message.
obdSignal_offset :: Lens.Lens' ObdSignal Prelude.Double
obdSignal_offset :: Lens' ObdSignal Double
obdSignal_offset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObdSignal' {Double
offset :: Double
$sel:offset:ObdSignal' :: ObdSignal -> Double
offset} -> Double
offset) (\s :: ObdSignal
s@ObdSignal' {} Double
a -> ObdSignal
s {$sel:offset:ObdSignal' :: Double
offset = Double
a} :: ObdSignal)

-- | Indicates the beginning of the message.
obdSignal_startByte :: Lens.Lens' ObdSignal Prelude.Natural
obdSignal_startByte :: Lens' ObdSignal Natural
obdSignal_startByte = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObdSignal' {Natural
startByte :: Natural
$sel:startByte:ObdSignal' :: ObdSignal -> Natural
startByte} -> Natural
startByte) (\s :: ObdSignal
s@ObdSignal' {} Natural
a -> ObdSignal
s {$sel:startByte:ObdSignal' :: Natural
startByte = Natural
a} :: ObdSignal)

-- | The length of a message.
obdSignal_byteLength :: Lens.Lens' ObdSignal Prelude.Natural
obdSignal_byteLength :: Lens' ObdSignal Natural
obdSignal_byteLength = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObdSignal' {Natural
byteLength :: Natural
$sel:byteLength:ObdSignal' :: ObdSignal -> Natural
byteLength} -> Natural
byteLength) (\s :: ObdSignal
s@ObdSignal' {} Natural
a -> ObdSignal
s {$sel:byteLength:ObdSignal' :: Natural
byteLength = Natural
a} :: ObdSignal)

instance Data.FromJSON ObdSignal where
  parseJSON :: Value -> Parser ObdSignal
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ObdSignal"
      ( \Object
x ->
          Maybe Natural
-> Maybe Natural
-> Natural
-> Natural
-> Natural
-> Double
-> Double
-> Natural
-> Natural
-> ObdSignal
ObdSignal'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"bitMaskLength")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"bitRightShift")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"pidResponseLength")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"serviceMode")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"pid")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"scaling")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"offset")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"startByte")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"byteLength")
      )

instance Prelude.Hashable ObdSignal where
  hashWithSalt :: Int -> ObdSignal -> Int
hashWithSalt Int
_salt ObdSignal' {Double
Natural
Maybe Natural
byteLength :: Natural
startByte :: Natural
offset :: Double
scaling :: Double
pid :: Natural
serviceMode :: Natural
pidResponseLength :: Natural
bitRightShift :: Maybe Natural
bitMaskLength :: Maybe Natural
$sel:byteLength:ObdSignal' :: ObdSignal -> Natural
$sel:startByte:ObdSignal' :: ObdSignal -> Natural
$sel:offset:ObdSignal' :: ObdSignal -> Double
$sel:scaling:ObdSignal' :: ObdSignal -> Double
$sel:pid:ObdSignal' :: ObdSignal -> Natural
$sel:serviceMode:ObdSignal' :: ObdSignal -> Natural
$sel:pidResponseLength:ObdSignal' :: ObdSignal -> Natural
$sel:bitRightShift:ObdSignal' :: ObdSignal -> Maybe Natural
$sel:bitMaskLength:ObdSignal' :: ObdSignal -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
bitMaskLength
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
bitRightShift
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
pidResponseLength
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
serviceMode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
pid
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
scaling
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
offset
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
startByte
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
byteLength

instance Prelude.NFData ObdSignal where
  rnf :: ObdSignal -> ()
rnf ObdSignal' {Double
Natural
Maybe Natural
byteLength :: Natural
startByte :: Natural
offset :: Double
scaling :: Double
pid :: Natural
serviceMode :: Natural
pidResponseLength :: Natural
bitRightShift :: Maybe Natural
bitMaskLength :: Maybe Natural
$sel:byteLength:ObdSignal' :: ObdSignal -> Natural
$sel:startByte:ObdSignal' :: ObdSignal -> Natural
$sel:offset:ObdSignal' :: ObdSignal -> Double
$sel:scaling:ObdSignal' :: ObdSignal -> Double
$sel:pid:ObdSignal' :: ObdSignal -> Natural
$sel:serviceMode:ObdSignal' :: ObdSignal -> Natural
$sel:pidResponseLength:ObdSignal' :: ObdSignal -> Natural
$sel:bitRightShift:ObdSignal' :: ObdSignal -> Maybe Natural
$sel:bitMaskLength:ObdSignal' :: ObdSignal -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
bitMaskLength
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
bitRightShift
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
pidResponseLength
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
serviceMode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
pid
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Double
scaling
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Double
offset
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
startByte
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
byteLength

instance Data.ToJSON ObdSignal where
  toJSON :: ObdSignal -> Value
toJSON ObdSignal' {Double
Natural
Maybe Natural
byteLength :: Natural
startByte :: Natural
offset :: Double
scaling :: Double
pid :: Natural
serviceMode :: Natural
pidResponseLength :: Natural
bitRightShift :: Maybe Natural
bitMaskLength :: Maybe Natural
$sel:byteLength:ObdSignal' :: ObdSignal -> Natural
$sel:startByte:ObdSignal' :: ObdSignal -> Natural
$sel:offset:ObdSignal' :: ObdSignal -> Double
$sel:scaling:ObdSignal' :: ObdSignal -> Double
$sel:pid:ObdSignal' :: ObdSignal -> Natural
$sel:serviceMode:ObdSignal' :: ObdSignal -> Natural
$sel:pidResponseLength:ObdSignal' :: ObdSignal -> Natural
$sel:bitRightShift:ObdSignal' :: ObdSignal -> Maybe Natural
$sel:bitMaskLength:ObdSignal' :: ObdSignal -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"bitMaskLength" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
bitMaskLength,
            (Key
"bitRightShift" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
bitRightShift,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"pidResponseLength" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
pidResponseLength),
            forall a. a -> Maybe a
Prelude.Just (Key
"serviceMode" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
serviceMode),
            forall a. a -> Maybe a
Prelude.Just (Key
"pid" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
pid),
            forall a. a -> Maybe a
Prelude.Just (Key
"scaling" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Double
scaling),
            forall a. a -> Maybe a
Prelude.Just (Key
"offset" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Double
offset),
            forall a. a -> Maybe a
Prelude.Just (Key
"startByte" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
startByte),
            forall a. a -> Maybe a
Prelude.Just (Key
"byteLength" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
byteLength)
          ]
      )