text:
1.115" width="0.254" layer="1"/>
<wire x1="38.735" y1="29.21" x2="16.51" y2="29.21" width="0.254" layer="1"/>
<wire x1="39.0525" y1="29.5275" x2="38.735" y2="29.21" width="0.254" layer="1"/>
<wire x1="44.45" y1="29.5275" x2="39.0525" y2="29.5275" width="0.254" layer="1"/>
<wire x1="45.085" y1="28.8925" x2="44.45" y2="29.5275" width="0.254" layer="1"/>
<wire x1="45.085" y1="37.7825" x2="45.085" y2="28.8925" width="0.254" layer="16"/>
<wire x1="45.72" y1="38.4175" x2="45.085" y2="37.7825" width="0.254" layer="1"/>
<wire x1="58.42" y1="38.4175" x2="45.72" y2="38.4175" width="0.254" layer="1"/>
<wire x1="59.055" y1="39.0525" x2="58.42" y2="38.4175" width="0.254" layer="1"/>
<wire x1="61.9125" y1="39.0525" x2="59.055" y2="39.0525" width="0.254" layer="1"/>
<wire x1="62.23" y1="39.37" x2="61.9125" y2="39.0525" width="0.254" layer="16"/>
<wire x1="62.23" y1="51.435" x2="62.23" y2="39.37" width="0.254" layer="16"/>
<wire x1="61.9125" y1="51.7525" x2="62.23" y2="51.435" width="0.254" layer="16"/>
<wire x1="61.9125" y1="60.0075" x2="61.9125" y2="51.7525" width="0.254" layer="16"/>
<wire x1="60.96" y1="60.96" x2="61.9125" y2="60.0075" width="0.254" layer="16"/>
<wire x1="9.2075" y1="31.75" x2="9.144" y2="31.7246" width="0.254" layer="1"/>
<via x="45.085" y="28.8925" extent="1-16" drill="0.6096"/>
<via x="45.085" y="37.7825" extent="1-16" drill="0.6096"/>
<via x="61.9125" y="39.0525" extent="1-16" drill="0.6096"/>
</signal>
<signal name="N$27">
<contactref element="JP7" pad="5"/>
<contactref element="ADCH" pad="4"/>
<wire x1="2.8575" y1="63.8175" x2="5.08" y2="66.04" width="0.254" layer="1"/>
<wire x1="2.8575" y1="62.23" x2="2.8575" y2="63.8175" width="0.254" layer="1"/>
<wire x1="12.3825" y1="62.23" x2="2.8575" y2="62.23" width="0.254" layer="1"/>
<wire x1="13.97" y1="63.8175" x2="12.3825" y2="62.23" width="0.254" layer="1"/>
<wire x1="24.765" y1="63.8175" x2="13.97" y2="63.8175" width="0.254" layer="1"/>
<wire x1="25.4" y1="63.1825" x2="24.765" y2="63.8175" width="0.254" layer="1"/>
<wire x1="25.7175" y1="63.1825" x2="25.4" y2="63.1825" width="0.254" layer="1"/>
<wire x1="27.94" y1="60.96" x2="25.7175" y2="63.1825" width="0.254" layer="1"/>
</signal>
<signal name="N$28">
<contactref element="JP7" pad="4"/>
<contactref element="ADCH" pad="5"/>
<wire x1="2.2225" y1="65.7225" x2="5.08" y2="68.58" width="0.254" layer="1"/>
<wire x1="2.2225" y1="57.4675" x2="2.2225" y2="65.7225" width="0.254" layer="1"/>
<wire x1="28.575" y1="57.4675" x2="2.2225" y2="57.4675" width="0.254" layer="1"/>
<wire x1="30.48" y1="59.3725" x2="28.575" y2="57.4675" width="0.254" layer="1"/>
<wire x1="30.48" y1="60.96" x2="30.48" y2="59.3725" width="0.254" layer="1"/>
</signal>
<signal name="SS3">
<contactref element="X5" pad="6"/>
<contactref element="XIOL" pad="6"/>
<wire x1="24.13" y1="66.675" x2="26.035" y2="68.58" width="0.254" layer="16"/>
<wire x1="24.13" y1="54.61" x2="24.13" y2="66.675" width="0.254" layer="16"/>
<wire x1="17.78" y1="48.26" x2="24.13" y2="54.61" width="0.254" layer="16"/>
<wire x1="26.035" y1="68.58" x2="26.289" y2="68.58" width="0.254" layer="16"/>
</signal>
<signal name="STEER">
<contactref element="PWML" pad="8"/>
<contactref element="JP12" pad="2"/>
<wire x1="48.5775" y1="2.2225" x2="45.72" y2="5.08" width="0.254" layer="16"/>
<wire x1="63.5" y1="2.2225" x2="48.5775" y2="2.2225" width="0.254" layer="16"/>
<wire x1="63.5" y1="10.16" x2="63.5" y2="2.2225" width="0.254" layer="16"/>
<wire x1="66.04" y1="12.7" x2="63.5" y2="10.16" width="0.254" layer="16"/>
</signal>
<signal name="CRUISE">
<contactref element="JP9" pad="6"/>
<contactref element="XIOH" pad="1"/>
<wire x1="20.6375" y1="2.8575" x2="22.86" y2="5.08" width="0.254" layer="16"/>
<wire x1="10.795" y1="2.8575" x2="20.6375" y2="2.8575" width="0.254" layer="16"/>
<wire x1="10.795" y1="7.62" x2="10.795" y2="2.8575" width="0.254" layer="16"/>
<wire x1="6.35" y1="12.065" x2="10.795" y2="7.62" width="0.254" layer="16"/>
<wire x1="5.08" y1="13.335" x2="6.35" y2="12.065" width="0.254" layer="1"/>
<wire x1="5.08" y1="17.78" x2="5.08" y2="13.335" width="0.254" layer="1"/>
<wire x1="6.985" y1="17.78" x2="5.08" y2="17.78" width="0.254" layer="1"/>
<wire x1="7.9375" y1="18.7325" x2="6.985" y2="17.78" width="0.254" layer="1"/>
<wire x1="7.9375" y1="20.0025" x2="7.9375" y2="18.7325" width="0.254" layer="1"/>
<wire x1="7.3025" y1="20.6375" x2="7.9375" y2="20.0025" width="0.254" layer="1"/>
<wire x1="5.715" y1="20.6375" x2="7.3025" y2="20.6375" width="0.254" layer="1"/>
<wire x1="1.905" y1="24.4475" x2="5.715" y2="20.6375" width="0.254" layer="1"/>
<wire x1="1.905" y1="37.1475" x2="1.905" y2="24.4475" width="0.254" layer="1"/>
<wire x1="7.3025" y1="37.1475" x2="1.905" y2="37.1475" width="0.254" layer="1"/>
<wire x1="8.5725" y1="35.8775" x2="7.3025" y2="37.1475" width="0.254" layer="1"/>
<wire x1="12.3825" y1="35.8775" x2="8.5725" y2="35.8775" width="0.254" layer="1"/>
<wire x1="15.24" y1="33.02" x2="12.3825" y2="35.8775" width="0.254" layer="16"/>
<via x="6.35" y="12.065" extent="1-16" drill="0.6096"/>
<via x="12.3825" y="35.8775" extent="1-16" drill="0.6096"/>
</signal>
<signal name="JSPARE">
<contactref element="JP9" pad="8"/>
<contactref element="XIOH" pad="3"/>
<wire x1="12.065" y1="10.795" x2="17.78" y2="5.08" width="0.254" layer="16"/>
<wire x1="5.715" y1="10.795" x2="12.065" y2="10.795" width="0.254" layer="1"/>
<wire x1="4.445" y1="12.065" x2="5.715" y2="10.795" width="0.254" layer="16"/>
<wire x1="4.445" y1="31.75" x2="4.445" y2="12.065" width="0.254" layer="16"/>
<wire x1="7.3025" y1="31.75" x2="4.445" y2="31.75" width="0.254" layer="1"/>
<wire x1="8.5725" y1="30.48" x2="7.3025" y2="31.75" width="0.254" layer="1"/>
<wire x1="15.24" y1="30.48" x2="8.5725" y2="30.48" width="0.254" layer="1"/>
<via x="12.065" y="10.795" extent="1-16" drill="0.6096"/>
<via x="5.715" y="10.795" extent="1-16" drill="0.6096"/>
<via x="4.445" y="31.75" extent="1-16" drill="0.6096"/>
</signal>
<signal name="5V">
<contactref element="JP12" pad="1"/>
<contactref element="JP10" pad="2"/>
<wire x1="52.07" y1="21.59" x2="60.96" y2="21.59" width="0.254" layer="1"/>
<wire x1="52.07" y1="8.89" x2="52.07" y2="21.59" width="0.254" layer="16"/>
<wire x1="48.26" y1="5.08" x2="52.07" y2="8.89" width="0.254" layer="16"/>
<via x="52.07" y="21.59" extent="1-16" drill="0.6096"/>
</signal>
<signal name="VIN">
<contactref element="X1" pad="2"/>
<contactref element="X5" pad="2"/>
<contactref element="POWER" pad="6"/>
<wire x1="33.02" y1="66.9925" x2="31.4325" y2="68.58" width="0.254" layer="16"/>
<wire x1="33.02" y1="65.405" x2="33.02" y2="66.9925" width="0.254" layer="16"/>
<wire x1="50.165" y1="65.405" x2="33.02" y2="65.405" width="0.254" layer="1"/>
<wire x1="52.3875" y1="67.6275" x2="50.165" y2="65.405" width="0.254" layer="1"/>
<wire x1="52.3875" y1="68.2625" x2="52.3875" y2="67.6275" width="0.254" layer="1"/>
<wire x1="31.4325" y1="68.58" x2="31.369" y2="68.58" width="0.254" layer="16"/>
<wire x1="52.3875" y1="68.2625" x2="52.451" y2="68.326" width="0.254" layer="1"/>
<wire x1="62.865" y1="64.135" x2="66.04" y2="60.96" width="0.254" layer="1"/>
<wire x1="55.88" y1="64.135" x2="62.865" y2="64.135" width="0.254" layer="1"/>
<wire x1="52.3875" y1="67.6275" x2="55.88" y2="64.135" width="0.254" layer="1"/>
<wire x1="52.3875" y1="67.6275" x2="52.451" y2="68.326" width="0.254" layer="1"/>
<via x="33.02" y="65.405" extent="1-16" drill="0.6096"/>
</signal>
<signal name="HALLPHASEA">
<contactref element="X3" pad="2"/>
<contactref element="COMM_DIG" pad="1"/>
<wire x1="28.8925" y1="9.2075" x2="25.4" y2="12.7" width="0.254" layer="1"/>
<wire x1="52.3875" y1="9.2075" x2="28.8925" y2="9.2075" width="0.254" layer="1"/>
<wire x1="53.0225" y1="9.8425" x2="52.3875" y2="9.2075" width="0.254" layer="1"/>
<wire x1="86.36" y1="9.8425" x2="53.0225" y2="9.8425" width="0.254" layer="1"/>
<wire x1="86.36" y1="21.9075" x2="86.36" y2="9.8425" width="0.254" layer="16"/>
<wire x1="86.0425" y1="22.225" x2="86.36" y2="21.9075" width="0.254" layer="16"/>
<wire x1="86.0425" y1="35.56" x2="86.0425" y2="22.225" width="0.254" layer="16"/>
<wire x1="86.6775" y1="36.195" x2="86.0425" y2="35.56" width="0.254" layer="16"/>
<wire x1="86.6775" y1="56.515" x2="86.6775" y2="36.195" width="0.254" layer="16"/>
<wire x1="86.0425" y1="57.15" x2="86.6775" y2="56.515" width="0.254" layer="16"/>
<wire x1="86.0425" y1="65.7225" x2="86.0425" y2="57.15" width="0.254" layer="16"/>
<wire x1="86.6775" y1="66.3575" x2="86.0425" y2="65.7225" width="0.254" layer="16"/>
<wire x1="86.6775" y1="72.0725" x2="86.6775" y2="66.3575" width="0.254" layer="16"/>
<wire x1="86.6775" y1="72.0725" x2="86.9315" y2="72.3887" width="0.254" layer="16"/>
<via x="86.36" y="9.8425" extent="1-16" drill="0.6096"/>
</signal>
<signal name="HALLPHASEC">
<contactref element="X3" pad="8"/>
<contactref element="COMM_DIG" pad="3"/>
<wire x1="31.75" y1="11.43" x2="30.48" y2="12.7" width="0.254" layer="16"/>
<wire x1="31.75" y1="3.81" x2="31.75" y2="11.43" width="0.254" layer="16"/>
<wire x1="34.29" y1="1.27" x2="31.75" y2="3.81" width="0.254" layer="16"/>
<wire x1="44.45" y1="1.27" x2="34.29" y2="1.27" width="0.254" layer="16"/>
<wire x1="44.45" y1="9.2075" x2="44.45" y2="1.27" width="0.254" layer="16"/>
<wire x1="46.99" y1="11.7475" x2="44.45" y2="9.2075" width="0.254" layer="16"/>
<wire x1="46.99" y1="23.495" x2="46.99" y2="11.7475" width="0.254" layer="16"/>
<wire x1="50.4825" y1="23.495" x2="46.99" y2="23.495" width="0.254" layer="1"/>
<wire x1="52.705" y1="25.7175" x2="50.4825" y2="23.495" width="0.254" layer="1"/>
<wire x1="66.9925" y1="25.7175" x2="52.705" y2="25.7175" width="0.254" layer="1"/>
<wire x1="68.58" y1="27.305" x2="66.9925" y2="25.7175" width="0.254" layer="16"/>
<wire x1="68.58" y1="32.7025" x2="68.58" y2="27.305" width="0.254" layer="16"/>
<wire x1="81.28" y1="32.7025" x2="68.58" y2="32.7025" width="0.254" layer="1"/>
<wire x1="81.5975" y1="33.02" x2="81.28" y2="32.7025" width="0.254" layer="16"/>
<wire x1="81.5975" y1="36.5125" x2="81.5975" y2="33.02" width="0.254" layer="16"/>
<wire x1="80.9625" y1="37.1475" x2="81.5975" y2="36.5125" width="0.254" layer="16"/>
<wire x1="80.9625" y1="51.435" x2="80.9625" y2="37.1475" width="0.254" layer="16"/>
<wire x1="82.2325" y1="52.705" x2="80.9625" y2="51.435" width="0.254" layer="16"/>
<wire x1="82.2325" y1="62.865" x2="82.2325" y2="52.705" width="0.254" layer="16"/>
<wire x1="78.74" y1="66.3575" x2="82.2325" y2="62.865" width="0.254" layer="16"/>
<wire x1="78.74" y1="69.5325" x2="78.74" y2="66.3575" width="0.254" layer="16"/>
<wire x1="77.47" y1="70.8025" x2="78.74" y2="69.5325" width="0.254" layer="16"/>
<wire x1="70.485" y1="70.8025" x2="77.47" y2="70.8025" width="0.254" layer="16"/>
<wire x1="70.485" y1="72.0725" x2="70.485" y2="70.8025" width="0.254" layer="16"/>
<wire x1="70.485" y1="72.0725" x2="70.3199" y2="72.3887" width="0.254" layer="16"/>
<via x="46.99" y="23.495" extent="1-16" drill="0.6096"/>
<via x="66.9925" y="25.7175" extent="1-16" drill="0.6096"/>
<via x="68.58" y="32.7025" extent="1-16" drill="0.6096"/>
<via x="81.28" y="32.7025" extent="1-16" drill="0.6096"/>
</signal>
<signal name="FWDSW">
<contactref element="X3" pad="9"/>
<contactref element="XIOH" pad="4"/>
<wire x1="18.415" y1="29.845" x2="17.78" y2="30.48" width="0.254" layer="1"/>
<wire x1="38.4175" y1="29.845" x2="18.415" y2="29.845" width="0.254" layer="1"/>
<wire x1="38.735" y1="30.1625" x2="38.4175" y2="29.845" width="0.254" layer="1"/>
<wire x1="45.72" y1="30.1625" x2="38.735" y2="30.1625" width="0.254" layer="1"/>
<wire x1="46.355" y1="29.5275" x2="45.72" y2="30.1625" width="0.254" layer="1"/>
<wire x1="46.355" y1="24.4475" x2="46.355" y2="29.5275" width="0.254" layer="16"/>
<wire x1="45.72" y1="23.8125" x2="46.355" y2="24.4475" width="0.254" layer="16"/>
<wire x1="45.72" y1="20.955" x2="45.72" y2="23.8125" width="0.254" layer="16"/>
<wire x1="51.1175" y1="20.955" x2="45.72" y2="20.955" width="0.254" layer="1"/>
<wire x1="51.7525" y1="20.32" x2="51.1175" y2="20.955" width="0.254" layer="1"/>
<wire x1="52.3875" y1="20.32" x2="51.7525" y2="20.32" width="0.254" layer="1"/>
<wire x1="53.0225" y1="20.955" x2="52.3875" y2="20.32" width="0.254" layer="1"/>
<wire x1="59.055" y1="20.955" x2="53.0225" y2="20.955" width="0.254" layer="1"/>
<wire x1="59.69" y1="20.32" x2="59.055" y2="20.955" width="0.254" layer="1"/>
<wire x1="69.215" y1="20.32" x2="59.69" y2="20.32" width="0.254" layer="1"/>
<wire x1="71.4375" y1="22.5425" x2="69.215" y2="20.32" width="0.254" layer="1"/>
<wire x1="87.3125" y1="22.5425" x2="71.4375" y2="22.5425" width="0.254" layer="1"/>
<wire x1="87.3125" y1="56.8325" x2="87.3125" y2="22.5425" width="0.254" layer="16"/>
<wire x1="86.6775" y1="57.4675" x2="87.3125" y2="56.8325" width="0.254" layer="16"/>
<wire x1="86.6775" y1="65.405" x2="86.6775" y2="57.4675" width="0.254" layer="16"/>
<wire x1="87.3125" y1="66.04" x2="86.6775" y2="65.405" width="0.254" layer="16"/>
<wire x1="87.3125" y1="67.945" x2="87.3125" y2="66.04" width="0.254" layer="16"/>
<wire x1="88.265" y1="68.8975" x2="87.3125" y2="67.945" width="0.254" layer="16"/>
<wire x1="91.1225" y1="71.755" x2="88.265" y2="68.8975" width="0.254" layer="1"/>
<wire x1="91.1225" y1="74.93" x2="91.1225" y2="71.755" width="0.254" layer="1"/>
<wire x1="88.5825" y1="74.93" x2="91.1225" y2="74.93" width="0.254" layer="1"/>
<wire x1="88.5825" y1="74.93" x2="88.3158" y2="75.2323" width="0.254" layer="1"/>
<via x="46.355" y="29.5275" extent="1-16" drill="0.6096"/>
<via x="45.72" y="20.955" extent="1-16" drill="0.6096"/>
<via x="87.3125" y="22.5425" extent="1-16" drill="0.6096"/>
<via x="88.265" y="68.8975" extent="1-16" drill="0.6096"/>
</signal>
<signal name="EBIKECONTRL">
<contactref element="X3" pad="10"/>
<contactref element="COMM_DIG" pad="4"/>
<wire x1="35.2425" y1="10.4775" x2="33.02" y2="12.7" width="0.254" layer="1"/>
<wire x1="44.1325" y1="10.4775" x2="35.2425" y2="10.4775" width="0.254" layer="1"/>
<wire x1="44.7675" y1="11.1125" x2="44.1325" y2="10.4775" width="0.254" layer="16"/>
<wire x1="44.7675" y1="20.32" x2="44.7675" y2="11.1125" width="0.254" layer="16"/>
<wire x1="44.45" y1="20.6375" x2="44.7675" y2="20.32" width="0.254" layer="16"/>
<wire x1="44.45" y1="21.59" x2="44.45" y2="20.6375" width="0.254" layer="16"/>
<wire x1="45.085" y1="22.225" x2="44.45" y2="21.59" width="0.254" layer="16"/>
<wire x1="45.085" y1="27.305" x2="45.085" y2="22.225" width="0.254" layer="16"/>
<wire x1="46.0375" y1="28.2575" x2="45.085" y2="27.305" width="0.254" layer="1"/>
<wire x1="47.3075" y1="28.2575" x2="46.0375" y2="28.2575" width="0.254" layer="1"/>
<wire x1="47.625" y1="28.575" x2="47.3075" y2="28.2575" width="0.254" layer="1"/>
<wire x1="61.9125" y1="28.575" x2="47.625" y2="28.575" width="0.254" layer="1"/>
<wire x1="62.5475" y1="27.94" x2="61.9125" y2="28.575" width="0.254" layer="1"/>
<wire x1="69.5325" y1="27.94" x2="62.5475" y2="27.94" width="0.254" layer="1"/>
<wire x1="71.755" y1="30.1625" x2="69.5325" y2="27.94" width="0.254" layer="1"/>
<wire x1="73.025" y1="30.1625" x2="71.755" y2="30.1625" width="0.254" layer="1"/>
<wire x1="72.7075" y1="30.48" x2="73.025" y2="30.1625" width="0.254" layer="16"/>
<wire x1="72.7075" y1="40.3225" x2="72.7075" y2="30.48" width="0.254" layer="16"/>
<wire x1="73.9775" y1="41.5925" x2="72.7075" y2="40.3225" width="0.254" layer="16"/>
<wire x1="79.6925" y1="41.5925" x2="73.9775" y2="41.5925" width="0.254" layer="16"/>
<wire x1="79.6925" y1="58.7375" x2="79.6925" y2="41.5925" width="0.254" layer="16"/>
<wire x1="80.9625" y1="60.0075" x2="79.6925" y2="58.7375" width="0.254" layer="16"/>
<wire x1="86.36" y1="65.405" x2="80.9625" y2="60.0075" width="0.254" layer="1"/>
<wire x1="89.535" y1="65.405" x2="86.36" y2="65.405" width="0.254" layer="1"/>
<wire x1="91.7575" y1="67.6275" x2="89.535" y2="65.405" width="0.254" layer="1"/>
<wire x1="91.7575" y1="76.835" x2="91.7575" y2="67.6275" width="0.254" layer="1"/>
<wire x1="87.3125" y1="76.835" x2="91.7575" y2="76.835" width="0.254" layer="1"/>
<wire x1="85.725" y1="75.2475" x2="87.3125" y2="76.835" width="0.254" layer="1"/>
<wire x1="85.725" y1="75.2475" x2="85.5472" y2="75.2323" width="0.254" layer="1"/>
<via x="44.1325" y="10.4775" extent="1-16" drill="0.6096"/>
<via x="45.085" y="27.305" extent="1-16" drill="0.6096"/>
<via x="73.025" y="30.1625" extent="1-16" drill="0.6096"/>
<via x="80.9625" y="60.0075" extent="1-16" drill="0.6096"/>
</signal>
<signal name="5VOLT">
<contactref element="JP13" pad="2"/>
<contactref element="JP11" pad="1"/>
<wire x1="62.23" y1="17.78" x2="66.04" y2="21.59" width="0.254" layer="16"/>
<wire x1="62.23" y1="6.35" x2="62.23" y2="17.78" width="0.254" layer="16"/>
<wire x1="60.96" y1="5.08" x2="62.23" y2="6.35" width="0.254" layer="16"/>
<wire x1="66.04" y1="21.59" x2="66.294" y2="21.59" width="0.254" layer="16"/>
</signal>
<signal name="N$1">
<contactref element="U$2" pad="P$1"/>
<contactref element="C10" pad="1"/>
<contactref element="R10" pad="1"/>
<wire x1="70.485" y1="19.05" x2="71.4375" y2="18.0975" width="0.254" layer="16"/>
<wire x1="70.485" y1="43.18" x2="70.485" y2="19.05" width="0.254" layer="16"/>
<wire x1="71.755" y1="44.45" x2="70.485" y2="43.18" width="0.254" layer="16"/>
<wire x1="71.755" y1="46.6725" x2="71.755" y2="44.45" width="0.254" layer="16"/>
<wire x1="75.565" y1="50.4825" x2="73.9775" y2="48.895" width="0.254" layer="1"/>
<wire x1="73.9775" y1="48.895" x2="71.755" y2="46.6725" width="0.254" layer="1"/>
<wire x1="75.565" y1="51.7525" x2="75.565" y2="50.4825" width="0.254" layer="1"/>
<wire x1="71.4375" y1="18.0975" x2="71.628" y2="18.034" width="0.254" layer="16"/>
<wire x1="75.565" y1="51.7525" x2="75.438" y2="51.816" width="0.254" layer="1"/>
<wire x1="95.885" y1="48.895" x2="96.8375" y2="47.9425" width="0.254" layer="1"/>
<wire x1="73.9775" y1="48.895" x2="95.885" y2="48.895" width="0.254" layer="1"/>
<wire x1="96.8375" y1="47.9425" x2="96.968" y2="47.824" width="0.254" layer="1"/>
<via x="71.755" y="46.6725" extent="1-16" drill="0.6096"/>
</signal>
</signals>
<mfgpreviewcolors>
<mfgpreviewcolor name="soldermaskcolor" color="0xC8008000"/>
<mfgpreviewcolor name="silkscreencolor" color="0xFFFEFEFE"/>
<mfgpreviewcolor name="backgroundcolor" color="0xFF282828"/>
<mfgpreviewcolor name="coppercolor" color="0xFFFFBF00"/>
<mfgpreviewcolor name="substratecolor" color="0xFF786E46"/>
</mfgpreviewcolors>
</board>
</drawing>
</eagle>


