I use WinAVR with eclipse to program an Arduino (AVR ATmega 328p). Since I updated the AVR-LibC to 2.0 I am not able to process direct char-arrays (Strings).
When I try
char test[10] = "hallo";
RS232_SendString(test);
it works and sends (68 61 6C 6C ...), but when i try
RS232_SendString("hallo");
it just sends nothing (00 00 00 00 ...).
Does anyone knows whats the problem and how to solve it?
Thanks in advance,
Spider
Related
I'm developing a flash based USB mass storage device with FAT16 file system.
It's working properly, however I have difficulties understanding what's happening on the FAT segments.
When I begin, I have a single file, 56 bytes long on the root directory, it's 32bits long and the data is stored on the 2nd cluster (the 0 and the 1 can't be used in FAT).
if I look at the memory dump of the FAT segment I see:
f8 ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00... zeros until the end
As I understand, the last 0xFFFF means that this cluster is the last cluster in the chain for this file.
so far so good.
But... when I extend the size of the actual file to 4,032 bytes , the FAT segment turn into
f8 ff ff 00 f0 ff 05 60 00 07 f0 ff 00 00 00 00 00... zeros until the end
Can anyone explain what's going on here ?
I see several things I can't explain:
1. why does the 4 system reserved bytes change ?
2. I can't see any 0xFFFF which means, there isn't an end to the cluster chain ?
If it helps anyone, the block size is 512 bytes, the file system is formatted 2 segments per cluster.
Figures it was FAT12 and not FAT16 I was working with.
FAT12-16 distinguished by the number of clusters, not the string that's written in the boot sector.
I'm not sure how to use hton(). The theory is that any data sent over the network should be in network byte (i.e. big-endian) format. Suppose client A supports big-endian and B supports little-endian. I'm sending data from A to B and the data is read as multibyte. Then in the network we need to convert data to network byte order using htonl() and htons(). Since client A is already big-endian, htonl() and htons() return the same output. But B is little-endian, so those functions reverse the order. Given that, how can we say that adhering to a common format (i.e. big-endian) is a solution to the problem when big- and little-endian machines need to communicate?
I'll try it the other way, showing the whole flow:
Sending 0x44332211 over the wire always happens as 44 33 22 11. The sender's htonl() ensures that, either by reverting the order of the bytes (on LE machines) or by just leaving them the way they are (on BE machines). The receiver turns the 44 33 22 11 into 0x44332211 with ntohl() - again, either by reverting them or leaving them.
The mentionned functions {hton,ntoh}{l,s}() help programming in a portable way: no matter if the program tuns on a LE or BE machine, they always work the way they should. Thus, even on BE machines the functions should be called, even if they are noops.
Example:
A (BE) wants to send 0x44332211 to B (LE).
A has the number 0x44332211 in memory as 44 33 22 11.
A calls htonl() as the program has been written to be portable.
The number is still represented as 44 33 22 11 and sent over the wire.
B receives 44 33 22 11 and puts it through ntohl().
B gets the value represented by 11 22 33 44 from ntohl() and puts it into the respective variable - which then results to 0x44332211 as wanted.
Again, the need for always calling these function saves you from thinking about which kind of machine you are programming for - just program for all kinds of machines and call each of these function when they are needed.
The same example can be expressed without knowing if A or B are BE or LE:
A has the number 0x44332211 in memory.
A calls htonl() so that the number is sent as 44 33 22 11 over the wire.
Whether this is done by reverting or by leaving it is determined by the endianness of host B.
B receives 44 33 22 11 and puts it through ntohl(). This one reverses it or not, depending on the endianness of host B.
B gets the value 0x44332211 as wanted.
I think you're thinking that client B seeing the bytes in "reversed order" means that they're wrong. The bytes will be in reverse order compared to client A, but that's because client A interprets integers backwards from client B; both will still interpret it as the same number in the end. For example, one machine would represent the number 4 as 00 00 00 04. The other would represent it as 04 00 00 00, but both would still see it as a 4 -- if you add 1 to it you're going to get 00 00 00 05 and 05 00 00 00, respectively. The hton/ntoh functions exist because there's no way to look at a number and know if it's big- or little-endian, so the receiver can't be sure which way to interpret the bytes
I'm currently working on a project in which I use antennas such as XBee 2 mW Wire Antenna - Series 2 (ZigBee Mesh).
How can I configure my antenna to go sleep mode using software in API mode (without using XCTU)?
How am I supposed to wake up the antenna?
There are many ways to put your device to sleep. If you don't have access to X-CTU you can give the END-DEVICE antenna (it has to be an end device cause for obvious reasons routers and coordinators can't stop responding) a remote AT command through another antenna (usually the coordinator with the help of any microcontroller)
There are 4 types of sleep you can configure (SM) depending on the value you assign
0 - NO SLEEP
1 - PIN HIBERNATE //I believe this one will wake the device only
when Sleep_Rq, module pin 9, transitions from a high to a low
state.There is not much documentation on this mode
4 - Cyclic SLEEP //This mode depends on the SP and SN parameters.
SP (20 to AF0) is the period of sleep in milliseconds and SN (0000
to FFFF) is the number of periods to sleep before waking
5 - Cyclic SLEEP with pin
wake //same as before but you can wake the device also when Sleep_Rq,
module pin 9, transitions from a high to a low state.
This is a typical api message that configures your end device for sleep mode 4
7E //start delimiter
00 0F //length
17 //frame type identifier (remote AT message)
01 //frame ID
00 7D 33 A2 00 40 5C 42 //64bit END-DEVICE address
0C FF //16bit destination network address
02 //command options
83 77 //command name ( SM in ASCII )
04 //command data
** //checksum
In general X.CTU saves you a lot of time, if for some reason you can't use it check out this valid alternative Zigbee Operator
I looked in The RFC and noting could explain why the following happens(Though the decoder can still produce the original movie).
I transmitted the H.264/AVC nals using VSS h.264 encoder, the byte stream looked something like this E5 46 0E 4F FF A0 23...
when I read the movie data one the receiver side after the RTP Broadcaster/RTSP receiver, I get extra unknown data but always in the same places, 8 bytes are added before Start Code prefix (0x00000001),
and 2 bytes are added after Start Code prefix it looks something like this.
XX XX XX XX XX XX XX XX 00 00 00 01 XX XX, then I look in the Wireshark and i could see that the RTP adds the bytes to the data payload.
Why does it happens why? and why the decoder seems to cope well with those extra bytes?!
Thats some messed up stream... And you can mess it up even more, and it will still work, because decoder parses it for 0x000001 start code, skipping the bytes that are added at the beginning. Those two new bytes at the end must be H264 fragmentation bytes... or something H264 related since they work.
So basically, this is due to defective packetizer/RTSP source filter. My guess is that if you ASCII encode those 8 bytes you will get the vendor name of the RTSP source filter... xD
As I mentioned in another post Changing NALU h.264/avc, for RTP encupsulation, H.264 is transmitted over RTP as defined in RFC 3984. This in particular defines how exactly large NAL units are broken into smaller parts that fit smaller message sizes, suchas UDP datagram size. That is, fragmentation.
Receiver depacketizes the data and restores NALUs, and it uses this extra information to do the job.
So what you essentially need is to compare raw data you have against RFC 3984 format. Also, Wireshark already does partially this for you by dissecting traffic into readable items.
On two PC, I am opening an AF_PACKET / PF_PACKET socket, raw protocol.
sock = socket(AF_PACKET, SOCK_RAW, htons(PROTO_BULK))
(edit: PROTO_BULK is a dummy type, created by myself for this test. I do not expect it to be inferring with this problem, but I may be wrong.)
The first PC send a packet to the other the standard send() way, which is received on the other side with:
recvfrom(sock, buffer, 1600, 0, (struct sockaddr*) &from, &fromlen);
My problem is now: what is the type of the data in "from"? Here is an exemple of what I am receiving:
00 00 00 00 00 00 00 00 f8 cd a1 00 58 1d a1 00 94 60
From the length and the content, it does not look like a "struct sockaddr" nor a "sockaddr_ll". Any idea?
I am actually looking for the interface the packet was received on. I could use the destination MAC from the packet and identify the interface from it, but it would not work with a broadcast packet.
I am running a recent Linux kernel (and I do not want to investigate in the kernel sources!).
Edit: My code was wrong. I did not initialized "fromlen" with "from" buffer size, so I supposed some spurious value was there and "recvfrom()" could not do its job correctly. Thanks to Ben Voigt for pointing me this bug with his comment below! Of course, I did not include this part of the faulty code in my question, as it was obvious there could be no mistake with such simple code...
With the correct paramter, I get a "struct sockaddr_ll" correctly filled, including the interface number I was looking for.
I am actually looking for the interface the packet was received on.
You should be using recvmsg, which gives access to metadata such as the packet's destination address (useful for multihomed systems) and I think also the interface.
The sender address you're looking at now isn't going to tell you the interface. It's good for sending a reply packet with sendto though.
I took a glance at the kernel sources. I do not claim to fully understand them, but...
Is PROTO_BULK 37984 (0x9460)?
If so, this is probably a "struct sockaddr_pkt". (It has the right size, anyway.) Although I am not sure what the other bytes mean. If I am reading the code correctly, they should be the "name" of the interface on which the packet was received. So I am probably reading the code incorrectly.