16. C言語の構造体を型として扱うC言語の構造体を型として扱うC言語の構造体を型として扱うC言語の構造体を型として扱うC言語の構造体を型として扱う
newtype {-# CTYPE "gpio_t" #-} GpioT = GpioT ()
foreign import primitive "const.sizeof(gpio_t)" gpio_t_size ::
Int
foreign import ccall "c_extern.h gpio_init" c_gpio_init :: Ptr
GpioT -> Int -> Int -> IO ()
gpioInit :: Int -> Int -> IO (Ptr GpioT)
gpioInit name direction = do tag <- mallocBytes gpio_t_size
c_gpio_init tag name direction
return tag
newtype {-# CTYPE "gpio_t" #-} GpioT = GpioT ()
foreign import primitive "const.sizeof(gpio_t)" gpio_t_size ::
Int
foreign import ccall "c_extern.h gpio_init" c_gpio_init :: Ptr
GpioT -> Int -> Int -> IO ()
gpioInit :: Int -> Int -> IO (Ptr GpioT)
gpioInit name direction = do tag <- mallocBytes gpio_t_size
c_gpio_init tag name direction
return tag
newtype {-# CTYPE "gpio_t" #-} GpioT = GpioT ()
foreign import primitive "const.sizeof(gpio_t)" gpio_t_size ::
Int
foreign import ccall "c_extern.h gpio_init" c_gpio_init :: Ptr
GpioT -> Int -> Int -> IO ()
gpioInit :: Int -> Int -> IO (Ptr GpioT)
gpioInit name direction = do tag <- mallocBytes gpio_t_size
c_gpio_init tag name direction
return tag
newtype {-# CTYPE "gpio_t" #-} GpioT = GpioT ()
foreign import primitive "const.sizeof(gpio_t)" gpio_t_size ::
Int
foreign import ccall "c_extern.h gpio_init" c_gpio_init :: Ptr
GpioT -> Int -> Int -> IO ()
gpioInit :: Int -> Int -> IO (Ptr GpioT)
gpioInit name direction = do tag <- mallocBytes gpio_t_size
c_gpio_init tag name direction
return tag
newtype {-# CTYPE "gpio_t" #-} GpioT = GpioT ()
foreign import primitive "const.sizeof(gpio_t)" gpio_t_size ::
Int
foreign import ccall "c_extern.h gpio_init" c_gpio_init :: Ptr
GpioT -> Int -> Int -> IO ()
gpioInit :: Int -> Int -> IO (Ptr GpioT)
gpioInit name direction = do tag <- mallocBytes gpio_t_size
c_gpio_init tag name direction
return tag
17. C言語ヘッダのアドレス設定を参照C言語ヘッダのアドレス設定を参照C言語ヘッダのアドレス設定を参照C言語ヘッダのアドレス設定を参照C言語ヘッダのアドレス設定を参照
foreign import primitive "const.LPC_GPIO0_BASE"
addr_LPC_GPIO0_BASE :: Int
pinName :: Int -> Int -> Int
pinName major minor = addr_LPC_GPIO0_BASE + major * 32 + minor
led1 :: Int
led1 = pinName 1 18 -- P1.18
foreign import primitive "const.LPC_GPIO0_BASE"
addr_LPC_GPIO0_BASE :: Int
pinName :: Int -> Int -> Int
pinName major minor = addr_LPC_GPIO0_BASE + major * 32 + minor
led1 :: Int
led1 = pinName 1 18 -- P1.18
foreign import primitive "const.LPC_GPIO0_BASE"
addr_LPC_GPIO0_BASE :: Int
pinName :: Int -> Int -> Int
pinName major minor = addr_LPC_GPIO0_BASE + major * 32 + minor
led1 :: Int
led1 = pinName 1 18 -- P1.18
foreign import primitive "const.LPC_GPIO0_BASE"
addr_LPC_GPIO0_BASE :: Int
pinName :: Int -> Int -> Int
pinName major minor = addr_LPC_GPIO0_BASE + major * 32 + minor
led1 :: Int
led1 = pinName 1 18 -- P1.18
foreign import primitive "const.LPC_GPIO0_BASE"
addr_LPC_GPIO0_BASE :: Int
pinName :: Int -> Int -> Int
pinName major minor = addr_LPC_GPIO0_BASE + major * 32 + minor
led1 :: Int
led1 = pinName 1 18 -- P1.18
18. LEDのON/OFFLEDのON/OFFLEDのON/OFFLEDのON/OFFLEDのON/OFF
pinOutput :: Int
pinOutput = 1
initLed :: Int -> IO (Ptr GpioT)
initLed name = gpioInit name pinOutput
ledOn, ledOff :: Ptr GpioT -> IO ()
ledOn l = gpioWrite l 1
ledOff l = gpioWrite l 0
pinOutput :: Int
pinOutput = 1
initLed :: Int -> IO (Ptr GpioT)
initLed name = gpioInit name pinOutput
ledOn, ledOff :: Ptr GpioT -> IO ()
ledOn l = gpioWrite l 1
ledOff l = gpioWrite l 0
pinOutput :: Int
pinOutput = 1
initLed :: Int -> IO (Ptr GpioT)
initLed name = gpioInit name pinOutput
ledOn, ledOff :: Ptr GpioT -> IO ()
ledOn l = gpioWrite l 1
ledOff l = gpioWrite l 0
pinOutput :: Int
pinOutput = 1
initLed :: Int -> IO (Ptr GpioT)
initLed name = gpioInit name pinOutput
ledOn, ledOff :: Ptr GpioT -> IO ()
ledOn l = gpioWrite l 1
ledOff l = gpioWrite l 0
pinOutput :: Int
pinOutput = 1
initLed :: Int -> IO (Ptr GpioT)
initLed name = gpioInit name pinOutput
ledOn, ledOff :: Ptr GpioT -> IO ()
ledOn l = gpioWrite l 1
ledOff l = gpioWrite l 0
20. ストリーム処理ストリーム処理ストリーム処理ストリーム処理ストリーム処理
receiveAll :: Ptr TCPSocketConnectionT -> IO [String]
receiveAll tcp = unsafeInterleaveIO receiveAll' where
receiveAll' = do
s <- tcpSocketConnection_receive tcp
if s == "" then return [] else do
s' <- unsafeInterleaveIO receiveAll'
return $ s:s'
receiveAll :: Ptr TCPSocketConnectionT -> IO [String]
receiveAll tcp = unsafeInterleaveIO receiveAll' where
receiveAll' = do
s <- tcpSocketConnection_receive tcp
if s == "" then return [] else do
s' <- unsafeInterleaveIO receiveAll'
return $ s:s'
receiveAll :: Ptr TCPSocketConnectionT -> IO [String]
receiveAll tcp = unsafeInterleaveIO receiveAll' where
receiveAll' = do
s <- tcpSocketConnection_receive tcp
if s == "" then return [] else do
s' <- unsafeInterleaveIO receiveAll'
return $ s:s'
receiveAll :: Ptr TCPSocketConnectionT -> IO [String]
receiveAll tcp = unsafeInterleaveIO receiveAll' where
receiveAll' = do
s <- tcpSocketConnection_receive tcp
if s == "" then return [] else do
s' <- unsafeInterleaveIO receiveAll'
return $ s:s'
receiveAll :: Ptr TCPSocketConnectionT -> IO [String]
receiveAll tcp = unsafeInterleaveIO receiveAll' where
receiveAll' = do
s <- tcpSocketConnection_receive tcp
if s == "" then return [] else do
s' <- unsafeInterleaveIO receiveAll'
return $ s:s'
21. えっと何がうれしいの?えっと何がうれしいの?えっと何がうれしいの?えっと何がうれしいの?えっと何がうれしいの?
main = do
ethernetInitDhcp
ethernetConnect 12000
ethernetGetIpAddress
tcp <- tcpSocketConnection_connect host 80
tcpSocketConnection_send_all tcp $ "GET /hoge.txt HTTP/1.0nn"
r <- receiveAll tcp
main = do
ethernetInitDhcp
ethernetConnect 12000
ethernetGetIpAddress
tcp <- tcpSocketConnection_connect host 80
tcpSocketConnection_send_all tcp $ "GET /hoge.txt HTTP/1.0nn"
r <- receiveAll tcp
main = do
ethernetInitDhcp
ethernetConnect 12000
ethernetGetIpAddress
tcp <- tcpSocketConnection_connect host 80
tcpSocketConnection_send_all tcp $ "GET /hoge.txt HTTP/1.0nn"
r <- receiveAll tcp
main = do
ethernetInitDhcp
ethernetConnect 12000
ethernetGetIpAddress
tcp <- tcpSocketConnection_connect host 80
tcpSocketConnection_send_all tcp $ "GET /hoge.txt HTTP/1.0nn"
r <- receiveAll tcp
main = do
ethernetInitDhcp
ethernetConnect 12000
ethernetGetIpAddress
tcp <- tcpSocketConnection_connect host 80
tcpSocketConnection_send_all tcp $ "GET /hoge.txt HTTP/1.0nn"
r <- receiveAll tcp
☆ この時"r"には単なるリストが返ってくる☆ この時"r"には単なるリストが返ってくる☆ この時"r"には単なるリストが返ってくる☆ この時"r"には単なるリストが返ってくる☆ この時"r"には単なるリストが返ってくる
☆ このリストを単に読むと☆ このリストを単に読むと☆ このリストを単に読むと☆ このリストを単に読むと☆ このリストを単に読むと
☆ lwIPが自動的にパケットを読んでくれる!☆ lwIPが自動的にパケットを読んでくれる!☆ lwIPが自動的にパケットを読んでくれる!☆ lwIPが自動的にパケットを読んでくれる!☆ lwIPが自動的にパケットを読んでくれる!
☆ このリストをRSSパーサに直接突っ込める☆ このリストをRSSパーサに直接突っ込める☆ このリストをRSSパーサに直接突っ込める☆ このリストをRSSパーサに直接突っ込める☆ このリストをRSSパーサに直接突っ込める