mqtt-sn what is the raw data format - mqtt
I am very new to this mqtt-sn stuff. So my question is - how does a mqtt-sn message look like. So I mean the raw data format. I do not clearly understand what octet means. So as I understand an octet is a byte.
So is the data transferred binary?
Or what means octet exact?
Please can someone give me a sample message. It is really bad that there is not example message in the specification.
Thanks,
Mathias
An octet is just a collection of 8 bit so just another name for a byte
So a message consists of a header made up of 2 or 4 bytes and the the message body.
The header is sub divided into 1 OR 3 bytes for the length and 1 byte for the type. If the first byte is 0x01 then the next 2 bytes are the length, else the value of the first byte is the length.
The next byte is a type, a table of valid message types can be found in sections 5.2.2 in the spec
The Message body varies depending on the type.
But to publish a message with payload HelloWorld on Topic ID of AB (0x41, 0x42) would look something like this:
0x0F - length (15 bytes total, including length)
0x0C - msg type (publish)
0x02 - flags (QOS 0, topic name)
0x41 - topic ID 1
0x42 - topic ID 2
0x00 - MsgID (00 for QOS 0)
0x48 - H
0x65 - e
0x6C - l
0x6C - l
0x6F - o
0x57 - W
0x6F - o
0x72 - r
0x6C - l
0x64 - d
Where the topic id is the output from a topic register message (Section 6.5 in the spec)
An octet is a byte.
There isn't an example payload because the spec doesn't dictate a payload format. You can use whatever you want.
Related
Need help calculating checksum (crc-16) from a string of data
I need help calculating the checksum (crc-16:X16+X15+X2+1) for BYTE6 and BYTE7 of this data string. I have read some examples but I have no idea how and where to start. What does the X16, X15 etc means? What should I put in BYTE6 and BYTE7? Byte0: 0x55 Byte1: 0x80 Byte2: 0x06 Byte3: 0x02 Byte4: 0x00 Byte5: 0x00 Byte6: MSB of the checksum word (CRC-16) Byte7: LSB of the checksum word (CRC-16)
The CRC polynomial (x16+x15+x2+1) is necessary but not sufficient to define the CRC. You can see this list of 16-bit CRCs, in which you can find seven different CRC's that use that particular polynomial (poly=0x8005). Once you have the full description, you can use my crcany code to generate C code to compute the CRC.
Direct Mapped Cache of Blocks Example
So i have this question in my homework assignment that i have struggling a bit with. I looked over my lecture content/notes and have been able to utilize those to answer the questions, however, i am not 100% sure that i did everything correctly. There are two parts (part C and D) in the question that i was not able to figure out even after consulting my notes and online sources. I am not looking for a solution for those two parts by any means, but it would be greatly appreciated if i could get, at least, a nudge in the right direction in how i can go about solving it. I know this is a rather large question, however, i hope someone could possibly check my answers and tell me if all my work and methods of looking at this problem is correct. As always, thank you for any help :) Alright, so now that we have the formalities out of the way, --------------------------Here is the Question:-------------------------- Suppose a small direct-mapped cache of blocks with 32 blocks is constructed. Each cache block stores eight 32-bit words. The main memory—which is byte addressable1—is 16,384 bytes in size. 32-bit words are stored word aligned in memory, i.e., at an address that is divisible by 4. (a) How many 32-bit words can the memory store (in decimal)? (b) How many address bits would be required to address each byte of memory? (c) What is the range of memory addresses, in hex? That is, what are the addresses of the first and last bytes of memory? I'll give you a hint: memory addresses are numbered starting at 0. (d) What would be the address of the last word in memory? (e) Using the cache mapping scheme discussed in the Chapter 5 lecture notes, how many and which address bits would be used to form the block offset? (f) How many and which memory address bits would be used to form the cache index? (g) How many and which address bits would be used to form the tag field for each cache block? (h) To which cache block (in decimal) would memory address 0x2A5C map to? (i) What would be the block offset (in decimal) for 0x2A5C? (j) How many other main memory words would map to the same block as 0x2A5C? (k) When the word at 0x2A5C is moved into a cache block, what are the memory addresses (in hex) of the other words which will also be moved into this block? Express your answer as a range, e.g., [0x0000, 0x0200]. (l) The first word of a main memory block that is mapped to a cache block will always be at an address that is divisible by __ (in decimal)? (m) Including the V and tag bits of each cache block, what would be the total size of the cache (in bytes) (n) what would be the size allocated for the data bits (in bytes)? ----------------------My answers and work----------------------------------- a) memory = 16384 bytes. 16384 bytes into bits = 131072 bits. 131072/32 = 4096 32-bit words b) 2^14 (main memory) * 2^2 (4 bits/word) = 2^16. take log(base2)(2^16) = 16 bits c) couldnt figure this part out (would appreciate some input (NOT A SOLUTION) on how i can go about looking at this problem d)could not figure this part out either :( e)8 words in each cache line. 8 * 4(2^2 bits/word) = 32 bits in each cache line. log(base2)(2^5) = 5 bits used for block offset. f) # of blocks = 2^5 = 32 blocks. log(base2)(2^5) = 5 bits for cache index g) tag = 16 - 5 - 5 - 2(word alignment) = 4 bits h) 0x2A5C 0010 10100 10111 00 tag index offset word aligned bits maps to cache block index = 10100 = 0x14 i) maps to block offset = 10111 = 0x17 j) 4 tag bits, 5 block offset = 2^9 other main memory words k) it is a permutation of the block offsets. so it maps the memory addresses with the same tag and cache index bits and block offsets of 0x00 0x01 0x02 0x04 0x08 0x10 0x11 0x12 0x14 0x18 0x1C 0x1E 0x1F l)divisible by 4 m) 2(V+tag+data) = 2(1+4+2^3*2^5) = 522 bits = 65.25 bytes n)data bits = 2^5 blocks * 2^3 words per block = 256 bits = 32 bytes
Part C: If a memory has M bytes, and the memory is byte addressable, the the memory addresses range from 0 to M - 1. For your question, this means that memory addresses range from 0 to 16383, or in hex 0x0 to 0x3FFF. Part D: Words are 4 bytes long. So given your answer to C, the last word is at: (0x3FFFF - 3) -> 0x3FFC. You can see that this is correct because the lowest 2 bits of the address are 0, which must be true of any 4 byte aligned address.
Non IDR Picture NAL Units - 0x21 and 0x61 meaning
Does anyone know what does 0x21 and 0x61 means in h.264 encoded video stream? I know that 0x01 means it's a b-frame and 0x41 means it's a p-frame. My encoded video gives me two 0x21 frame followed by one b-frame. I 21 21 B 21 21 B...... What is this 0x21?
First point, a NALu is not the same than as a frame. A frame can contain more that 1 NALu (but not less). A frame can also be made up of more than one slice type. A single frame can have I, B and P slices. If it is an IDR frame, then EVERY slice of that frame must be IDR. 0x01 is NOT a B slice. it is a "Coded slice of a non-IDR picture". exactly like 0x21 and 0x61. It could be a I/B/P or p slice. you need to parse the slice_type to know more.
From H.264 spec: 7.3.1 NAL unit syntax forbidden_zero_bit - 1 bit - shall be equal to 0. nal_ref_idc - 2 bits - not equal to 0 specifies that the content of the NAL unit contains a sequence parameter set [...] nal_unit_type - 5 bits - specifies the type of RBSP data structure contained in the NAL unit [...] 0x21 and 0x61 make it NAL unit type 1 (Coded slice of a non-IDR picture) with different values for nal_ref_idc. UPD. There is no one to one mapping of specific bit, esp. at fixed position from the beginning of the "frame" that says it's I/P/B frame. You will need to parse out the bitstream to read values per 7.4.3 Slice header semantics of H.264 spec (it is still doable in most cases since the value is real close to the beginning of the bitstream - check H.264 spec for details):
Erlang get string from UDP packet
I have this udp packet: P = <<83,65,77,80,188,64,172,85,30,144,105,0,0,0,50,0,7,0,0,0,115,97,109,112,45,114,112,11,0,0,0,149,78,87,149,82,80,149,118,50,46,50,11,0,0,0,83,97,110,32,65,110,100,114,101,97,115>> 14-15 byte is the players var (Byte width - 2) 15-18 byte of it is the length of the server hostname (Byte width - 4) 19 + strlen is the hostname of server (Byte width - strlen) I get players var so: <<_:11/bytes, Players:16/integer-big, Max:16/integer-big, _/binary>> = P. It's 50. How can I get the hostname?
You can improve the expression to obtain the correct values. Note that server length, as you put it, is 32 bits, and, by the look of it, it seems that it is little endian, not big endian (note how the name is 7 bytes, in this case "samp-rp", and the coding of these bytes is <<7,0,0,0>>, which indicates little endian (maybe your players are also little endian). Also, your numbers seem a little bit off. The expression would then be: <<_:14/bytes, Players:16/integer-little, HNameLength:32/integer-little, HostNameBinary:HNameLength/binary, _/binary>> = P. Then, the host name can be converted to a string from the binary with binary_to_list: HostName = binary_to_list(HostNameBinary).
websocket client packet unframe/unmask
I am trying to implement latest websocket spec. However, i am unable to get through the unmasking step post successful handshake. I receive following web socket frame: <<129,254,1,120,37,93,40,60,25,63,71,88,92,125,80,81,73, 51,91,1,2,53,92,72,85,103,7,19,79,60,74,94,64,47,6,83, 87,58,7,76,87,50,92,83,70,50,68,19,77,41,92,76,71,52, 70,88,2,125,90,85,65,96,15,14,20,107,31,14,28,100,27,9, 17,122,8,72,74,96,15,86,68,37,68,18,76,48,15,28,93,48, 68,6,73,60,70,91,24,122,77,82,2,125,80,81,85,45,18,74, 64,47,91,85,74,51,21,27,20,115,24,27,5,37,69,80,75,46, 18,68,72,45,88,1,2,40,90,82,31,37,69,76,85,103,80,94, 74,46,64,27,5,60,75,87,24,122,25,27,5,47,71,73,81,56, 21,27,93,48,88,76,31,57,77,74,11,55,73,68,73,115,65,81, 31,104,26,14,23,122,8,75,68,52,92,1,2,110,24,27,5,53, 71,80,65,96,15,13,2,125,75,83,75,41,77,82,81,96,15,72, 64,37,92,19,93,48,68,7,5,62,64,93,87,46,77,72,24,40,92, 90,8,101,15,28,83,56,90,1,2,108,6,13,21,122,8,82,64,42, 67,89,92,96,15,93,19,56,28,8,65,101,31,94,16,105,28,10, 20,56,30,14,65,56,27,93,71,106,16,11,17,63,25,4,17,57, 73,89,17,59,29,88,29,106,24,27,5,46,65,72,64,54,77,69, 24,122,66,93,93,49,5,12,8,109,15,28,76,59,90,93,72,56, 76,1,2,41,90,73,64,122,8,89,85,50,75,84,24,122,25,15, 23,105,25,5,19,106,26,14,20,111,25,27,5,53,77,85,66,53, 92,1,2,110,26,13,2,125,95,85,65,41,64,1,2,108,27,10,19, 122,7,2>> As per base framing protocol defined here (https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-17#section-5.2) i have: fin:1, rsv:0, opcode:1, mask:1, length:126 Masked application+payload data comes out to be: <<87,58,7,76,87,50,92,83,70,50,68,19,77,41,92,76,71,52,70,88,2,125,90,85,65,96, 15,14,20,107,31,14,28,100,27,9,17,122,8,72,74,96,15,86,68,37,68,18,76,48,15, 28,93,48,68,6,73,60,70,91,24,122,77,82,2,125,80,81,85,45,18,74,64,47,91,85, 74,51,21,27,20,115,24,27,5,37,69,80,75,46,18,68,72,45,88,1,2,40,90,82,31,37, 69,76,85,103,80,94,74,46,64,27,5,60,75,87,24,122,25,27,5,47,71,73,81,56,21, 27,93,48,88,76,31,57,77,74,11,55,73,68,73,115,65,81,31,104,26,14,23,122,8,75, 68,52,92,1,2,110,24,27,5,53,71,80,65,96,15,13,2,125,75,83,75,41,77,82,81,96, 15,72,64,37,92,19,93,48,68,7,5,62,64,93,87,46,77,72,24,40,92,90,8,101,15,28, 83,56,90,1,2,108,6,13,21,122,8,82,64,42,67,89,92,96,15,93,19,56,28,8,65,101, 31,94,16,105,28,10,20,56,30,14,65,56,27,93,71,106,16,11,17,63,25,4,17,57,73, 89,17,59,29,88,29,106,24,27,5,46,65,72,64,54,77,69,24,122,66,93,93,49,5,12,8, 109,15,28,76,59,90,93,72,56,76,1,2,41,90,73,64,122,8,89,85,50,75,84,24,122, 25,15,23,105,25,5,19,106,26,14,20,111,25,27,5,53,77,85,66,53,92,1,2,110,26, 13,2,125,95,85,65,41,64,1,2,108,27,10,19,122,7,2>> While the 32-bit masking key is: <<37,93,40,60,25,63,71,88,92,125,80,81,73,51,91,1,2,53,92,72,85,103,7,19,79,60, 74,94,64,47,6,83>> As per https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-17#section-5.2 : j = i MOD 4 transformed-octet-i = original-octet-i XOR masking-key-octet-j however, i doesn't seem to get my original octet sent from client side, which is basically a xml packet. Any direction, correction, suggestions are greatly appreciated.
I think you've mis-read the data framing section of the protocol spec. Your interpretation of the first byte (129) is correct - fin + opcode 1 - final (and first) fragment of a text message. The next byte (254) implies that the body of the message is masked and that the following 2 bytes provide its length (lengths of 126 or 127 imply longer messages whose length's can't be represented in 7 bits. 126 means that the following 2 bytes hold the length; 127 mean that its the following 4 bytes). The following 2 bytes - 1, 120 - imply a message length of 376 bytes. The following 4 bytes - 37,93,40,60 - are your mask. The remaining data is your message which should be transformed as you write, giving the message <body xmlns='http://jabber.org/protocol/httpbind' rid='2167299354' to='jaxl.im' xml:lang='en' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh' ack='1' route='xmpp:dev.jaxl.im:5222' wait='30' hold='1' content='text/xml; charset=utf-8' ver='1.1 0' newkey='a6e44d87b54461e62de3ab7874b184dae4f5d870' sitekey='jaxl-0-0' iframed='true' epoch='1324196722121' height='321' width='1366'/>