text:
find_program(LUACOV luacov
    HINTS .rocks/
    PATH_SUFFIXES bin
    DOC "Lua test coverage analysis"
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LuaCov
    REQUIRED_VARS LUACOV
)

mark_as_advanced(LUACOV)

repository: tarantool/http

license_type: permissive

repo_name: tarantool/http

branch_name: refs/heads/master

gha_license_id: NOASSERTION

gha_language: Lua

extension: cmake


text:
import defaultConfig, {Config} from '../defaultConfig';

let timer = null;
let previousContent = ""
let config: Config = defaultConfig;

browser.storage.sync.get('config').then(({config: extensionConfig}: { config?: Config }) => {
    config = extensionConfig || defaultConfig;
    updateTimer(config.vnHookClipboardFrequency);
});

browser.storage.onChanged.addListener(({config: {newValue: extensionConfig}}: { config: { newValue: Config } }, areaName) => {
    if (areaName === 'local' || !extensionConfig) return;

    config = extensionConfig || defaultConfig;
    updateTimer(config.vnHookClipboardFrequency);
});

const shouldScroll = (): boolean => {
    if (!config.vnAutoScroll || config.vnHookAppendToTop) return false;

    const rikaiWindow = document.getElementById('rikaichan-window')

    if (rikaiWindow && rikaiWindow.style.display !== "none") return false;

    const LEEWAY = 170; // Amount of "leeway" pixels before latching onto the bottom.

    // Some obscene browser shit because making sense is for dweebs
    const offset = window.innerHeight + window.scrollY;
    const distanceFromBottom = document.body.offsetHeight - offset;

    return distanceFromBottom < LEEWAY;
}

