From ac3987255cb472100be32f604d840be85a298d08 Mon Sep 17 00:00:00 2001 From: Pasi Miettinen Date: Fri, 12 Apr 2019 15:53:48 +0300 Subject: [PATCH 1/3] Do not call nullary constructors in Haskell ToJSON --- generator/sbpg/targets/haskell.py | 2 +- .../targets/resources/SbpMessageTemplate.hs | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/generator/sbpg/targets/haskell.py b/generator/sbpg/targets/haskell.py index a8c65dc6b3..ae25446212 100755 --- a/generator/sbpg/targets/haskell.py +++ b/generator/sbpg/targets/haskell.py @@ -209,7 +209,7 @@ def render_sbp(output_dir, package_specs): modules.append(full_module_name) for m in package_spec.definitions: if m.static and m.sbp_id: - msgs.append(to_data(m.identifier)) + msgs.append(m) destination_filename = "%s/src/SwiftNav/SBP.hs" % output_dir py_template = JENV.get_template(SBP_TEMPLATE_NAME) with open(destination_filename, 'w') as f: diff --git a/generator/sbpg/targets/resources/SbpMessageTemplate.hs b/generator/sbpg/targets/resources/SbpMessageTemplate.hs index 09a65f23fc..24efe0f77f 100644 --- a/generator/sbpg/targets/resources/SbpMessageTemplate.hs +++ b/generator/sbpg/targets/resources/SbpMessageTemplate.hs @@ -36,9 +36,9 @@ import SwiftNav.SBP.Types -- Includes SBPMsgUnknown for valid SBP messages with undefined message -- types and SBPMsgBadCRC for SBP messages with invalid CRC checksums. data SBPMsg = - SBP(((m))) (((m))) Msg + SBP(((m.identifier | hs_to_data))) (((m.identifier | hs_to_data))) Msg ((*- else *)) - | SBP(((m))) (((m))) Msg + | SBP(((m.identifier | hs_to_data))) (((m.identifier | hs_to_data))) Msg ((*- endif *)) ((*- if loop.last *)) | SBPMsgBadCrc Msg @@ -57,7 +57,7 @@ instance Binary SBPMsg where decoder m@Msg {..} | checkCrc m /= _msgSBPCrc = SBPMsgBadCrc m ((*- for m in msgs *)) - | _msgSBPType == (((m | hs_to_global))) = SBP(((m))) (decode (fromStrict (unBytes _msgSBPPayload))) m + | _msgSBPType == (((m.identifier | hs_to_global))) = SBP(((m.identifier | hs_to_data))) (decode (fromStrict (unBytes _msgSBPPayload))) m ((*- endfor *)) | otherwise = SBPMsgUnknown m @@ -65,7 +65,7 @@ instance Binary SBPMsg where putWord8 msgSBPPreamble encoder sm where ((*- for m in msgs *)) - encoder (SBP(((m))) _ m) = put m + encoder (SBP(((m.identifier | hs_to_data))) _ m) = put m ((*- endfor *)) encoder (SBPMsgUnknown m) = put m encoder (SBPMsgBadCrc m) = put m @@ -77,7 +77,7 @@ instance FromJSON SBPMsg where decoder msgType payload where decoder msgType payload ((*- for m in msgs *)) - | msgType == (((m | hs_to_global))) = SBP(((m))) <$> pure (decode (fromStrict (unBytes payload))) <*> parseJSON obj + | msgType == (((m.identifier | hs_to_global))) = SBP(((m.identifier | hs_to_data))) <$> pure (decode (fromStrict (unBytes payload))) <*> parseJSON obj ((*- endfor *)) | otherwise = SBPMsgUnknown <$> parseJSON obj parseJSON _ = mzero @@ -90,14 +90,18 @@ instance FromJSON SBPMsg where instance ToJSON SBPMsg where ((*- for m in msgs *)) - toJSON (SBP(((m))) n m) = toJSON n <<>> toJSON m + ((*- if m.fields *)) + toJSON (SBP(((m.identifier | hs_to_data))) n m) = toJSON n <<>> toJSON m + ((*- else *)) + toJSON (SBP(((m.identifier | hs_to_data))) _ m) = toJSON m + ((*- endif *)) ((*- endfor *)) toJSON (SBPMsgBadCrc m) = toJSON m toJSON (SBPMsgUnknown m) = toJSON m instance HasMsg SBPMsg where ((*- for m in msgs *)) - msg f (SBP(((m))) n m) = SBP(((m))) n <$> f m + msg f (SBP(((m.identifier | hs_to_data))) n m) = SBP(((m.identifier | hs_to_data))) n <$> f m ((*- endfor *)) msg f (SBPMsgUnknown m) = SBPMsgUnknown <$> f m msg f (SBPMsgBadCrc m) = SBPMsgBadCrc <$> f m From 69add649f163129a72a278bf91253cc29cfafd3b Mon Sep 17 00:00:00 2001 From: Pasi Miettinen Date: Fri, 12 Apr 2019 16:18:31 +0300 Subject: [PATCH 2/3] Add lambda for sorting --- generator/sbpg/targets/haskell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generator/sbpg/targets/haskell.py b/generator/sbpg/targets/haskell.py index ae25446212..e2271e38c7 100755 --- a/generator/sbpg/targets/haskell.py +++ b/generator/sbpg/targets/haskell.py @@ -215,10 +215,10 @@ def render_sbp(output_dir, package_specs): with open(destination_filename, 'w') as f: f.write(py_template.render(modules=sorted(modules), pkgs=package_specs, - msgs=sorted(msgs))) + msgs=sorted(msgs, key=lambda m:to_data(m.identifier)))) destination_filename = "%s/src/SwiftNav/SBP/Msg.hs" % output_dir py_template = JENV.get_template(MESSAGE_TEMPLATE_NAME) with open(destination_filename, 'w') as f: f.write(py_template.render(modules=sorted(modules), pkgs=package_specs, - msgs=sorted(msgs))) + msgs=sorted(msgs, key=lambda m:to_data(m.identifier)))) From 2907e1eda546cc8910da5b686906fcdfca01a63c Mon Sep 17 00:00:00 2001 From: Pasi Miettinen Date: Fri, 12 Apr 2019 15:54:15 +0300 Subject: [PATCH 3/3] Regenerate Msg.hs --- haskell/src/SwiftNav/SBP/Msg.hs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/haskell/src/SwiftNav/SBP/Msg.hs b/haskell/src/SwiftNav/SBP/Msg.hs index 8e1a85d2fc..0ef6d8c28f 100644 --- a/haskell/src/SwiftNav/SBP/Msg.hs +++ b/haskell/src/SwiftNav/SBP/Msg.hs @@ -766,7 +766,7 @@ instance ToJSON SBPMsg where toJSON (SBPMsgAcqSvProfile n m) = toJSON n <<>> toJSON m toJSON (SBPMsgAcqSvProfileDep n m) = toJSON n <<>> toJSON m toJSON (SBPMsgAgeCorrections n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgAlmanac n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgAlmanac _ m) = toJSON m toJSON (SBPMsgAlmanacGlo n m) = toJSON n <<>> toJSON m toJSON (SBPMsgAlmanacGloDep n m) = toJSON n <<>> toJSON m toJSON (SBPMsgAlmanacGps n m) = toJSON n <<>> toJSON m @@ -781,7 +781,7 @@ instance ToJSON SBPMsg where toJSON (SBPMsgBaselineNed n m) = toJSON n <<>> toJSON m toJSON (SBPMsgBaselineNedDepA n m) = toJSON n <<>> toJSON m toJSON (SBPMsgBootloaderHandshakeDepA n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgBootloaderHandshakeReq n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgBootloaderHandshakeReq _ m) = toJSON m toJSON (SBPMsgBootloaderHandshakeResp n m) = toJSON n <<>> toJSON m toJSON (SBPMsgBootloaderJumpToApp n m) = toJSON n <<>> toJSON m toJSON (SBPMsgCellModemStatus n m) = toJSON n <<>> toJSON m @@ -790,8 +790,8 @@ instance ToJSON SBPMsg where toJSON (SBPMsgCommandResp n m) = toJSON n <<>> toJSON m toJSON (SBPMsgCsacTelemetry n m) = toJSON n <<>> toJSON m toJSON (SBPMsgCsacTelemetryLabels n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgCwResults n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgCwStart n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgCwResults _ m) = toJSON m + toJSON (SBPMsgCwStart _ m) = toJSON m toJSON (SBPMsgDeviceMonitor n m) = toJSON n <<>> toJSON m toJSON (SBPMsgDgnssStatus n m) = toJSON n <<>> toJSON m toJSON (SBPMsgDops n m) = toJSON n <<>> toJSON m @@ -841,7 +841,7 @@ instance ToJSON SBPMsg where toJSON (SBPMsgIarState n m) = toJSON n <<>> toJSON m toJSON (SBPMsgImuAux n m) = toJSON n <<>> toJSON m toJSON (SBPMsgImuRaw n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgInitBase n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgInitBase _ m) = toJSON m toJSON (SBPMsgInsStatus n m) = toJSON n <<>> toJSON m toJSON (SBPMsgIono n m) = toJSON n <<>> toJSON m toJSON (SBPMsgLinuxCpuState n m) = toJSON n <<>> toJSON m @@ -858,11 +858,11 @@ instance ToJSON SBPMsg where toJSON (SBPMsgMaskSatellite n m) = toJSON n <<>> toJSON m toJSON (SBPMsgMaskSatelliteDep n m) = toJSON n <<>> toJSON m toJSON (SBPMsgMeasurementState n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgNapDeviceDnaReq n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgNapDeviceDnaReq _ m) = toJSON m toJSON (SBPMsgNapDeviceDnaResp n m) = toJSON n <<>> toJSON m toJSON (SBPMsgNdbEvent n m) = toJSON n <<>> toJSON m toJSON (SBPMsgNetworkBandwidthUsage n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgNetworkStateReq n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgNetworkStateReq _ m) = toJSON m toJSON (SBPMsgNetworkStateResp n m) = toJSON n <<>> toJSON m toJSON (SBPMsgObs n m) = toJSON n <<>> toJSON m toJSON (SBPMsgObsDepA n m) = toJSON n <<>> toJSON m @@ -879,18 +879,18 @@ instance ToJSON SBPMsg where toJSON (SBPMsgPosLlhDepA n m) = toJSON n <<>> toJSON m toJSON (SBPMsgPrintDep n m) = toJSON n <<>> toJSON m toJSON (SBPMsgReset n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgResetDep n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgResetDep _ m) = toJSON m toJSON (SBPMsgResetFilters n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSbasRaw n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgSetTime n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgSettingsReadByIndexDone n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgSetTime _ m) = toJSON m + toJSON (SBPMsgSettingsReadByIndexDone _ m) = toJSON m toJSON (SBPMsgSettingsReadByIndexReq n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSettingsReadByIndexResp n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSettingsReadReq n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSettingsReadResp n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSettingsRegister n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSettingsRegisterResp n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgSettingsSave n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgSettingsSave _ m) = toJSON m toJSON (SBPMsgSettingsWrite n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSettingsWriteResp n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSpecan n m) = toJSON n <<>> toJSON m @@ -902,7 +902,7 @@ instance ToJSON SBPMsg where toJSON (SBPMsgStartup n m) = toJSON n <<>> toJSON m toJSON (SBPMsgStmFlashLockSector n m) = toJSON n <<>> toJSON m toJSON (SBPMsgStmFlashUnlockSector n m) = toJSON n <<>> toJSON m - toJSON (SBPMsgStmUniqueIdReq n m) = toJSON n <<>> toJSON m + toJSON (SBPMsgStmUniqueIdReq _ m) = toJSON m toJSON (SBPMsgStmUniqueIdResp n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSvAzEl n m) = toJSON n <<>> toJSON m toJSON (SBPMsgSvConfigurationGpsDep n m) = toJSON n <<>> toJSON m