Beispiel #1
0
def send_data(dev_name, testcase_name):
    dev_fd = open(dev_name, "wb", 0)
    testcase_fd = open(testcase_name, "rb")
    try:
        # read max data
        data = testcase_fd.read(0x1010)
        ret = dev_fd.write(data)
        print("write %d bytes to %s" % (len(data), dev_name))
        xxd_bin(data)
    finally:
        dev_fd.close()
        testcase_fd.close()
    return
Beispiel #2
0
def send_data(dev_name,testcase_name):
    dev_fd = open(dev_name,"wb",0)
    testcase_fd = open(testcase_name,"rb")
    try:
        # read max data
        data = testcase_fd.read(0x1010)
        ret = dev_fd.write(data)
        print("write %d bytes to %s" % (len(data),dev_name))
        xxd_bin(data)
    finally:
        dev_fd.close()
        testcase_fd.close()
    return
Beispiel #3
0
def read_dpram(file_name,size):
    """
    this function try send message
    """
    dpram_fp = open(file_name,"rb",0)

    try:
        data = dpram_fp.read(size)
        print("has read %d char form %s" % (len(data),file_name))
        xxd_bin(data)
        print()
    except Exception as e:
        print("read ",file_name,e)
        print()
        dpram_fp.close()
    finally:
        dpram_fp.close()
    return
Beispiel #4
0
def send_fiber(file_name):
    """
    this function try send message
    """
    fiber_fp = open(file_name, "wb", 0)

    try:
        # generate random number and output
        size = randint(0, 0x30)
        msg = [randint(0, 255) for i in range(size)]
        b = struct.pack("%dB" % size, *tuple(msg))
        xxd_bin(b)
        fiber_fp.write(b)
        print("has write %s %d num" % (file_name, size))
        print()

    finally:
        fiber_fp.close()
    return
Beispiel #5
0
def send_fiber(file_name):
    """
    this function try send message
    """
    fiber_fp = open(file_name,"wb",0)

    try:
        # generate random number and output
        size = randint(0,0x30)
        msg = [randint(0,255) for i in range(size)]
        b = struct.pack("%dB" % size,*tuple(msg))
        xxd_bin(b)
        fiber_fp.write(b)
        print("has write %s %d num" % (file_name,size))
        print()

    finally:
        fiber_fp.close()
    return
Beispiel #6
0
def recv_fiber(file_name):
    """
    this function try recv message
    """
    fiber_fp = open(file_name,"rb",0)
    print("has open",file_name);

    try:
        b = fiber_fp.read(0xFFF)
        if b:
            print("has read %d num from %s" % (len(b),file_name))
            xxd_bin(b)
        else:
            print("none data read from %s" % file_name)
        print()

    finally:
        fiber_fp.close()
    return
Beispiel #7
0
def send_can(file_name):
    """
    this function try send message
    """
    can_fp = open(file_name,"wb",0)

    try:
        size = 13
        msg = [randint(0,255) for i in range(size)]
        msg[0] = 0x88 # 扩展帧
        b = struct.pack("%dB" % size,*tuple(msg))
        can_fp.write(b)
        print("has write to %s %d char" % (file_name,size))
        xxd_bin(b)
        print()

    finally:
        can_fp.close()
    return
Beispiel #8
0
def recv_data(file_name, size):
    """
    this function try recv message
    """
    fiber_fp = open(file_name, "rb", 0)

    try:
        #size = 0xff7
        #size = 0xff
        b = fiber_fp.read(size)
        if b:
            print("has read %d num from %s" % (len(b), file_name))
            xxd_bin(b)
        else:
            print("none data read from %s" % file_name)
        print()

    finally:
        fiber_fp.close()
    return
Beispiel #9
0
def recv_data(file_name,size):
    """
    this function try recv message
    """
    fiber_fp = open(file_name,"rb",0)

    try:
        #size = 0xff7
        #size = 0xff
        b = fiber_fp.read(size)
        if b:
            print("has read %d num from %s" % (len(b),file_name))
            xxd_bin(b)
        else:
            print("none data read from %s" % file_name)
        print()

    finally:
        fiber_fp.close()
    return