const checkClipboard = () => {
    // @ts-ignore
    navigator.clipboard.readText().then(content => {
        if (content.trim() !== previousContent.trim() && content !== "") {
            addItem(content.trim());
        }
    })
};

const updateTimer = (frequency: number) => {
    const stop = () => {
        clearInterval(timer.id)
        timer = null
    };

    const start = () => {
        const id = setInterval(checkClipboard, frequency)
        timer = {id, interval: frequency}
    };

    if (timer === null) {
        start()
    } else if (timer.interval !== frequency) {
        stop()
        start()
    }
};

const addItem = (text: string) => {
    const checkShouldScroll = shouldScroll();

    previousContent = text.trim();
    const vnContent = document.getElementById('vn-content');

    const newItem = document.createElement('div');
    newItem.innerText = text;

    if (config.vnHookAppendToTop) {
        vnContent.prepend(newItem);
    } else {
        vnContent.appendChild(newItem);
    }

    if (checkShouldScroll) {
        window.scrollTo(0, document.body.scrollHeight);
    }
}

export default () => {
    updateTimer(defaultConfig.vnHookClipboardFrequency);

    $("#clear-page").on('click', () => {
        document.getElementById('vn-content').innerHTML = '';
    })
}

license: MIT

repository: Garethp/RikaiRebuilt

