2020/6/11

Modify OpenRadar command code

python code to command DCA1000EVM Start/Stop Record
把這個啟動命令寫到 adc.py:

adc.py 的 command 宣告:
class CMD(Enum):
    RESET_FPGA_CMD_CODE = '0100'
    RESET_AR_DEV_CMD_CODE = '0200'
    CONFIG_FPGA_GEN_CMD_CODE = '0300'
    CONFIG_EEPROM_CMD_CODE = '0400'
    RECORD_START_CMD_CODE = '0500'
    RECORD_STOP_CMD_CODE = '0600'
    PLAYBACK_START_CMD_CODE = '0700'
    PLAYBACK_STOP_CMD_CODE = '0800'
    SYSTEM_CONNECT_CMD_CODE = '0900'
    SYSTEM_ERROR_CMD_CODE = '0a00'
    CONFIG_PACKET_DATA_CMD_CODE = '0b00'
    CONFIG_DATA_MODE_AR_DEV_CMD_CODE = '0c00'
    INIT_FPGA_PLAYBACK_CMD_CODE = '0d00'
    READ_FPGA_VERSION_CMD_CODE = '0e00'
對應ref 的內容,依序是送...
  • 5aa50300060001020102031eaaee : CONFIG_FPGA_GEN_CMD_CODE
  • 5aa509000000aaee : SYSTEM_CONNECT_CMD_COD
  • 5aa505000000aaee : RECORD_START_CMD_COD
然後停止的 command 是:
  • 5aa506000000aaee : RECORD_STOP_CMD_CODE
除了第一個 FPGA_GEN_CMD 之外,都沒有 data。

send command 的 function 是
    def _send_command(self, cmd, length='0000', body='', timeout=1):
        """Helper function to send a single commmand to the FPGA

        Args:
            cmd (CMD): Command code to send to the FPGA
            length (str): Length of the body of the command (if any)
            body (str): Body information of the command
            timeout (int): Time in seconds to wait for socket data until timeout

        Returns:
            str: Response message

        """
        # Create timeout exception
        self.config_socket.settimeout(timeout)

        # Create and send message
        resp = ''
        msg = codecs.decode(''.join((CONFIG_HEADER, str(cmd), length, body, CONFIG_FOOTER)), 'hex')
        try:
            self.config_socket.sendto(msg, self.cfg_dest)
            resp, addr = self.config_socket.recvfrom(MAX_PACKET_SIZE)
        except socket.timeout as e:
            print(e)
        return resp
所以對應上面的命令應該是...
_send_command(CONFIG_FPGA_GEN_CMD_CODE,'0600','01020102031e')
_send_command(SYSTEM_CONNECT_CMD_COD)
_send_command(RECORD_START_CMD_COD)
然後停止是
_send_command(RECORD_STOP_CMD_CODE)
所以在 adc.py 中增加兩個 functions:
    def send_start_command(self):
        print(self._send_command(CMD.CONFIG_FPGA_GEN_CMD_CODE,'0600','01020102031e'))
        print(self._send_command(CMD.SYSTEM_CONNECT_CMD_CODE))
        print(self._send_command(CMD.RECORD_START_CMD_CODE))
    
    def send_stop_command(self):
        print(self._send_command(CMD.RECORD_STOP_CMD_CODE))

沒有留言:

張貼留言