Beispiel #10
0
def recv_uart(name):
    """
    this function try recv message from /dev/name
    """
    file_name = "/dev/%s" % name

    uart_fp = open(file_name, "rb", 0)

    try:
        b = uart_fp.read(0x7F)
        if b:
            print("has read %d char from %s" % (len(b), file_name))
            xxd_bin(b)
        else:
            print("none data read from %s" % file_name)
        print()

    finally:
        uart_fp.close()
    return
Beispiel #11
0
def send_dpram(file_name,size):
    """
    this function try send message
    """
    dpram_fp = open(file_name,"wb",0)

    try:
        # generate random number and output
        #size = randint(5,10)
        msg = [randint(0,255) for i in range(size)]
        b = struct.pack("%dB" % size,*tuple(msg))
        dpram_fp.write(b)
        print("has write to %s %d char" % (file_name,size))
        xxd_bin(b)
        print()
    except Exception as e:
        print("write ",file_name,e)
        print()
        dpram_fp.close()
    finally:
        dpram_fp.close()
    return
Beispiel #12
0
def send_uart(name):
    """
    this function try send message to /dev/name
    """
    file_name = "/dev/%s" % name

    uart_fp = open(file_name,"wb",0)

    try:
        # generate random number and output
        #size = randint(0,0x7f)
        size = 10
        msg = [randint(0,255) for i in range(size)]
        b = struct.pack("%dB" % size,*tuple(msg))
        uart_fp.write(b)
        print("has write %s %d num" % (file_name,size))
        xxd_bin(b)
        print()

    finally:
        uart_fp.close()
    return
Beispiel #13
0
def send_dpram(file_name, size):
    """
    this function try send message
    """
    dpram_fp = open(file_name, "wb", 0)

    try:
        # generate random number and output
        #size = randint(5,10)
        msg = [randint(0, 255) for i in range(size)]
        b = struct.pack("%dB" % size, *tuple(msg))
        dpram_fp.write(b)
        print("has write to %s %d char" % (file_name, size))
        xxd_bin(b)
        print()
    except Exception as e:
        print("write ", file_name, e)
        print()
        dpram_fp.close()
    finally:
        dpram_fp.close()
    return
Beispiel #14
0
def send_uart(name):
    """
    this function try send message to /dev/name
    """
    file_name = "/dev/%s" % name

    uart_fp = open(file_name, "wb", 0)

    try:
        # generate random number and output
        #size = randint(0,0x7f)
        size = 10
        msg = [randint(0, 255) for i in range(size)]
        b = struct.pack("%dB" % size, *tuple(msg))
        uart_fp.write(b)
        print("has write %s %d num" % (file_name, size))
        xxd_bin(b)
        print()

    finally:
        uart_fp.close()
    return
Beispiel #15
0
def send_net(file_name):
    """
    this function try send message
    """

    net_fp = open(file_name, "wb", 0)
    ip_bin_a = struct.pack("4B", 192, 168, 1, 95)
    ip_bin_b = struct.pack("4B", 192, 168, 2, 95)
    ip = struct.unpack("1i", ip_bin_a)
    #print("ip:%x port:3000" % ip)
    # set ip a
    ioctl(net_fp.fileno(), 0xc0046b32, ip[0])
    # set port a
    ioctl(net_fp.fileno(), 0xc0046b33, 3000)

    ip = struct.unpack("1i", ip_bin_b)
    # set ip b
    ioctl(net_fp.fileno(), 0xc0046b34, ip[0])
    # set port b
    ioctl(net_fp.fileno(), 0xc0046b35, 3000)

    try:
        # generate random number and output
        size = randint(19, 255)
        msg = [randint(0, 255) for i in range(size)]
        msg[0] = 0x55
        msg[1] = 0xAA
        msg[10] = 0
        b = struct.pack("%dB" % size, *tuple(msg))
        net_fp.write(b)
        print("has write to %s station:%d %d char" % (file_name, 0, size))
        xxd_bin(b)
        print()

    finally:
        net_fp.close()
    return