repo_name: Garethp/RikaiRebuilt

extension: ts


text:
DESCRIPTION = "XMODEM protocol implementation"

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI[sha256sum] = "089737298f5738eabc43f2519efdc80b402693768f16383f7013b9e6f8f279d7"

inherit pypi setuptools3

RDEPENDS_${PN} += " \
    ${PYTHON_PN}-logging \
"

BBCLASSEXTEND = "native nativesdk"

repository: ni/meta-openembedded

repo_name: ni/meta-openembedded

branch_name: refs/heads/nilrt/master/hardknott

gha_license_id: MIT

gha_language: BitBake

extension: bb


text:
package transactionpool

import (
	"testing"
)

// testTransactionDumping calls TransactionSet and puts the transactions in a
// block that gets submitted to the state. If there is an error, the
// transaction set is known to be invalid.
func (tpt *tpoolTester) testSiacoinTransactionDump() {
	tlen := len(tpt.tpool.TransactionSet())

	tpt.addDependentSiacoinTransactionToPool()
	if tlen >= len(tpt.tpool.TransactionSet()) {
		tpt.t.Error("wrong number of transactions in transaction dump, expecting mor than", tlen, "got", len(tpt.tpool.TransactionSet()))
	}

	// Add the transaction set to a block and check that it is valid in the
	// state by adding it to the state.
	b, _ := tpt.miner.FindBlock()
	err := tpt.cs.AcceptBlock(b)
	if err != nil {
		tpt.t.Error(err)
	}
	tpt.csUpdateWait()
	if len(tpt.tpool.TransactionSet()) != 0 {
		tpt.t.Error("Transaction set should be empty after mining a block, instead is size", len(tpt.tpool.TransactionSet()))
	}
}

// TestSiacoinTransactionDump creates a tpoolTester and uses it to call
// testSiacoinTransactionDump.
func TestSiacoinTransactionDump(t *testing.T) {
	tpt := newTpoolTester("TestSiacoinTransactionDump", t)
	tpt.testSiacoinTransactionDump()
}

repository: jefdiesel/Sia

repo_name: jefdiesel/Sia

extension: go


text:
/*
 * Copyright (c) 2017 AlexRuzin (stan.ruzin@gmail.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/* Commit test */

package websock

import (
    "fmt"
    "sync"
    "bytes"
    "strings"
    "io"
    "time"
    "net/http"
    "crypto/elliptic"
    "crypto/rand"
    "crypto/md5"
    "encoding/hex"

    "github.com/AlexRuzin/util"
    "github.com/wsddn/go-ecdh"
)

/************************************************************
 * websock Server objects and methods                       *
 ************************************************************/
type NetChannelService struct {
    /* Handler for new clients */
    IncomingHandler         func(client *NetInstance, server *NetChannelService) error

    /* Flags may be modified at any time */
    Flags                   FlagVal

    /* Non-exported members */
    port                    int16
    pathGate                string
    clientMap               map[string]*NetInstance

    config                  *ProtocolConfig
}

