Byte Back Solutions

0 views
Skip to first unread message

Angelique Syria

unread,
Aug 5, 2024, 12:37:58 AM8/5/24
to tiostopdicon
Fornow I am focused on just getting some DFU command to work successfully over I2C, and I started with "Get Version" to get the bootloader version. I am able to get the ACK byte back (0x79), but not the rest of the data.

Since the documentation flowcharts indicates for host to "wait for ACK" (although the device flowchart does not mention it). I also tried to first read 1 byte for the ACK, check it, and then wait for the remaining 2 bytes. In this case I get the ACK byte successfully, but then nothing for. I have tried to omit the STOP condition.


The device is put into the sytem bootloader using the BOOT0/RESET pins. I always do this, then wait 1 second, before attempt I2C communication. The ACK byte is reliably transmitted, 5/5 times per each test-run.


The host board, which will do the programming, is a Particle P1 (STM32F2xx I think). There are other I2C devices on the bus, like a screen and I/O expander, etc. I have check and there should be no conflict for the address.


I've been struggling to implement this too and think I finally cracked the code. The AN4221 document isn't very clear on what "wait for ACK or NACK frame" really means. But as you discovered, you can't just read three bytes as AN4221 section 2.2 would suggest. You actually have to do a read (with I2C start and stop conditions) to get the first ACK/NACK byte, a second read to get the data byte, and a third and final read to get the final ACK/NACK byte. I figured this out doing a lot of playing with the Bus Pirate tool; in Bus Pirate commands, it looks like this:


where "[" indicates an I2C start condition, "]" indicates an I2C stop condition, hex numbers specify a byte written, and "r" specifies a byte read. Don't get too confused by the addresses here; Bus Pirate needs you to specify the address left-shifted with the read/write bit, so 0x94 really is a write to 0x4A (the bootloader I2C address in my STM32L452 device) and 0x95 is a read from 0x4A. So to re-write your pseudocode, try this:


Hopefully this helps, and you'll be able to properly interpret the other command flowcharts. Figuring out how to do something complex like a memory read or write is a bit of a chore, and the documentation is less than clear about the details. It really helps to have a tool that allows you to "play" with the I2C bus readily, and a good scope so you can see the actual bus traffic.


Java 8 provides Byte.toUnsignedInt to convert byte to int by unsigned conversion. In Oracle's JDK this is simply implemented as return ((int) x) & 0xff; because HotSpot already understands how to optimize this pattern, but it could be intrinsified on other VMs. More importantly, no prior knowledge is needed to understand what a call to toUnsignedInt(foo) does.


In total, Java 8 provides methods to convert byte and short to unsigned int and long, and int to unsigned long. A method to convert byte to unsigned short was deliberately omitted because the JVM only provides arithmetic on int and long anyway.


Also, bear in mind that you can't use byte type, doing so will result in a signed value as mentioned by other answerers. The smallest primitive type you could use to represent an 8-bit unsigned value would be a short.


The solution works fine (thanks!), but if you want to avoid casting and leave the low level work to the JDK, you can use a DataOutputStream to write your int's and a DataInputStream to read them back in. They are automatically treated as unsigned bytes then:


Even though it's too late, I'd like to give my input on this as it might clarify why the solution given by JB Nizet works. I stumbled upon this little problem working on a byte parser and to string conversion myself.When you copy from a bigger size integral type to a smaller size integral type as this java doc says this happens:


-5.html#jls-5.1.3A narrowing conversion of a signed integer to an integral type T simply discards all but the n lowest order bits, where n is the number of bits used to represent type T. In addition to a possible loss of information about the magnitude of the numeric value, this may cause the sign of the resulting value to differ from the sign of the input value.


Second part of the story involves how Java unary and binary operators promote operands. -5.html#jls-5.6.2Widening primitive conversion (5.1.2) is applied to convert either or both operands as specified by the following rules:


I was thinking of iterating the string array twice, first one to get the actual size needed for the byte array and then a second one to write the length and actual string ([]byte(str)) for each element.


XML is another common format. However, it has pretty high overhead and not as easy to use. While you could just do the same you did for gob and json, proper xml requires a root tag. In this case, we are using the root tag "Strings" and each string is wrapped in an "S" tag.


