Ejemplo n.º 1
0
def run_avr_elf(elf_file, mcu = 'atmega2560', f_cpu = 16000000):
      print "Running simulation with ... " + elf_file

      simulation = ArduinoSim(external_elf=elf_file,
                        mcu = mcu,
                        f_cpu=f_cpu,
                        timespan=7,
                        fps=20,
                        )
      output = simulation.get_serial()
      print output
Ejemplo n.º 2
0
def test_udp():
    snippet = '''
    for(int i=0;i<100;i++)
    {
        Serial.print(i);
        Serial.println(":abcdefgh");
        //delay(100);
    }
    '''
    x = ArduinoSim(snippet=snippet, timespan=10).get_serial()
    print x
    lines = x.splitlines()
    eq_(len(lines), 100)
    for i, l in zip(xrange(100), lines):
        eq_(l, str(i) + ":abcdefgh")
Ejemplo n.º 3
0
def run_sim(vcdfile='delay.vcd'):
    snippet = '''
        Serial.println("start");
        pinMode(0, OUTPUT);
        digitalWrite(0, HIGH);
        delay(100);
        digitalWrite(0, LOW);
        delay(100);
        digitalWrite(0, HIGH);
        delay(100);
        digitalWrite(0, LOW);
        delay(100);
        Serial.println("end");
    '''
    sim = ArduinoSim(snippet=snippet, vcd=vcdfile, timespan=0.5)
    sim.run()
Ejemplo n.º 4
0
def check_fcpu(f):
    snippet = '''Serial.print(F_CPU);'''
    s = ArduinoSim(
        snippet=snippet,
        f_cpu=f,
        timespan=1).get_serial()
    eq_(int(s), f)
Ejemplo n.º 5
0
def test():
    snippet='''
        Serial.println("start");
        pinMode(0, OUTPUT);     
        digitalWrite(0, HIGH);   
        delay(100);           
        digitalWrite(0, LOW);   
        delay(100);              
        digitalWrite(0, HIGH);   
        delay(100);           
        digitalWrite(0, LOW);   
        delay(100);             
        Serial.println("end");
    '''
    vcdfile= tempfile.mkdtemp() + '/vcdtest.vcd'
    sim=ArduinoSim(snippet=snippet, vcd=vcdfile, timespan=0.5)
    sim.run()
Ejemplo n.º 6
0
def generate_vcd(song, vcd, mcu='atmega168', f_cpu=16000000, timespan=2, logger=lambda x: None):
    code = TEMPLATE_PLAY.replace('$SONG$', song)
    vcd = path(vcd)
    d = vcd.dirname()
    fcode = d / ('generated_code4_' + vcd.name + '.c')
    fcode.write_text(code)
    logger('writing ' + fcode)

    x = ArduinoSim(code=code,
                   mcu=mcu,
                   f_cpu=f_cpu,
                   vcd=vcd,
                   #                      extra_lib=root,
                   #                      template=TEMPLATE,
                   timespan=timespan,
                   )
    x.run()
Ejemplo n.º 7
0
def test():
    snippet = '''
        Serial.println("start");
        pinMode(0, OUTPUT);
        digitalWrite(0, HIGH);
        delay(100);
        digitalWrite(0, LOW);
        delay(100);
        digitalWrite(0, HIGH);
        delay(100);
        digitalWrite(0, LOW);
        delay(100);
        Serial.println("end");
    '''
    vcdfile = tempfile.mkdtemp() + '/vcdtest.vcd'
    sim = ArduinoSim(snippet=snippet, vcd=vcdfile, timespan=0.5)
    sim.run()
Ejemplo n.º 8
0
def check_mcu(mcu1, mcu2):
    snippet = mcu_h.text() + '''
    Serial.print(MCU_DEFINED);
    '''
    s = ArduinoSim(
        snippet=snippet,
        mcu=mcu1,
        timespan=1).get_serial()
    eq_(s, mcu2)
Ejemplo n.º 9
0
def simulator(snippet=None, mcu=None, code=None):
    return ArduinoSim(
        snippet=snippet,
        code=code,
        mcu=mcu,
        #                      extra_lib=root,
        template=TEMPLATE,
        timespan=0.1  # 100ms
    )
