Exemple #1
0
async def dev_service():  # cdbus hw setup
    sock = CDWebSocket(ws_ns, 'dev')
    while True:
        dat, src = await sock.recvfrom()
        print('dev ser', dat)

        if dat['action'] == 'get':
            ports = get_ports()
            if csa['dev']:
                await sock.sendto(
                    {
                        'ports': ports,
                        'port': csa['dev'].portstr,
                        'online': csa['dev'].online,
                        'net': csa['net'],
                        'mac': csa['mac']
                    }, src)
            else:
                await sock.sendto(
                    {
                        'ports': ports,
                        'port': None,
                        'online': False,
                        'net': csa['net'],
                        'mac': csa['mac']
                    }, src)

        elif dat['action'] == 'open' and not csa['dev']:
            try:
                if dat['bridge']:
                    csa['dev'] = CDBusBridge(dat['port'])
                else:
                    csa['dev'] = CDBusSerial(dat['port'], baud=dat['baud'])
                await sock.sendto('successed', src)
            except Exception as err:
                print('open dev err:', err)
                await sock.sendto(f'err: {err}', src)

        elif dat['action'] == 'close' and csa['dev']:
            print('stop dev')
            csa['dev'].stop()
            print('stop finished')
            csa['dev'] = None
            await sock.sendto('successed', src)

        elif dat['action'] == 'set_local':
            print('set_local')
            csa['net'] = dat['net']
            csa['mac'] = dat['mac']
            await sock.sendto('successed', src)

        else:
            await sock.sendto('err: dev: unknown cmd', src)
direct = args.get("--direct") != None
local_mac = int(args.get("--mac", dft="0xaa" if direct else "0x00"), 0)

if args.get("--help", "-h") != None:
    print(__doc__)
    exit()

if args.get("--verbose", "-v") != None:
    logger_init(logging.VERBOSE)
elif args.get("--debug", "-d") != None:
    logger_init(logging.DEBUG)
elif args.get("--info", "-i") != None:
    logger_init(logging.INFO)

if direct:
    dev = CDBusSerial(dev_port=dev_str)
else:
    dev = CDBusBridge(dev_port=dev_str, filter_=local_mac)
CDNetIntf(dev, mac=local_mac)
sock = CDNetSocket(('', 0xcdcd))


def rx_echo():
    while True:
        rx = sock.recvfrom()
        print('\r-> ' + to_hexstr(rx[0]), rx[1])
        print('\r  (' + re.sub(br'[^\x20-\x7e]', br'.', rx[0]).decode() +
              ')\n<-',
              end='',
              flush=True)
Exemple #3
0
direct = args.get("--direct") != None
local_mac = int(args.get("--mac", dft="0xaa" if direct else "0x00"), 0)

if args.get("--help", "-h") != None:
    print(__doc__)
    exit()

if args.get("--verbose", "-v") != None:
    logger_init(logging.VERBOSE)
elif args.get("--debug", "-d") != None:
    logger_init(logging.DEBUG)
elif args.get("--info", "-i") != None:
    logger_init(logging.INFO)

if direct:
    dev = CDBusSerial(dev_port=dev_str)
else:
    dev = CDBusBridge(dev_port=dev_str, filter_=local_mac)


def rx_echo():
    while True:
        rx = dev.recv()
        print('\r-> ' + to_hexstr(rx))
        print('\r  (' + re.sub(br'[^\x20-\x7e]', br'.', rx).decode() + ')\n<-',
              end='',
              flush=True)


_thread.start_new_thread(rx_echo, ())
Exemple #4
0
# Software License Agreement (MIT License)
#
# Copyright (c) 2017, DUKELEC, Inc.
# All rights reserved.
#
# Author: Duke Fong <*****@*****.**>

import sys, os
from time import sleep

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from cdnet.utils.log import *
from cdnet.dev.cdbus_serial import CDBusSerial
from cdnet.dispatch import *

logger_init(logging.VERBOSE)
#logger_init(logging.DEBUG)
#logger_init(logging.INFO)

dev = CDBusSerial('/dev/ttyACM0')  # dev path or filter string
CDNetIntf(dev, net=0, mac=0xaa)
sock = CDNetSocket(('', 0xcdcd))

sock.sendto(b'', ('80:00:55', 1))  # level1, target: mac 55, port 1

print('wait recv')
rx = sock.recvfrom()

print('recv:', rx)
# Software License Agreement (MIT License)
#
# Copyright (c) 2017, DUKELEC, Inc.
# All rights reserved.
#
# Author: Duke Fong <*****@*****.**>

import sys, os
from time import sleep

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from cdnet.utils.log import *
from cdnet.dev.cdbus_serial import CDBusSerial
from cdnet.dispatch import *

logger_init(logging.VERBOSE)
#logger_init(logging.DEBUG)
#logger_init(logging.INFO)

dev = CDBusSerial(dev_port='/dev/ttyUSB0')
CDNetIntf(dev, net=0, mac=0xaa)
sock = CDNetSocket(('', 0xcdcd))

sock.sendto(b'', ('80:00:55', 1))  # level1, target: mac 55, port 1

print('wait recv')
rx = sock.recvfrom()

print('recv:', rx)