将二进制文件发送到16微控制器。 [英] sending binary files to a 16 micro controller.

查看:75
本文介绍了将二进制文件发送到16微控制器。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个项目,需要能够将固件上传到基于微控制器的以太网设备。但由于内存受限制,控制器只能处理每个300字节的封装时间。因此固件文件必须以块的形式发送,我需要每个文件中的一个标题,描述文件的哪一部分是我发送的
。任何人都可以给我一些关于如何在python中完成

的指针?我在谈论通过TCP上传软件

到客户端的客户端。


祝你好运


Johnny Karlsson

解决方案

jo ************* @ gmail.com 写道:

我正在做一个项目是一个需要能够将固件上传到基于微控制器的以太网设备。但由于内存的限制,控制器每次只能处理300字节的包。因此,固件文件必须以块的形式发送,我需要在每个文件中使用一个标题来描述它是我发送的文件的哪个部分。谁能给我一些关于如何在python中完成的指针?我说的是通过TCP将软件上传到设备的客户端。




你可以从这里开始:
http://docs.python.org/lib/socket-example.html


如果您不确定传输的

消息的确切内容,并且可以访问其他一些客户端程序,您可以

写一个Python服务器,看看客户端发送的另一个b / b
究竟是什么位模式。然后你可以编写一个行为与
相同的Python客户端。


拆分和传输文件的基本模式可能是

类似于:


f = open(''filename'')

header_template =''Chunk%05i,%03i bytes''

表示i,枚举中的字节数(f.read(max_number_of_bytes_per_chunk)):

msg = header_template%(i,len(bytes))

msg + =字节

sock.send(msg)

sock.send(''结束!'')


< blockquote> Magnus Lycka写道:

header_template =''Chunk%05i,%03i bytes''




BTW,如果标题是二进制的,你可能想看看结构模块的

http://docs.python.org/lib/module-struct。 html


2005-08-22, jo ************* @ gmail.com < jo ************* @ gmail.com>写道:

我正在研究一个项目,需要能够将固件上传到基于微控制器的以太网设备。但由于内存的限制,控制器每次只能处理300字节的包。因此,固件文件必须以块的形式发送,我需要在每个文件中使用一个标题来描述它是我发送的文件的哪个部分。谁能给我一些关于如何在python中完成的指针?我正在谈论通过TCP将软件上传到设备的客户端。




如果使用,您无法控制TCP中的数据包大小

普通套接字接口。关于你可以做的唯一事情是

在send()调用之间放置延迟,希望TCP堆栈

将发送一个数据包。

如果你真的想要控制数据包大小,你将不得不使用一个原始套接字并且自己实施TCP。


-

格兰特爱德华兹格兰特哇!在这之后,让我们去往费城的


visi.com TRIPLETS !!


Hi, I''m working on a project were a need to be able to upload firmware
to a microcontroller based Ethernet device. But because of the memory
constraints the controller can only handle packages of 300 bytes each
time. So therefore the firmware file must be sent in chunks and i need
a header in each file describing which part of the file it is I''m
sending. Could anyone give me some pointer on how a could accomplish
that in python? I''m talking about the client that uploads the software
to the device via TCP.

Best regards

Johnny Karlsson

解决方案

jo*************@gmail.com wrote:

Hi, I''m working on a project were a need to be able to upload firmware
to a microcontroller based Ethernet device. But because of the memory
constraints the controller can only handle packages of 300 bytes each
time. So therefore the firmware file must be sent in chunks and i need
a header in each file describing which part of the file it is I''m
sending. Could anyone give me some pointer on how a could accomplish
that in python? I''m talking about the client that uploads the software
to the device via TCP.



You can probably start here:
http://docs.python.org/lib/socket-example.html

If you''re uncertain about the exact content of the transmitted
messages, and has access to some other client program, you could
write a Python server and see exactly what bit pattern the other
client sends. Then you can write a Python client that behaves the
same way.

The basic pattern to split and transmit your file would probably
be something like:

f = open(''filename'')
header_template = ''Chunk %05i, %03i bytes''
for i, bytes in enumerate(f.read(max_number_of_bytes_per_chunk)):
msg = header_template % (i, len(bytes))
msg += bytes
sock.send(msg)
sock.send(''The end!'')


Magnus Lycka wrote:

header_template = ''Chunk %05i, %03i bytes''



BTW, if the header is binary, you probably want to have a look at
the struct module. http://docs.python.org/lib/module-struct.html


On 2005-08-22, jo*************@gmail.com <jo*************@gmail.com> wrote:

I''m working on a project were a need to be able to upload firmware
to a microcontroller based Ethernet device. But because of the memory
constraints the controller can only handle packages of 300 bytes each
time. So therefore the firmware file must be sent in chunks and i need
a header in each file describing which part of the file it is I''m
sending. Could anyone give me some pointer on how a could accomplish
that in python? I''m talking about the client that uploads the software
to the device via TCP.



You have no control over packet size in TCP if you use the
normal socket interface. About the only thing you can to is
put delays between calls to send() in hope that the TCP stack
will send a packet.

If you really do want control over packet size, you''ll have to
use a raw socket and impliment TCP yourself.

--
Grant Edwards grante Yow! After THIS, let''s go
at to PHILADELPHIA and have
visi.com TRIPLETS!!


这篇关于将二进制文件发送到16微控制器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