diff --git a/cqg-cms-api-client/app/cqg-cms-example/Main.hs b/cqg-cms-api-client/app/cqg-cms-example/Main.hs index 5c224d9..a7a064f 100644 --- a/cqg-cms-api-client/app/cqg-cms-example/Main.hs +++ b/cqg-cms-api-client/app/cqg-cms-example/Main.hs @@ -67,4 +67,3 @@ app :: IO () app cqgUsername cqgPassword cqgClientAppId conn = do logon cqgUsername cqgPassword cqgClientAppId conn - diff --git a/cqg-cms-api-client/src/Lib.hs b/cqg-cms-api-client/src/Lib.hs index 5f9e98e..c2b7257 100644 --- a/cqg-cms-api-client/src/Lib.hs +++ b/cqg-cms-api-client/src/Lib.hs @@ -1,15 +1,16 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeApplications #-} +{-# LANGUAGE LambdaCase #-} module Lib (logon) where import Data.Function ((&)) -import Data.ProtoLens (defMessage) +import Data.ProtoLens (defMessage, encodeMessage, decodeMessage) import Data.ProtoLens.Field (field) import Data.Text (Text) import Lens.Micro ((.~)) -import Network.WebSockets (Connection) -import Proto.CMS.Cmsapi1 () +import Network.WebSockets (Connection, sendBinaryData, receiveData) +import Proto.CMS.Cmsapi1 (ServerMessage, ClientMessage, ProtocolVersion (..)) import Proto.CMS.Common1 (Logon) logon :: @@ -23,9 +24,26 @@ logon :: IO () logon cqgUsername cqgPassword cqgClientAppId conn = do print logonMsg + sendBinaryData conn rawClientMsg + rawResp <- receiveData conn + print (decodeMessage rawResp :: Either String ServerMessage) where + clientMsg = defMessage @ClientMessage & field @"logon" .~ logonMsg + + rawClientMsg = encodeMessage clientMsg + logonMsg = defMessage @Logon & field @"userName" .~ cqgUsername & field @"password" .~ cqgPassword & - field @"clientAppId" .~ cqgClientAppId + field @"clientAppId" .~ cqgClientAppId & + field @"protocolVersionMajor" .~ fromIntegral (fromEnum PROTOCOL_VERSION_MAJOR) & + field @"protocolVersionMinor" .~ fromIntegral (fromEnum PROTOCOL_VERSION_MINOR) + + -- handleRawResp :: Message -> IO () + -- handleRawResp = \case + -- ControlMessage ctrlMsg -> print ctrlMsg + -- DataMessage _ _ _ dmsg -> + -- let dmsg = + -- case dmsg of +