/*
 * Global object representing the service instance
 */
var channelService          *NetChannelService

/*
 * Channel for inbound clients
 */
var clientIO                chan *NetInstance

type NetInstance struct {
    /* Unique identifier that represents the client connection */
    ClientIdString          string

    /* Non-exported members */
    service                 *NetChannelService
    secret                  []byte
    clientId                []byte
    clientTX                *bytes.Buffer       /* Data waiting to be transmitted */
    clientRX                *rxElement          /* Data that is waiting to be read, using a custom FIFO queue */
    iOSync                  sync.Mutex

    connected               bool

    /* URI Path */
    RequestURI              string
}

func CreateServer(pathGate string, port int16, flags FlagVal, handler func(client *NetInstance,
    server *NetChannelService) error) (*NetChannelService, error) {

    /* The FLAG_ENCRYPT switch must always be set to true */
    if (flags & FLAG_ENCRYPT) == 0 {
        return nil, util.RetErrStr("FLAG_ENCRYPT must be set")
    }

    var (
        tmpConfig   *ProtocolConfig
        err         error
    )
    tmpConfig, err = parseConfig()
    if err != nil {
        return nil, err
    }

    if testCharSetPKE(tmpConfig.PostBodyKeyCharset) == false {
        return nil, util.RetErrStr("PANIC: POST_BODY_KEY_CHARSET contains non-unique elements")
    }

    var server = &NetChannelService{
        IncomingHandler:    handler,
        port:               port,
        Flags:              flags,
        pathGate:           pathGate,

        /* Map consists of key: ClientId (string) and value: *NetInstance object */
        clientMap:          make(map[string]*NetInstance),

        /* Set the main config */
        config:             tmpConfig,
    }
    channelService = server

    /* Start the inbound/outbound listener threads */
    util.Sleep(100 * time.Millisecond)
    server.startListeners()

    return server, nil
}

func (f *NetChannelService) closeClient(client *NetInstance) {
    delete(f.clientMap, client.ClientIdString)
}

func (f *NetChannelService) CloseService() {
    panic("Closing primary service for handling websock protocol")
    if clientIO != nil {
        close(clientIO)
    }
}

func (f *NetInstance) Close() {
    f.service.closeClient(f)
}

/*
 * Retrieves length of the buffer at index 0
 */
func (f *NetInstance) Len() int {
    return f.queueLen()
}

func (f *NetInstance) Wait(timeoutMilliseconds time.Duration) (responseLen int, err error) {
    return f.waitInternal(timeoutMilliseconds)
}

func (f *NetInstance) Read(p []byte) (read int, err error) {
    read, err = f.readInternal(p)
    if err != io.EOF {
        return 0, err
    }

    return
}

func (f *NetInstance) Write(p []byte) (wrote int, err error) {
    wrote, err = f.writeInternal(p)
    if err != io.EOF {
        return 0, err
    }

    return
}

func (f *NetChannelService) startListeners() {
    /* Create the clientIO channel */
    clientIO = make(chan *NetInstance)
    go func (svc *NetChannelService) {
        var wg sync.WaitGroup
        wg.Add(1)
        for {
            client, ok := <- clientIO
            if !ok {
                break /* Close the processor */
            }

            svc.clientMap[client.ClientIdString] = client
            if err := svc.IncomingHandler(client, svc); err != nil {
                svc.closeClient(client)
            }

            client.connected = true
        }

        panic(util.RetErrStr("inbound client channel has been terminated"))
    } (f)

    go func(svc *NetChannelService) {
        http.HandleFunc(svc.pathGate, handleClientRequest)
        svc.sendDebug("Handling request for path :" + svc.pathGate)
        if err := http.ListenAndServe(":" + util.IntToString(int(f.port)),nil); err != nil {
            panic("panic: Failure in loading httpd -- port already used for another service?")
        }
    } (f)
}

/* Create circuit -OR- process gate requests */
func handleClientRequest(writer http.ResponseWriter, reader *http.Request) {
    defer reader.Body.Close()

    /* Contains the marshalled Public Key after the initial decoding */
    var (
        marshalledPublicClientKey       *string
        keyStatus                       error
    )
    if marshalledPublicClientKey, keyStatus = decodePublicKeyParameters(reader); keyStatus != nil {
        util.RetErrStr(keyStatus.Error())
    }

    if marshalledPublicClientKey == nil {
        /*
         * Parameter for key negotiation does not exist. This implies that either someone is not using
         *  the server in the designed fashion, or that there is another command request coming from
         *  and existing client. Here we verify if the client exists.
         *
         * If it's a command, then there should be only one parameter, which is:
         *  b64(ClientIdString) = <command>
         */
         parseExistingClient(reader, &writer)

         return /* The appropriate ClientData has been stored, so no more need for this method */
    }

    /*
     * Create a new client
     */
    if err := handleNewClient(*marshalledPublicClientKey, reader, &writer); err != nil {
        util.DebugOut(err.Error())
    }

    return
}

func handleNewClient(marshalledKey string, reader *http.Request, writer *http.ResponseWriter) error {
    /* Parse client-side public ECDH key*/
    marshalled, err := getClientPublicKey(marshalledKey)
    if err != nil || marshalled == nil {
        sendBadErrorCode(*writer, err)
        util.DebugOut(err.Error())
        return err
    }

    ecurve := ecdh.NewEllipticECDH(elliptic.P384())
    clientPublicKey, ok := ecurve.Unmarshal(marshalled)
    if !ok {
        sendBadErrorCode(*writer, util.RetErrStr("unmarshalling failed"))
        return util.RetErrStr("Failed to unmarshal the ecurve Public Key")
    }

    /*
     * Since the client public key is nominal return generate
     *  our own keypair
     */
    serverPrivateKey, serverPublicKey, err := ecurve.GenerateKey(rand.Reader)
    if err != nil {
        sendBadErrorCode(*writer, err)
        return err
    }

    /* Transmit the server public key */
    var serverPubKeyMarshalled = ecurve.Marshal(serverPublicKey)
    if serverPubKeyMarshalled == nil {
        sendBadErrorCode(*writer, util.RetErrStr("Failed to marshal server-side pub key"))
        return err
    }
    clientId := md5.Sum(marshalled)
    if err := sendPubKey(*writer, serverPubKeyMarshalled, clientId[:]); err != nil {
        sendBadErrorCode(*writer, err)
        return err
    }

    /* Generate the secret */
    secret, err := ecurve.GenerateSharedSecret(serverPrivateKey, clientPublicKey)
    if len(secret) == 0 {
        sendBadErrorCode(*writer, util.RetErrStr("Failed to generate a shared secret key"))
        return err
    }

    if (channelService.Flags & FLAG_DEBUG) > 1 {
        util.DebugOut("Server-side secret:")
        util.DebugOutHex(secret)
    }

    var instance = &NetInstance{
        service:            channelService,
        secret:             secret,
        clientId:           clientId[:],
        ClientIdString:     hex.EncodeToString(clientId[:]),
        clientRX:           nil,
        clientTX:           &bytes.Buffer{},
        connected:          false,
        RequestURI:         reader.RequestURI,
    }

    /* Send the signal to startListeners() */
    clientIO <- instance

    return nil
}

