-
Notifications
You must be signed in to change notification settings - Fork 0
/
coap-dfu-server.py
executable file
·55 lines (50 loc) · 1.89 KB
/
coap-dfu-server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env python2
import click
import os
import piccata
import sys
import logging
import time
sys.path.append(os.getcwd() + '/pc-nrfutil')
from transport.tsocket import SocketTransport
from nordicsemi.thread.dfu_thread import create_dfu_server
from nordicsemi.dfu.package import Package
logging.basicConfig(format='%(asctime)s %(message)s', level=2)
def pause():
while True:
time.sleep(5)
@click.command(short_help="Update the firmware on a device over an IP connection.")
@click.option('-pkg', '--package',
help='Filename of the DFU package.',
type=click.Path(exists=True, resolve_path=True, file_okay=True, dir_okay=False),
required=True)
@click.option('-sp', '--server_port',
help='UDP port to which the DFU server binds. If not specified the 5683 is used.',
type=click.INT,
default=5683)
@click.option('-mc', '--mcast_dfu',
help='Use multicast. ',
default=False)
@click.option('-r', '--rate',
help="Multicast upload rate in blocks per second.",
type=click.FLOAT)
@click.option('-rs', '--reset_suppress',
help='Suppress device reset after finishing DFU for a given number of milliseconds. ' +
'If -1 is given then suppress indefinitely.',
type = click.INT,
metavar = '<delay_in_ms>')
def start_server(package, server_port, mcast_dfu, rate, reset_suppress):
opts = type('DFUServerOptions', (object,), {})()
opts.mcast_dfu = mcast_dfu
opts.rate = rate
opts.reset_suppress = reset_suppress
transport = SocketTransport(server_port)
dfu = create_dfu_server(transport, package, opts)
try:
sighandler = lambda signum, frame : transport.close()
transport.open()
pause()
except Exception as e:
print(e)
if __name__ == '__main__':
start_server()