argument_parser.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Copyright 2015-2021 Espressif Systems (Shanghai) CO LTD
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import argparse
  15. import os
  16. from .constants import DEFAULT_PRINT_FILTER, DEFAULT_TOOLCHAIN_PREFIX, PANIC_DECODE_BACKTRACE, PANIC_DECODE_DISABLE
  17. from .coredump import COREDUMP_DECODE_DISABLE, COREDUMP_DECODE_INFO
  18. def get_parser(): # type: () -> argparse.ArgumentParser
  19. parser = argparse.ArgumentParser('idf_monitor - a serial output monitor for esp-idf')
  20. parser.add_argument(
  21. '--port', '-p',
  22. help='Serial port device',
  23. default=os.environ.get('ESPTOOL_PORT', '/dev/ttyUSB0')
  24. )
  25. parser.add_argument(
  26. '--disable-address-decoding', '-d',
  27. help="Don't print lines about decoded addresses from the application ELF file",
  28. action='store_true',
  29. default=os.environ.get('ESP_MONITOR_DECODE') == 0
  30. )
  31. parser.add_argument(
  32. '--baud', '-b',
  33. help='Serial port baud rate',
  34. type=int,
  35. default=os.getenv('IDF_MONITOR_BAUD', os.getenv('MONITORBAUD', 115200)))
  36. parser.add_argument(
  37. '--make', '-m',
  38. help='Command to run make',
  39. type=str, default='make')
  40. parser.add_argument(
  41. '--encrypted',
  42. help='Use encrypted targets while running make',
  43. action='store_true')
  44. parser.add_argument(
  45. '--toolchain-prefix',
  46. help='Triplet prefix to add before cross-toolchain names',
  47. default=DEFAULT_TOOLCHAIN_PREFIX)
  48. parser.add_argument(
  49. '--eol',
  50. choices=['CR', 'LF', 'CRLF'],
  51. type=lambda c: c.upper(),
  52. help='End of line to use when sending to the serial port',
  53. default='CR')
  54. parser.add_argument(
  55. 'elf_file', help='ELF file of application',
  56. type=argparse.FileType('rb'))
  57. parser.add_argument(
  58. '--print_filter',
  59. help='Filtering string',
  60. default=DEFAULT_PRINT_FILTER)
  61. parser.add_argument(
  62. '--decode-coredumps',
  63. choices=[COREDUMP_DECODE_INFO, COREDUMP_DECODE_DISABLE],
  64. default=COREDUMP_DECODE_INFO,
  65. help='Handling of core dumps found in serial output'
  66. )
  67. parser.add_argument(
  68. '--decode-panic',
  69. choices=[PANIC_DECODE_BACKTRACE, PANIC_DECODE_DISABLE],
  70. default=PANIC_DECODE_DISABLE,
  71. help='Handling of panic handler info found in serial output'
  72. )
  73. parser.add_argument(
  74. '--target',
  75. help='Target name (used when stack dump decoding is enabled)',
  76. default=os.environ.get('IDF_TARGET', 'esp32')
  77. )
  78. parser.add_argument(
  79. '--revision',
  80. help='Revision of the target',
  81. type=int,
  82. default=0
  83. )
  84. parser.add_argument(
  85. '--ws',
  86. default=os.environ.get('ESP_IDF_MONITOR_WS', None),
  87. help='WebSocket URL for communicating with IDE tools for debugging purposes'
  88. )
  89. parser.add_argument(
  90. '--timestamps',
  91. help='Add timestamp for each line',
  92. default=False,
  93. action='store_true')
  94. parser.add_argument(
  95. '--timestamp-format',
  96. default=os.environ.get('ESP_IDF_MONITOR_TIMESTAMP_FORMAT', '%Y-%m-%d %H:%M:%S'),
  97. help='Set a strftime()-compatible timestamp format'
  98. )
  99. return parser