func parseExistingClient(reader *http.Request, writer *http.ResponseWriter) {
    /*
     * Parameter for key negotiation does not exist. This implies that either someone is not using
     *  the server in the designed fashion, or that there is another command request coming from
     *  and existing client. Here we verify if the client exists.
     *
     * If it's a command, then there should be only one parameter, which is:
     *  b64(ClientIdString) = <command>
     */
    key := reader.Form
    if key == nil {
        return
    }

    for k := range key {
        var err error = nil
        var decodedKey []byte
        if decodedKey, err = util.B64D(k); err != nil {
            continue
        }
        client := channelService.clientMap[string(decodedKey)]
        if client != nil {
            /*
             * An active connection exists.
             *
             * Base64 decode the signal and return the RC4 encrypted buffer to
             *  be processed
             *
             * Write data to NetInstance.ClientData
             */
            value := key[k]
            var (
                clientId       string
                data           []byte = nil
                txUnit         *transferUnit = nil
            )
            if clientId, data, txUnit, err = decryptData(value[0], client.secret);
                err != nil || strings.Compare(clientId, client.ClientIdString) != 0 {
                channelService.closeClient(client)
                return
            }

            if (channelService.Flags & FLAG_COMPRESS) > 0 && (txUnit.Flags & FLAG_COMPRESS) > 0 {
                var streamStatus error = nil
                data, streamStatus = util.DecompressStream(data)
                if streamStatus != nil {
                    channelService.closeClient(client)
                    return
                }
            }

            if err := client.parseClientData(data, *writer); err != nil {
                channelService.closeClient(client)
            }

            return /* The appropriate ClientData has been stored, so no more need for this method */
        }
    }
}

func decodePublicKeyParameters(reader *http.Request) (clientKey *string, err error) {
    /* Get remote client public key base64 marshalled string */
    clientKey = nil
    if err := reader.ParseForm(); err != nil {
        util.DebugOut(err.Error())
        return clientKey, err
    }

    for key := range reader.Form {
        for i := len(channelService.config.PostBodyKeyCharset); i != 0; i -= 1 {
            var tmpKey = string(channelService.config.PostBodyKeyCharset[i - 1])

            decodedKey, err := util.B64D(key)
            if err != nil {
                return nil, err
            }

            if strings.Compare(tmpKey, string(decodedKey)) == 0 {
                clientKey = &reader.Form[key][0]
                break
            }
        }
        if clientKey != nil {
            break
        }
    }
    return clientKey, nil
}

func (f *NetInstance) cmdWaitAndTransmitData(writer http.ResponseWriter) error {
    var timeout = f.service.config.C2ResponseTimeout
    for ; timeout != 0; timeout -= 1 {
        if f.clientTX.Len() != 0 {
            break
        }
        util.Sleep(1 * time.Second)
    }

    if timeout == 0 || f.clientTX.Len() == 0 {
        /* Time out -- no data to be sent */
        writer.WriteHeader(http.StatusOK)
        return nil
    }

    defer f.clientTX.Reset()

    var (
        outputStream = f.clientTX.Bytes()
        otherFlags FlagVal = 0
    )

    if (f.service.Flags & FLAG_COMPRESS) > 0 && len(outputStream) > util.GetCompressedSize(outputStream) {
        otherFlags |= FLAG_COMPRESS
        var streamStatus error = nil
        outputStream, streamStatus = util.CompressStream(outputStream)
        if streamStatus != nil {
            panic(streamStatus)
        }
    }

    encrypted, _ := encryptData(outputStream, f.secret, FLAG_DIRECTION_TO_CLIENT, otherFlags, f.ClientIdString)
    return sendResponse(writer, encrypted)
}

func (f *NetInstance) parseClientData(rawData []byte, writer http.ResponseWriter) error {
    /*
     * Check for internal commands first
     */
    if util.IsAsciiPrintable(string(rawData)) {
        var command = string(rawData)

        switch command {
        case f.service.config.CheckStream: // FLAG_CHECK_STREAM_DATA
            return f.cmdWaitAndTransmitData(writer)

        case f.service.config.TestStream: // FLAG_TEST_CONNECTION
            encrypted, _ := encryptData(rawData, f.secret, FLAG_DIRECTION_TO_CLIENT, 0, f.ClientIdString)
            return sendResponse(writer, encrypted)

        case f.service.config.TermConnect: // FLAG_TERMINATE_CONNECTION
            /* FIXME */
            return ERROR_TERMINATE
        }
    }

    /* Decompression, if required, has already taken place in handleClientRequest() by parsing the TransmissionUnit flags */
    f.enqueue(rawData)

    /* If there is any data to return, then send it over */
    var otherFlags FlagVal = 0
    if f.clientTX.Len() > 0 {
        defer f.clientTX.Reset()

        var outputStream []byte = f.clientTX.Bytes()

        if (f.service.Flags & FLAG_COMPRESS) > 0 && len(outputStream) > util.GetCompressedSize(outputStream) {
            otherFlags |= FLAG_COMPRESS

            var streamStatus error = nil
            outputStream, streamStatus = util.CompressStream(outputStream)
            if streamStatus != nil {
                panic(streamStatus)
            }
        }

        encrypted, _ := encryptData(outputStream, f.secret, FLAG_DIRECTION_TO_CLIENT, otherFlags, f.ClientIdString)
        return sendResponse(writer, encrypted)
    }
    writer.WriteHeader(http.StatusOK)

    return nil
}

func (f *NetInstance) waitInternal(timeoutMilliseconds time.Duration) (responseLen int, err error) {
    if f.connected == false {
        return 0, util.RetErrStr("client not connected")
    }

    responseLen = 0
    err = WAIT_TIMEOUT_REACHED

    for i := timeoutMilliseconds / 100; i != 0; i -= 1 {
        if f.connected == false {
            responseLen = -1
            err = WAIT_CLOSED
            break
        }

        responseLen = f.Len()
        if responseLen > 0 {
            err = WAIT_DATA_RECEIVED
            break
        }

        util.Sleep(100 * time.Millisecond)
    }

    return
}

func (f *NetInstance) readInternal(p []byte) (int, error) {
    if f.connected == false {
        return 0, util.RetErrStr("client not connected")
    }

    f.iOSync.Lock()
    defer f.iOSync.Unlock()

    rawData, _ := f.dequeue()
    if len(rawData) == 0 {
        return 0, nil
    }

    copy(p, rawData)
    return len(rawData), io.EOF
}

func (f *NetInstance) writeInternal(p []byte) (int, error) {
    if f.connected == false {
        return 0, util.RetErrStr("client not connected")
    }

    f.iOSync.Lock()
    defer f.iOSync.Unlock()

    f.clientTX.Write(p)

    return len(p), io.EOF
}

/*
 * Queue subsystem for the input elements
 */
type rxElement struct {
    data            *bytes.Buffer

    next            *rxElement
    last            *rxElement
}
var rxQueueSync     sync.Mutex

func (f *NetInstance) enqueue(p []byte) {
    rxQueueSync.Lock()
    defer rxQueueSync.Unlock()

    if f.clientRX == nil {
        f.clientRX = &rxElement{
            data:   bytes.NewBuffer(p),
            next:   nil,
            last:   nil,
        }

        return
    }

    f.clientRX.last = &rxElement{
            data:   bytes.NewBuffer(p),
            next:   f.clientRX,
            last:   nil,
    }

    f.clientRX = f.clientRX.last
}

func (f *NetInstance) dequeue() ([]byte, error) {
    rxQueueSync.Lock()
    defer rxQueueSync.Unlock()

    if f.clientRX == nil {
        return nil, nil
    }

    if f.clientRX.next == nil {
        out := f.clientRX.data.Bytes()
        f.clientRX = nil
        return out, nil
    }

    endElement := f.clientRX
    for ;endElement.next != nil; endElement = endElement.next {}
    var out = endElement.data.Bytes()
    t := endElement.last
    t.next = nil

    return out, nil
}

func (f *NetInstance) queueLen() int {
    rxQueueSync.Lock()
    defer rxQueueSync.Unlock()

    if f.clientRX == nil {
        return 0
    }

    q := f.clientRX
    total := 0
    for q != nil {
        total += q.data.Len()
        q = q.next
    }

    return total
}

/* HTTP 500 - Internal Server Error */
func sendBadErrorCode(writer http.ResponseWriter, err error) {
    writer.WriteHeader(http.StatusInternalServerError)
    writer.Write([]byte("500 - " + err.Error()))
    return
}