CSV is different from the others. You have two options, use one record with n rows or n records with 1 row. The following example uses n records. It would be boring if I used one record. It would look too much like the others. CSV can ONLY hold strings.


Which format you use is a matter of preference. There are many other possible encodings that I have not mentioned. For example, there is an external library called bencode. I don't personally like bencode, but it works. It is the same encoding used by bittorrent metadata files.


I would suggest to use PutUvarint and Uvarint for storing/retrieving len(s) and using []byte(str) to pass str to some io.Writer. With a string length known from Uvarint, one can buf := make([]byte, n) and pass the buf to some io.Reader.


Prepend the whole thing with length of the string array and repeat the above for all of its items. Reading the whole thing back is again reading first the outer length and repeating n-times the item read.


I understand that there are similar questions, but I do not understand them so here goes: I have bytes (encoded from a string) in a string form (read from a file). When I try to decode the bytes, I get an error saying that it is a string, not bytes. I understand it is in the wrong form, but do I not have the correct information? How can I convert bytes in a string back to bytes? I will also note I know this is not a secure password method and will not be used as one. (I am using python 3)


With prices rising and decreased support, the time has come to cut the cord. Get ahead of the shutdown by switching to POTS over LTE/5G solutions that deliver immediate cost savings and productivity enhancements.


Reliable, high-speed internet access is required for so many of our daily tasks, but the digital divide means that many Americans have to continue to rely on schools and libraries for internet access.


In the fast-paced world of technology, clinging to outdated systems can hold your business back. Say goodbye to the past and hello to ByteSpeed's POTS Line Replacement Solution! Out with the Old: The POTS Line SunsetThe era of Plain Old Telephone Service (POTS) lines is...


ByteSpeed has been a leading IT solutions resource since 1999. We provide customized computer hardware, enterprise networking solutions, and professional IT services nationwide. We have a proven track record of excellent customer service and a strong focus on offering a personal level of service.


Hi all. I am trying to setup a site to site VPN tunnel with one of our customer. I've got the dedicated layer 3 zone, tunnel interface, IKE Gateway, Virtual Router etc. configured per the Palo Alto admin guide. In the "IPSec Tunnels" section, it shows the VPN tunnel is up. However, I cannot access any of the server located at the customer's environment.


The numbers '1' and '2' are the 2 rows you will create in the packet filter. The addresses x.x.x.x and y.y.y.y are the source and destination (and back) for the actual IPs you are pinging from and to. Configure packet capture for the drop, receive and transmit stage. Refer to this KB for more information on pcaps - -Articles/How-to-Run-a-Packet-Capture/ta-p/62390


If we are simply not receiving packets, then the issue could be return route on the remote site. If we are receiving packets, then we'd have to check in the counters and flow basic (debug logs) to find out where it's going.


is it a PA on both ends of the tunnel? or what device are they using? dunno if it's of any help, but just throwing it out there because there is the requirement of the use of proxy ids in order to establish a tunnel with a policy-based vpn device to essentially identify the interesting traffic.


I am wondering if the remtoe network didn't configure their route properly. Otherwise I don't see any issue on the VPN tunnel side, it is up, just no traffic coming back. Also the tracert result bothers me, as it shows stopped on our PA.


So I ran the "show vpn flow name" command, and I can see the "encap/decap bytes" field logs data there, and no authentication errors. The tunnel looks perfectly fine. Pretty much stuck on this one ...


I'm currently working on a project, where serial data is "received" in data bursts. These bursts happen every few seconds and are about 100-200bytes long. I'm currently receiving at a rate 9600 baude. So far, so good - everything works. The problem starts, when the data is received while the display gets updatet. The display update-cycle takes 60ms which is 8times longer then the data-burst (7ms) and the data can't be read before the serial-buffer is overflowed.


Maybe i missed it, but i coulnd't find a "overflow" handler method/callback in the hardware serial implementation which would be invoked on an overflow.. What i (would) need is some interrupt (or callback) which has a higher priority and would interrput the display update if new data arrives.


yes, that would be the simplest solution.

The code above doesn't work yet - just don't know why..might be, because i'm running out of memory - or because of an endless recurion (though i tought, the overflow_handler would "reset" tail/head) - or because i have a race condition in the overflow-handler

3a8082e126
Reply all
Reply to author
Forward
0 new messages