【问题标题】:Print system time when getting data from a local IP server从本地 IP 服务器获取数据时打印系统时间
【发布时间】:2017-01-05 14:14:37
【问题描述】:

我正在尝试使用https://devzone.nordicsemi.com/question/83524/how-to-use-rtt-viewer-or-similar-on-gnulinux/此处描述的方法调试嵌入式软件

调试器所做的是设置一个本地主机服务器,该服务器提供来自被测嵌入式设备的所有类似 printf 的消息。基本上我在使用命令telnet localhost 19021时得到调试输出

我想要打印一个,系统时间和两个,从上一条消息经过的时间以及收到的调试消息。这将帮助我以毫秒(甚至微秒?)为单位了解调试消息的确切时间。我怎样才能轻松做到这一点?谢谢。

【问题讨论】:

    标签: localhost systemtime


    【解决方案1】:

    使用 Python,可以使用socket 接收来自服务器的数据。下面的 sn-p 完成从套接字接收数据并打印接收时间的工作。

    # Create a TCP/IP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    # Bind the socket to the port
    server_address = ('localhost', 19021)
    
    print "Connecting to the server @",server_address
    sock.connect(server_address)
    
    time.sleep(1)
    
    past = 0
    base = 0
    
    while True:
        #read up to 1000 bytes from the socket (the max amount)
        rcv=sock.recv(1000)
    
        #we didn't get any data.
        if rcv=="":
            continue
    
        #Set base time as the time when first character is received
        if not base:
            base = time.time()
    
        current = time.time()
        elapsed = current - base
        delta = elapsed - past
        past = elapsed 
    
        current_str = datetime.datetime.now().strftime("%H:%M:%S.%f")
        print_msg = "[%s %2.6f] " % (current_str, delta)
        print (print_msg + rcv).strip()
    

    对于调试基于nRF5 SoC的嵌入式应用程序的具体案例,如问题中的链接,完整的脚本可以在这里找到https://github.com/Appiko/nrf5x-firmware/blob/master/utils/rtt_logger.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 2018-02-28
      • 2020-03-21
      • 2016-11-24
      • 1970-01-01
      相关资源
      最近更新 更多