Amateur radio, programming, electronics and other musings

All posts in Code

I received an email from someone in the US who had just built one of my Thunderbolt Monitors. He casually asked if there was a way of showing EST rather than UTC on the display. Whilst on a computer this would be easy, it is a little harder on NETMF due to the fact it doesn’t understand timezones. It isn’t just a case of subtracting 5 hours from the UTC time as we also need to consider daylight savings time.

After some research, I put together a code change which appears to work for him and should handle the daylight savings rules too. Before I share the code I must warn you that this is a little rough but solves the problem. I will not be releasing this in the main branch but you should be able to hack it in if you really want it.

Add the following to the end of the class of program.cs.

public static bool IsDaylightSaving(DateTime dt)
{
    var dow = (int)(dt.DayOfWeek);

    // January, February, and December are out.
    if (dt.Month < 3 || dt.Month > 11) { return false; }

    // April to October are in
    if (dt.Month > 3 && dt.Month < 11) { return true; }

    var previousSunday = dt.Day - dow;

    if (dt.Month == 3 && dt.Day >= 8 && dt.Day <= 14 && dow == 0)
    {
        return dt.Hour >= 2;
    }

    // In March, we are DST if our previous sunday was on or after the 8th.
    if (dt.Month == 3) { return previousSunday >= 8; }

    if (dt.Month == 11 && dt.Day >= 1 && dt.Day <= 7 && dow == 0)
    {
        return dt.Hour >= 2;
    }

    // In November we must be before the first Sunday to be DST.
    // That means the previous Sunday must be before the 1st.
    return previousSunday <= 0;

}
 
public static DateTime ConvertToEasternTime(DateTime dt)
{
    var utcOffsetHours = -5;
    if (IsDaylightSaving(dt))
    {
        utcOffsetHours += 1;
    }
    return dt.AddHours(utcOffsetHours);
}

Change references of :

string mode = _thunderbolt.TimingMode == TimingModes.UTC ? "U" : "G";
_lcdshield.WriteLine(0, DateTime.UtcNow.ToString(@"dd-MMM-yy " + mode + " HH:mm:ss"));

to

string mode = "E";
_lcdshield.WriteLine(0, ConvertToEasternTime(DateTime.UtcNow).ToString(@"dd-MMM-yy " + mode + " HH:mm:ss"));

I changed the U/G to an E to signify Eastern time but feel free to ignore that or even replace it with just a space instead.

Today I noticed two WordPress sites I maintain had some broken images. I keep all of my images in Azure Blob Storage so I jumped into Cloudberry Explorer and looked at the files contained in the blob container. I found my images were there. I looked at the source of the page and noticed that the markup has changed for some images.

Since WP4.4 it appears that responsive images have been implemented. The markup for an image now looked like…

&lt;img class="alignright size-medium wp-image-8931" src="http://m1dst.blob.core.windows.net/blog-media/2014/09/lipo-dist-clean-angled-300x300.jpg" sizes="(max-width: 300px) 100vw, 300px" srcset="https://m1dst.blob.core.windows.net/blog-media/2014/09/lipo-dist-clean-angled-150x150.jpg 150w, https://m1dst.blob.core.windows.net/blog-media/2014/09/lipo-dist-clean-angled-300x300.jpg 300w, https://m1dst.blob.core.windows.net/blog-media/2014/09/lipo-dist-clean-angled-1024x1024.jpg 1024w, https://m1dst.blob.core.windows.net/blog-media/2014/09/lipo-dist-clean-angled-144x144.jpg 144w, https://m1dst.blob.core.windows.net/blog-media/2014/09/lipo-dist-clean-angled-480x480.jpg 480w, https://m1dst.blob.core.windows.net/blog-media/2014/09/lipo-dist-clean-angled-900x900.jpg 900w, https://m1dst.blob.core.windows.net/blog-media/2014/09/lipo-dist-clean-angled-924x924.jpg 924w" alt="lipo-dist-clean-angled" width="300" height="300" /&gt;

The code above is the fixed markup not the code that was failing. Having looked in Developer Tools I noticed I was getting a 404 on an image load. Looking at where the image was coming from showed it wasn’t from Azure. This meant that the Azure Storage plugin didn’t yet know about the new SRCSET property. Some searching online found a number of people experiencing the issue and various fixes. http://projectnami.org/fix-for-azure-storage-plugin-and-wp-4-4/ is the blog post that helped me fix my problem.

Hopefully Microsoft will release an official plugin update soon.  UPDATE: The plugin has been updated and this fix is no longer required.

Further Reading

TSIP Packet Structure

Categories: Code
Comments Off on TSIP Packet Structure

TSIP stands for Trimble Standard Interface Protocol, and it is used in products from Trimble such as the Thunderbolt and differs from NMEA which is a lot simpler and only contains status data.

The TSIP protocol is based on the transmission of packets of information between the user equipment and the GPS receiver. Each packet includes an identification code that identifies the meaning and format of the data that follows. Each packet begins and ends with control characters.

Read more