Subversion Repositories Projects

Rev

Rev 696 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 696 Rev 697
Line 54... Line 54...
54
 
54
 
55
class MkMsg:
55
class MkMsg:
56
    def __init__(self, msg=None, address=None, cmd=None, data=None):
56
    def __init__(self, msg=None, address=None, cmd=None, data=None):
57
        if (msg != None):
57
        if (msg != None):
58
            # Create instance based on received message
58
            # Create instance based on received message
59
            self.parse(msg)
59
            self.parseUartLine(msg)
60
        elif (address != None and cmd != None and data != None):
60
        elif (address != None and cmd != None and data != None):
61
            # Create instance based on address, command and data
61
            # Create instance based on address, command and data
62
            self.address = address
62
            self.address = address
63
            self.cmd = cmd
63
            self.cmd = cmd
64
            self.data = data
64
            self.data = data
65
        else:
65
        else:
66
            # Cannot create instance
66
            # Cannot create instance
Line 67... Line 67...
67
            raise InvalidArguments
67
            raise InvalidArguments
68
 
68
 
Line 69... Line 69...
69
    def generateMsg(self):
69
    def generateUartLine(self):
70
        msg = ""
70
        msg = ""
71
 
71
 
Line 98... Line 98...
98
        msg += crc1 + crc2
98
        msg += crc1 + crc2
99
        msg += '\r'
99
        msg += '\r'
100
        return msg
100
        return msg
Line 101... Line 101...
101
 
101
 
102
 
102
 
103
    def parse(self, msg):
103
    def parseUartLine(self, msg):
104
        if len(msg)<6:
104
        if len(msg)<6:
105
            raise InvalidMsg()
105
            raise InvalidMsg()
106
        if (msg[0] != '#'):
106
        if (msg[0] != '#'):
Line 238... Line 238...
238
 
238
 
239
        self.serPort = None
239
        self.serPort = None
Line 240... Line 240...
240
        self.printDebugMsg = printDebugMsg
240
        self.printDebugMsg = printDebugMsg
241
 
241
 
242
        msg = MkMsg(address=0, cmd='v', data=[])
242
        msg = MkMsg(address=0, cmd='v', data=[])
243
        self.getVersionMsgLn = msg.generateMsg()
243
        self.getVersionMsgLn = msg.generateUartLine()
Line 244... Line 244...
244
        msg = MkMsg(address=0, cmd='d', data=[500])
244
        msg = MkMsg(address=0, cmd='d', data=[500])
245
        self.getDebugMsgLn = msg.generateMsg()
245
        self.getDebugMsgLn = msg.generateUartLine()
246
       
246
       
Line 280... Line 280...
280
        return msg
280
        return msg
Line 281... Line 281...
281
 
281
 
282
    def sendNCRedirectUartFromFC(self):
282
    def sendNCRedirectUartFromFC(self):
283
        self.serPort.flushInput()
283
        self.serPort.flushInput()
284
        msg = MkMsg(address=MkComm.ADDRESS_NC, cmd='u', data=[0])
284
        msg = MkMsg(address=MkComm.ADDRESS_NC, cmd='u', data=[0])
285
        self.sendLn(msg.generateMsg())
285
        self.sendLn(msg.generateUartLine())
286
        time.sleep(.5)
286
        time.sleep(.5)
Line 287... Line 287...
287
        # No reply expected...   
287
        # No reply expected...   
288
       
288
       
289
    def sendSettings(self, settings):
289
    def sendSettings(self, settings):
290
        msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='s', data=settings)
290
        msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='s', data=settings)
291
        self.sendLn(msg.generateMsg())
291
        self.sendLn(msg.generateUartLine())
Line 292... Line 292...
292
        time.sleep(1)
292
        time.sleep(1)
293
        msg = self.waitForMsg('S')
293
        msg = self.waitForMsg('S')
Line 300... Line 300...
300
        return msg
300
        return msg
Line 301... Line 301...
301
   
301
   
302
    def getSettingsMsg(self, index=0xFF):
302
    def getSettingsMsg(self, index=0xFF):
303
        self.serPort.flushInput()
303
        self.serPort.flushInput()
304
        msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='q', data=[index])
304
        msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='q', data=[index])
305
        self.sendLn(msg.generateMsg())
305
        self.sendLn(msg.generateUartLine())
306
        msg = self.waitForMsg('Q')
306
        msg = self.waitForMsg('Q')
307
        msg = SettingsMsg(msg)
307
        msg = SettingsMsg(msg)
Line 308... Line 308...
308
        return msg
308
        return msg
Line 313... Line 313...
313
        msg = VersionMsg(msg)
313
        msg = VersionMsg(msg)
314
        return msg
314
        return msg
Line 315... Line 315...
315
 
315
 
316
    def setMotorTest(self, motorSpeeds):
316
    def setMotorTest(self, motorSpeeds):
317
        msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='t', data=motorSpeeds)
317
        msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='t', data=motorSpeeds)
Line 318... Line 318...
318
        self.sendLn(msg.generateMsg())
318
        self.sendLn(msg.generateUartLine())
319
       
319
       
320
    def doVibrationTest(self, nbSamples, channel):
320
    def doVibrationTest(self, nbSamples, channel):
321
        data = []
321
        data = []
322
        for i in range(0,(min(nbSamples,1000)/50)):
322
        for i in range(0,(min(nbSamples,1000)/50)):
323
          msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='f', data=[channel, i])
323
          msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='f', data=[channel, i])
324
          self.sendLn(msg.generateMsg())
324
          self.sendLn(msg.generateUartLine())
325
          msg = self.waitForMsg('F')
325
          msg = self.waitForMsg('F')
Line 326... Line 326...
326
          msg = VibrationDataMsg(msg)
326
          msg = VibrationDataMsg(msg)