Skip to content

Commit

Permalink
get logon working
Browse files Browse the repository at this point in the history
  • Loading branch information
cdepillabout committed Jun 6, 2024
1 parent 76ad098 commit 96ae9a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
1 change: 0 additions & 1 deletion cqg-cms-api-client/app/cqg-cms-example/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ app ::
IO ()
app cqgUsername cqgPassword cqgClientAppId conn = do
logon cqgUsername cqgPassword cqgClientAppId conn

26 changes: 22 additions & 4 deletions cqg-cms-api-client/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -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 ::
Expand All @@ -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

0 comments on commit 96ae9a9

Please sign in to comment.