Ejemplo n.º 10
0
def run_sim(timespan=5, f_cpu=16000000, speed=1, fps=20):
    ArduinoSim(
        snippet=snippet,
        timespan=timespan,
        serial_line_logger=logger,
        f_cpu=f_cpu,
        fps=fps,
        speed=speed,
    ).run()
Ejemplo n.º 11
0
def simulator(snippet=None, mcu=None, code=None, vcd=None):
    return ArduinoSim(
        snippet=snippet,
        code=code,
        mcu=mcu,
        #                      f_cpu=f_cpu,
        vcd=vcd,
        #                      extra_lib=root,
        template=TEMPLATE,
        timespan=0.1,
    )
Ejemplo n.º 12
0
def generate_vcd(song,
                 vcd,
                 mcu='atmega168',
                 f_cpu=16000000,
                 timespan=2,
                 logger=lambda x: None):
    code = TEMPLATE_PLAY.replace('$SONG$', song)
    vcd = path(vcd)
    d = vcd.dirname()
    fcode = d / ('generated_code4_' + vcd.name + '.c')
    fcode.write_text(code)
    logger('writing ' + fcode)

    x = ArduinoSim(
        code=code,
        mcu=mcu,
        f_cpu=f_cpu,
        vcd=vcd,
        #                      extra_lib=root,
        #                      template=TEMPLATE,
        timespan=timespan,
    )
    x.run()
Ejemplo n.º 13
0
def test_atmega88():
    mcu = 'atmega88'
    snippet = 'Serial.print("hi");'

    output = ArduinoSim(snippet=snippet, mcu=mcu, timespan=0.01).get_serial()
    assert output == 'hi'
Ejemplo n.º 14
0
for source in sources:
    print '  '+source
print '-------------------------------------------------------------------'
print cc.command_list(sources)
error = False
try:
    cc.build(sources = sources)

except:
    error = True
    print cc.error_text

# run the project for 5 seconds
if not error:
    print 'Temporary output file \n' + '   ' + cc.output
    size = cc.size()
    print '-------------------------------------------------------------------'
    print 'Program size \n  program =' , str(size.program_bytes).rjust(8), \
          '\n  data    =', str(size.data_bytes).rjust(7)
    print '-------------------------------------------------------------------'
    simulation = ArduinoSim(external_elf=cc.output,
                            mcu = mcu,
                            f_cpu=f_cpu,
                            timespan=5,
                            fps=20,
                            )
    output = simulation.get_serial()
    print output

print "Aus Maus"
Ejemplo n.º 15
0
from pysimavr.sim import ArduinoSim


vcdfile='delay.vcd'
snippet = '''
    Serial.println("start");
    pinMode(0, OUTPUT);
    digitalWrite(0, HIGH);
    delay(100);
    digitalWrite(0, LOW);
    delay(100);
    digitalWrite(0, HIGH);
    delay(100);
    digitalWrite(0, LOW);
    delay(100);
    Serial.println("end");
'''

if __name__ == "__main__":
    sim = ArduinoSim(snippet=snippet, vcd=vcdfile, timespan=0.5)
    sim.run()
Ejemplo n.º 16
0
def run_sim():
    print ArduinoSim(snippet='Serial.println("hello!");').get_serial()
Ejemplo n.º 17
0
{
    Serial.println(i++);
    _delay_ms(1000);
}
'''
t0 = None


def logger(x):
    global t0
    t = time.time()
    if not t0:
        t0 = t
    print t - t0, x


f_cpu = 16000000
fps = 20
speed = 1
timespan = 5

if __name__ == "__main__":
    ArduinoSim(
        snippet=snippet,
        timespan=timespan,
        serial_line_logger=logger,
        f_cpu=f_cpu,
        fps=fps,
        speed=speed,
    ).run()
Ejemplo n.º 18
0
def check_sim(snippet, mcu, value, timespan=1):
    eq_(ArduinoSim(
        snippet=snippet, mcu=mcu, timespan=timespan).get_serial(), value)
Ejemplo n.º 19
0
from pysimavr.sim import ArduinoSim

if __name__ == "__main__":
    s = ArduinoSim(snippet='Serial.println("hello!");').get_serial()
    print(s)