Beispiel #16
0
def send_net(file_name):
    """
    this function try send message
    """

    net_fp = open(file_name,"wb",0)
    ip_bin_a = struct.pack("4B",192,168,1,95)
    ip_bin_b = struct.pack("4B",192,168,2,95)
    ip = struct.unpack("1i",ip_bin_a)
    #print("ip:%x port:3000" % ip)
    # set ip a
    ioctl(net_fp.fileno(),0xc0046b32,ip[0])
    # set port a
    ioctl(net_fp.fileno(),0xc0046b33,3000)

    ip = struct.unpack("1i",ip_bin_b)
    # set ip b
    ioctl(net_fp.fileno(),0xc0046b34,ip[0])
    # set port b
    ioctl(net_fp.fileno(),0xc0046b35,3000)

    try:
        # generate random number and output
        size = randint(19,255)
        msg = [randint(0,255) for i in range(size)]
        msg[0] = 0x55
        msg[1] = 0xAA
        msg[10] = 0
        b = struct.pack("%dB" % size,*tuple(msg))
        net_fp.write(b)
        print("has write to %s station:%d %d char" % (file_name,0,size))
        xxd_bin(b)
        print()

    finally:
        net_fp.close()
    return
Beispiel #17
0
 def handle(self):
     data = self.request[0]
     print("%s wrote:" % self.client_address[0])
     xxd_bin(data)
Beispiel #18
0
 def handle(self):
     data = self.request[0]
     print("%s wrote:" % self.client_address[0])
     xxd_bin(data)
Beispiel #19
0
# 2.make sure assigned msg[0] and msg[1] to 0x55 and 0xAA respectively.otherwise
#   SCM of W7100 will discard this packet.
# 3.make sure msg[10] is range from 1 to 10.because FPGA only allocate 10 block
#   to simulate the full duplex virtual network,if you assign other number at 
#   here,you will not be send and recieve successfully.
#

import socket
import struct
from xxd import xxd_bin

address = ('192.168.1.4', 3000)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

size = 0xff

msg = [0x01 for i in range(size)]
#head
msg[0] = 0x55
msg[1] = 0xAA
msg[10] = 0x01
msg[15] = 0x0b
msg[16] = 0x00

b = struct.pack("%dB" % size ,*tuple(msg))
print("sendto {0}:{1}".format(*address))
xxd_bin(b)
s.sendto(b, address)

s.close()
Beispiel #20
0
#!  /usr/bin/python3
# author: zhangys
# date  : 20140310
# ver   : 0.1
#
# this program will test read data from can board

from xxd import xxd_bin

cana_file_name = "/dev/cana"

buf_size = 0x2000

# open function use 4096 as its buffer size,we expected it is no buffer
cana_fp = open(cana_file_name,"rb",0)

try:
    buf = cana_fp.read(buf_size)
    xxd_bin(buf)

finally:
    cana_fp.close()


Beispiel #21
0
# 2.make sure assigned msg[0] and msg[1] to 0x55 and 0xAA respectively.otherwise
#   SCM of W7100 will discard this packet.
# 3.make sure msg[10] is range from 1 to 10.because FPGA only allocate 10 block
#   to simulate the full duplex virtual network,if you assign other number at
#   here,you will not be send and recieve successfully.
#

import socket
import struct
from xxd import xxd_bin

address = ('192.168.1.4', 3000)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

size = 0xff

msg = [0x01 for i in range(size)]
#head
msg[0] = 0x55
msg[1] = 0xAA
msg[10] = 0x01
msg[15] = 0x0b
msg[16] = 0x00

b = struct.pack("%dB" % size, *tuple(msg))
print("sendto {0}:{1}".format(*address))
xxd_bin(b)
s.sendto(b, address)

s.close()