能源管控程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

134 lines
3.6 KiB

  1. #!/bin/bash
  2. echo "Installing Python Wheel ..."
  3. pip install wheel > /dev/null 2>&1
  4. echo "Installing PlatformIO ..."
  5. pip install -U platformio > /dev/null 2>&1
  6. echo "PlatformIO has been installed"
  7. echo ""
  8. function build_pio_sketch(){ # build_pio_sketch <board> <path-to-ino>
  9. if [ "$#" -lt 2 ]; then
  10. echo "ERROR: Illegal number of parameters"
  11. echo "USAGE: build_pio_sketch <board> <path-to-ino>"
  12. return 1
  13. fi
  14. local board="$1"
  15. local sketch="$2"
  16. local sketch_dir=$(dirname "$sketch")
  17. echo ""
  18. echo "Compiling '"$(basename "$sketch")"' ..."
  19. python -m platformio ci -l '.' --board "$board" "$sketch_dir" --project-option="board_build.partitions = huge_app.csv"
  20. }
  21. function count_sketches() # count_sketches <examples-path>
  22. {
  23. local examples="$1"
  24. rm -rf sketches.txt
  25. if [ ! -d "$examples" ]; then
  26. touch sketches.txt
  27. return 0
  28. fi
  29. local sketches=$(find $examples -name *.ino)
  30. local sketchnum=0
  31. for sketch in $sketches; do
  32. local sketchdir=$(dirname $sketch)
  33. local sketchdirname=$(basename $sketchdir)
  34. local sketchname=$(basename $sketch)
  35. if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
  36. continue
  37. fi;
  38. if [[ -f "$sketchdir/.test.skip" ]]; then
  39. continue
  40. fi
  41. echo $sketch >> sketches.txt
  42. sketchnum=$(($sketchnum + 1))
  43. done
  44. return $sketchnum
  45. }
  46. function build_pio_sketches() # build_pio_sketches <board> <examples-path> <chunk> <total-chunks>
  47. {
  48. if [ "$#" -lt 2 ]; then
  49. echo "ERROR: Illegal number of parameters"
  50. echo "USAGE: build_pio_sketches <board> <examples-path> [<chunk> <total-chunks>]"
  51. return 1
  52. fi
  53. local board=$1
  54. local examples=$2
  55. local chunk_idex=$3
  56. local chunks_num=$4
  57. if [ "$#" -lt 4 ]; then
  58. chunk_idex="0"
  59. chunks_num="1"
  60. fi
  61. if [ "$chunks_num" -le 0 ]; then
  62. echo "ERROR: Chunks count must be positive number"
  63. return 1
  64. fi
  65. if [ "$chunk_idex" -ge "$chunks_num" ]; then
  66. echo "ERROR: Chunk index must be less than chunks count"
  67. return 1
  68. fi
  69. set +e
  70. count_sketches "$examples"
  71. local sketchcount=$?
  72. set -e
  73. local sketches=$(cat sketches.txt)
  74. rm -rf sketches.txt
  75. local chunk_size=$(( $sketchcount / $chunks_num ))
  76. local all_chunks=$(( $chunks_num * $chunk_size ))
  77. if [ "$all_chunks" -lt "$sketchcount" ]; then
  78. chunk_size=$(( $chunk_size + 1 ))
  79. fi
  80. local start_index=$(( $chunk_idex * $chunk_size ))
  81. if [ "$sketchcount" -le "$start_index" ]; then
  82. echo "Skipping job"
  83. return 0
  84. fi
  85. local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
  86. if [ "$end_index" -gt "$sketchcount" ]; then
  87. end_index=$sketchcount
  88. fi
  89. local start_num=$(( $start_index + 1 ))
  90. echo "Found $sketchcount Sketches";
  91. echo "Chunk Count : $chunks_num"
  92. echo "Chunk Size : $chunk_size"
  93. echo "Start Sketch: $start_num"
  94. echo "End Sketch : $end_index"
  95. local sketchnum=0
  96. for sketch in $sketches; do
  97. local sketchdir=$(dirname $sketch)
  98. local sketchdirname=$(basename $sketchdir)
  99. local sketchname=$(basename $sketch)
  100. if [ "${sketchdirname}.ino" != "$sketchname" ] \
  101. || [ -f "$sketchdir/.test.skip" ]; then
  102. continue
  103. fi
  104. sketchnum=$(($sketchnum + 1))
  105. if [ "$sketchnum" -le "$start_index" ] \
  106. || [ "$sketchnum" -gt "$end_index" ]; then
  107. continue
  108. fi
  109. build_pio_sketch "$board" "$sketch"
  110. local result=$?
  111. if [ $result -ne 0 ]; then
  112. return $result
  113. fi
  114. done
  115. return 0
  116. }