func sendResponse(writer http.ResponseWriter, data []byte) error {
    if len(data) == 0 {
        return util.RetErrStr("sendResponse: Invalid parameter")
    }

    var b64Encoded = util.B64E(data)

    writer.Header().Set("Content-Type", channelService.config.ContentType)
    writer.Header().Set("Connection", "close")
    writer.WriteHeader(http.StatusOK)

    fmt.Fprintln(writer, b64Encoded)

    return nil
}

/* EOF */

repository: firebitsbr/websock

repo_name: firebitsbr/websock


text:
package pulse

/*
DO NOT EDIT!
This code was generated automatically using github.com/gojuno/minimock v1.9
The original interface "Calculator" can be found in github.com/insolar/insolar/insolar/pulse
*/
import (
	context "context"
	"sync/atomic"
	"time"

	"github.com/gojuno/minimock"
	insolar "github.com/insolar/insolar/insolar"

	testify_assert "github.com/stretchr/testify/assert"
)

//CalculatorMock implements github.com/insolar/insolar/insolar/pulse.Calculator
type CalculatorMock struct {
	t minimock.Tester

	BackwardsFunc       func(p context.Context, p1 insolar.PulseNumber, p2 int) (r insolar.Pulse, r1 error)
	BackwardsCounter    uint64
	BackwardsPreCounter uint64
	BackwardsMock       mCalculatorMockBackwards

	ForwardsFunc       func(p context.Context, p1 insolar.PulseNumber, p2 int) (r insolar.Pulse, r1 error)
	ForwardsCounter    uint64
	ForwardsPreCounter uint64
	ForwardsMock       mCalculatorMockForwards
}

//NewCalculatorMock returns a mock for github.com/insolar/insolar/insolar/pulse.Calculator
func NewCalculatorMock(t minimock.Tester) *CalculatorMock {
	m := &CalculatorMock{t: t}

	if controller, ok := t.(minimock.MockController); ok {
		controller.RegisterMocker(m)
	}

	m.BackwardsMock = mCalculatorMockBackwards{mock: m}
	m.ForwardsMock = mCalculatorMockForwards{mock: m}

	return m
}

type mCalculatorMockBackwards struct {
	mock              *CalculatorMock
	mainExpectation   *CalculatorMockBackwardsExpectation
	expectationSeries []*CalculatorMockBackwardsExpectation
}

type CalculatorMockBackwardsExpectation struct {
	input  *CalculatorMockBackwardsInput
	result *CalculatorMockBackwardsResult
}

type CalculatorMockBackwardsInput struct {
	p  context.Context
	p1 insolar.PulseNumber
	p2 int
}

type CalculatorMockBackwardsResult struct {
	r  insolar.Pulse
	r1 error
}

//Expect specifies that invocation of Calculator.Backwards is expected from 1 to Infinity times
func (m *mCalculatorMockBackwards) Expect(p context.Context, p1 insolar.PulseNumber, p2 int) *mCalculatorMockBackwards {
	m.mock.BackwardsFunc = nil
	m.expectationSeries = nil

	if m.mainExpectation == nil {
		m.mainExpectation = &CalculatorMockBackwardsExpectation{}
	}
	m.mainExpectation.input = &CalculatorMockBackwardsInput{p, p1, p2}
	return m
}

//Return specifies results of invocation of Calculator.Backwards
func (m *mCalculatorMockBackwards) Return(r insolar.Pulse, r1 error) *CalculatorMock {
	m.mock.BackwardsFunc = nil
	m.expectationSeries = nil

	if m.mainExpectation == nil {
		m.mainExpectation = &CalculatorMockBackwardsExpectation{}
	}
	m.mainExpectation.result = &CalculatorMockBackwardsResult{r, r1}
	return m.mock
}

//ExpectOnce specifies that invocation of Calculator.Backwards is expected once
func (m *mCalculatorMockBackwards) ExpectOnce(p context.Context, p1 insolar.PulseNumber, p2 int) *CalculatorMockBackwardsExpectation {
	m.mock.BackwardsFunc = nil
	m.mainExpectation = nil

	expectation := &CalculatorMockBackwardsExpectation{}
	expectation.input = &CalculatorMockBackwardsInput{p, p1, p2}
	m.expectationSeries = append(m.expectationSeries, expectation)
	return expectation
}

func (e *CalculatorMockBackwardsExpectation) Return(r insolar.Pulse, r1 error) {
	e.result = &CalculatorMockBackwardsResult{r, r1}
}

//Set uses given function f as a mock of Calculator.Backwards method
func (m *mCalculatorMockBackwards) Set(f func(p context.Context, p1 insolar.PulseNumber, p2 int) (r insolar.Pulse, r1 error)) *CalculatorMock {
	m.mainExpectation = nil
	m.expectationSeries = nil

	m.mock.BackwardsFunc = f
	return m.mock
}

//Backwards implements github.com/insolar/insolar/insolar/pulse.Calculator interface
func (m *CalculatorMock) Backwards(p context.Context, p1 insolar.PulseNumber, p2 int) (r insolar.Pulse, r1 error) {
	counter := atomic.AddUint64(&m.BackwardsPreCounter, 1)
	defer atomic.AddUint64(&m.BackwardsCounter, 1)

	if len(m.BackwardsMock.expectationSeries) > 0 {
		if counter > uint64(len(m.BackwardsMock.expectationSeries)) {
			m.t.Fatalf("Unexpected call to CalculatorMock.Backwards. %v %v %v", p, p1, p2)
			return
		}

		input := m.BackwardsMock.expectationSeries[counter-1].input
		testify_assert.Equal(m.t, *input, CalculatorMockBackwardsInput{p, p1, p2}, "Calculator.Backwards got unexpected parameters")

		result := m.BackwardsMock.expectationSeries[counter-1].result
		if result == nil {
			m.t.Fatal("No results are set for the CalculatorMock.Backwards")
			return
		}

		r = result.r
		r1 = result.r1

		return
	}

	if m.BackwardsMock.mainExpectation != nil {

		input := m.BackwardsMock.mainExpectation.input
		if input != nil {
			testify_assert.Equal(m.t, *input, CalculatorMockBackwardsInput{p, p1, p2}, "Calculator.Backwards got unexpected parameters")
		}

		result := m.BackwardsMock.mainExpectation.result
		if result == nil {
			m.t.Fatal("No results are set for the CalculatorMock.Backwards")
		}

		r = result.r
		r1 = result.r1

		return
	}

	if m.BackwardsFunc == nil {
		m.t.Fatalf("Unexpected call to CalculatorMock.Backwards. %v %v %v", p, p1, p2)
		return
	}

	return m.BackwardsFunc(p, p1, p2)
}

//BackwardsMinimockCounter returns a count of CalculatorMock.BackwardsFunc invocations
func (m *CalculatorMock) BackwardsMinimockCounter() uint64 {
	return atomic.LoadUint64(&m.BackwardsCounter)
}

//BackwardsMinimockPreCounter returns the value of CalculatorMock.Backwards invocations
func (m *CalculatorMock) BackwardsMinimockPreCounter() uint64 {
	return atomic.LoadUint64(&m.BackwardsPreCounter)
}

//BackwardsFinished returns true if mock invocations count is ok
func (m *CalculatorMock) BackwardsFinished() bool {
	// if expectation series were set then invocations count should be equal to expectations count
	if len(m.BackwardsMock.expectationSeries) > 0 {
		return atomic.LoadUint64(&m.BackwardsCounter) == uint64(len(m.BackwardsMock.expectationSeries))
	}

	// if main expectation was set then invocations count should be greater than zero
	if m.BackwardsMock.mainExpectation != nil {
		return atomic.LoadUint64(&m.BackwardsCounter) > 0
	}

	// if func was set then invocations count should be greater than zero
	if m.BackwardsFunc != nil {
		return atomic.LoadUint64(&m.BackwardsCounter) > 0
	}

	return true
}

type mCalculatorMockForwards struct {
	mock              *CalculatorMock
	mainExpectation   *CalculatorMockForwardsExpectation
	expectationSeries []*CalculatorMockForwardsExpectation
}

type CalculatorMockForwardsExpectation struct {
	input  *CalculatorMockForwardsInput
	result *CalculatorMockForwardsResult
}

