Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

#!/usr/bin/env python 

 

""" 

@file ion/agents/instrumentagents/instrument_connection.py 

@author Dave Everett 

@brief Instrument Connection Object 

""" 

 

import ion.util.ionlog 

log = ion.util.ionlog.getLogger(__name__) 

from twisted.internet import defer, reactor 

 

from twisted.internet.protocol import Protocol 

 

class InstrumentConnection(Protocol): 

    """ 

    The InstrumentConnection class; inherits from Protocol.  Override 

    connectionMade, connectionLost, and dataReceived and call parent methods 

    for detailed handling.   

    """ 

    def __init__(self, parent): 

        self.parent = parent 

 

    def connectionMade(self): 

        log.debug("connectionMade, calling gotConnected().") 

        self.parent.gotConnected(self) 

 

    def connectionLost(self, reason): 

        log.debug("connectionLost, calling gotDisconnected()") 

        self.parent.gotDisconnected(self) 

 

    def dataReceived(self, data): 

        """ 

        Filter the data; the instrument will send the 

        prompt, which we don't care about, I'm assuming.  We might need a sort 

        of state machine or something; for instance, the agent sends a getStatus 

        command, we need to know that we're expecting a status message. 

        """ 

        #log.debug("dataReceived! Length: %s, data-[%s]" %(len(data), data)) 

        self.parent.gotData(data)