type CalculatorMockForwardsInput struct {
	p  context.Context
	p1 insolar.PulseNumber
	p2 int
}

type CalculatorMockForwardsResult struct {
	r  insolar.Pulse
	r1 error
}

//Expect specifies that invocation of Calculator.Forwards is expected from 1 to Infinity times
func (m *mCalculatorMockForwards) Expect(p context.Context, p1 insolar.PulseNumber, p2 int) *mCalculatorMockForwards {
	m.mock.ForwardsFunc = nil
	m.expectationSeries = nil

	if m.mainExpectation == nil {
		m.mainExpectation = &CalculatorMockForwardsExpectation{}
	}
	m.mainExpectation.input = &CalculatorMockForwardsInput{p, p1, p2}
	return m
}

//Return specifies results of invocation of Calculator.Forwards
func (m *mCalculatorMockForwards) Return(r insolar.Pulse, r1 error) *CalculatorMock {
	m.mock.ForwardsFunc = nil
	m.expectationSeries = nil

	if m.mainExpectation == nil {
		m.mainExpectation = &CalculatorMockForwardsExpectation{}
	}
	m.mainExpectation.result = &CalculatorMockForwardsResult{r, r1}
	return m.mock
}

//ExpectOnce specifies that invocation of Calculator.Forwards is expected once
func (m *mCalculatorMockForwards) ExpectOnce(p context.Context, p1 insolar.PulseNumber, p2 int) *CalculatorMockForwardsExpectation {
	m.mock.ForwardsFunc = nil
	m.mainExpectation = nil

	expectation := &CalculatorMockForwardsExpectation{}
	expectation.input = &CalculatorMockForwardsInput{p, p1, p2}
	m.expectationSeries = append(m.expectationSeries, expectation)
	return expectation
}

func (e *CalculatorMockForwardsExpectation) Return(r insolar.Pulse, r1 error) {
	e.result = &CalculatorMockForwardsResult{r, r1}
}

//Set uses given function f as a mock of Calculator.Forwards method
func (m *mCalculatorMockForwards) Set(f func(p context.Context, p1 insolar.PulseNumber, p2 int) (r insolar.Pulse, r1 error)) *CalculatorMock {
	m.mainExpectation = nil
	m.expectationSeries = nil

	m.mock.ForwardsFunc = f
	return m.mock
}

//Forwards implements github.com/insolar/insolar/insolar/pulse.Calculator interface
func (m *CalculatorMock) Forwards(p context.Context, p1 insolar.PulseNumber, p2 int) (r insolar.Pulse, r1 error) {
	counter := atomic.AddUint64(&m.ForwardsPreCounter, 1)
	defer atomic.AddUint64(&m.ForwardsCounter, 1)

	if len(m.ForwardsMock.expectationSeries) > 0 {
		if counter > uint64(len(m.ForwardsMock.expectationSeries)) {
			m.t.Fatalf("Unexpected call to CalculatorMock.Forwards. %v %v %v", p, p1, p2)
			return
		}

		input := m.ForwardsMock.expectationSeries[counter-1].input
		testify_assert.Equal(m.t, *input, CalculatorMockForwardsInput{p, p1, p2}, "Calculator.Forwards got unexpected parameters")

		result := m.ForwardsMock.expectationSeries[counter-1].result
		if result == nil {
			m.t.Fatal("No results are set for the CalculatorMock.Forwards")
			return
		}

		r = result.r
		r1 = result.r1

		return
	}

	if m.ForwardsMock.mainExpectation != nil {

		input := m.ForwardsMock.mainExpectation.input
		if input != nil {
			testify_assert.Equal(m.t, *input, CalculatorMockForwardsInput{p, p1, p2}, "Calculator.Forwards got unexpected parameters")
		}

		result := m.ForwardsMock.mainExpectation.result
		if result == nil {
			m.t.Fatal("No results are set for the CalculatorMock.Forwards")
		}

		r = result.r
		r1 = result.r1

		return
	}

	if m.ForwardsFunc == nil {
		m.t.Fatalf("Unexpected call to CalculatorMock.Forwards. %v %v %v", p, p1, p2)
		return
	}

	return m.ForwardsFunc(p, p1, p2)
}

//ForwardsMinimockCounter returns a count of CalculatorMock.ForwardsFunc invocations
func (m *CalculatorMock) ForwardsMinimockCounter() uint64 {
	return atomic.LoadUint64(&m.ForwardsCounter)
}

//ForwardsMinimockPreCounter returns the value of CalculatorMock.Forwards invocations
func (m *CalculatorMock) ForwardsMinimockPreCounter() uint64 {
	return atomic.LoadUint64(&m.ForwardsPreCounter)
}

//ForwardsFinished returns true if mock invocations count is ok
func (m *CalculatorMock) ForwardsFinished() bool {
	// if expectation series were set then invocations count should be equal to expectations count
	if len(m.ForwardsMock.expectationSeries) > 0 {
		return atomic.LoadUint64(&m.ForwardsCounter) == uint64(len(m.ForwardsMock.expectationSeries))
	}

	// if main expectation was set then invocations count should be greater than zero
	if m.ForwardsMock.mainExpectation != nil {
		return atomic.LoadUint64(&m.ForwardsCounter) > 0
	}

	// if func was set then invocations count should be greater than zero
	if m.ForwardsFunc != nil {
		return atomic.LoadUint64(&m.ForwardsCounter) > 0
	}

	return true
}

//ValidateCallCounters checks that all mocked methods of the interface have been called at least once
//Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller
func (m *CalculatorMock) ValidateCallCounters() {

	if !m.BackwardsFinished() {
		m.t.Fatal("Expected call to CalculatorMock.Backwards")
	}

	if !m.ForwardsFinished() {
		m.t.Fatal("Expected call to CalculatorMock.Forwards")
	}

}

//CheckMocksCalled checks that all mocked methods of the interface have been called at least once
//Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller
func (m *CalculatorMock) CheckMocksCalled() {
	m.Finish()
}

//Finish checks that all mocked methods of the interface have been called at least once
//Deprecated: please use MinimockFinish or use Finish method of minimock.Controller
func (m *CalculatorMock) Finish() {
	m.MinimockFinish()
}

//MinimockFinish checks that all mocked methods of the interface have been called at least once
func (m *CalculatorMock) MinimockFinish() {

	if !m.BackwardsFinished() {
		m.t.Fatal("Expected call to CalculatorMock.Backwards")
	}

	if !m.ForwardsFinished() {
		m.t.Fatal("Expected call to CalculatorMock.Forwards")
	}

}

//Wait waits for all mocked methods to be called at least once
//Deprecated: please use MinimockWait or use Wait method of minimock.Controller
func (m *CalculatorMock) Wait(timeout time.Duration) {
	m.MinimockWait(timeout)
}

//MinimockWait waits for all mocked methods to be called at least once
//this method is called by minimock.Controller
func (m *CalculatorMock) MinimockWait(timeout time.Duration) {
	timeoutCh := time.After(timeout)
	for {
		ok := true
		ok = ok && m.BackwardsFinished()
		ok = ok && m.ForwardsFinished()

		if ok {
			return
		}

		select {
		case <-timeoutCh:

			if !m.BackwardsFinished() {
				m.t.Error("Expected call to CalculatorMock.Backwards")
			}

			if !m.ForwardsFinished() {
				m.t.Error("Expected call to CalculatorMock.Forwards")
			}

			m.t.Fatalf("Some mocks were not called on time: %s", timeout)
			return
		default:
			time.Sleep(time.Millisecond)
		}
	}
}

//AllMocksCalled returns true if all mocked methods were called before the execution of AllMocksCalled,
//it can be used with assert/require, i.e. assert.True(mock.AllMocksCalled())
func (m *CalculatorMock) AllMocksCalled() bool {

	if !m.BackwardsFinished() {
		return false
	}

	if !m.ForwardsFinished() {
		return false
	}

	return true
}