Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

newfierich

Member Since 09 May 2011
Offline Last Active Aug 12 2011 05:32 PM
-----

Posts I've Made

In Topic: NMEA checksum Calculator

12 August 2011 - 04:14 PM

Hello all. Wondering if anyone was successful in creating checking checksums in NMEA messages? Problem I am having is that .net micro does not have a Convert class... Has anyone on the forum been successfull in calculating NMEA checksums?

http://www.codepedia... NMEA Checksums


This is my first kick at writing a function to check the checksums of a NMEA message.. Its a bit long because as far as I know, there are no methods in .NET MICRO to convert to hex strings from an integer. if there are any ways to make this code more efficient please let me know. It should also be noted that there is little to no error handling


class NMEAparser
    {

        public bool varifyCheckSum(String Message)
        {
            
            int index = 0;
            string checksum;
            index = Message.IndexOf('*', 1);
            if (index == -1)
                return false;
           
            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(Message.Substring(1, index - 1));
            
            checksum = Message.Substring(index + 1, 2);
                       
            int decimalValue = 0;
            foreach (byte b in byteArray)
            {

                if ( decimalValue == 0)
                {
                    decimalValue = int.Parse(b.ToString());

                }
                else
                {
                    decimalValue = decimalValue ^ int.Parse(b.ToString());
                }

                
            }
            

            String calcCheckSum = intToHexString(decimalValue);

            
            
            return calcCheckSum.Substring(calcCheckSum.Length - 2) == checksum;
            
           
            
        }
         public string intToHexString(int value)
         {
             string hexString = "";
             if (value == 0)
             {
                 hexString = "0";
             }
             else
             {
                switch (value%16)
                {
                    case 0:
                        hexString = intToHexString(value / 16) + "0";
                        break;
                    case 1:
                        hexString = intToHexString(value / 16) + "1";
                        break;
                    case 2:
                        hexString = intToHexString(value/16) + "2";
                        break;
                    case 3:
                        hexString = intToHexString(value / 16) + "3";
                        break;
                    case 4:
                        hexString = intToHexString(value / 16) + "4";
                        break;
                    case 5:
                        hexString = intToHexString(value / 16) + "5";
                        break;
                    case 6:
                        hexString = intToHexString(value / 16) + "6";
                        break;
                    case 7:
                        hexString = intToHexString(value / 16) + "7";
                        break;
                    case 8:
                        hexString = intToHexString(value / 16) + "8";
                        break;
                    case 9:
                        hexString = intToHexString(value / 16) + "9";
                        break;
                    case 10:
                        hexString = intToHexString(value / 16) + "A";
                        break;
                    case 11:
                        hexString = intToHexString(value / 16) + "B";
                        break;
                    case 12:
                        hexString = intToHexString(value / 16) + "C";
                        break;
                    case 13:
                        hexString = intToHexString(value / 16) + "D";
                        break;
                    case 14:
                        hexString = intToHexString(value / 16) + "E";
                        break;
                    case 15:
                        hexString = intToHexString(value / 16) + "F";
                       break;

                }


            }

             return hexString;
        }
    }




In Topic: Connecting Netdruino to MySQL db

17 June 2011 - 01:15 PM

There isn't really a good way to do this directly, as any full MySQL driver would probably take up most of the RAM and flash, however you could write a sort of REST API and tie the Netduino to that. Keep in mind, I would consider such a system to be highly insecure, due to the risk of someone unauthorized getting in to said REST API and either dumping or dropping the tables.

A better option would be to expose any functionality you need through such a REST API and then secure upon that. This means that full MySQL queries can not be injected.


Thanks, Like you said I guess I will have to come up with something on the server side. I didn't know if there were any light weight libs, but I guess not.

In Topic: UTF8 Encoding

14 June 2011 - 07:12 PM

Hi newfierich,

Is there any chance you could print out the values of each byte in the array--and then post those here? We've seen ocassional UTF-8 decoding exceptions--but it would be good to analyze exactly what's going on...and see if there's another way that .NET MF could handle the error condition.

Chris


Hello Chris,

below is a code snip I used to receive the GPS messages and printed them both as a byte array and string for debugging purposes. I ran the Netduino and GPS while plugging and unplugging the GPS from the Netduinos UART until the Netduino hanged for three trials. I attached the outputs to this post. The Netduino seems to run fine when the debugger is not running via c# express.



namespace NetduinoPlusAHRSTest
{
    public class Program
    {
        public static void Main()
        {

            SerialPort Port1 = new SerialPort("COM1", 57600, Parity.None, 8, StopBits.One);
            Port1.DataReceived += new SerialDataReceivedEventHandler(Port1_DataReceived);
            Port1.Open();
        }
        
        static void Port1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                SerialPort Port1 = (SerialPort)sender;
                int i = 0;

                int GPStoRead = Port1.BytesToRead;
                byte[] GPSbuffer = new byte[GPStoRead];
                Port1.Read(GPSbuffer, 0, GPSbuffer.Length);
                String byteString = "[" + GPSbuffer[0];
                for (i = 1; i < GPSbuffer.Length; i++)
                {
                    byteString += ", " + (int)GPSbuffer[i];
                }


                byteString += "]";
                Debug.Print(byteString);
                String GPSBufferString = new String(System.Text.UTF8Encoding.UTF8.GetChars(GPSbuffer));
                Debug.Print(GPSBufferString);
            }
            catch (Exception error)
            {
                Debug.Print("//\n//\n//\n ERROR FOUND: " + error.StackTrace + "\n//\n//\n//" );

            }
       }
}




In Topic: UTF8 Encoding

14 June 2011 - 05:44 PM

I have the attached the GPS datasheet and pasted a few sample messages below. They are all ASCII Characters, I should note that the issue only arises when I plug or unplug the GPS from the UART. $GPGGA,053740.000,2503.6319,N,12136.0099,E,1,08,1.1,63.8,M,15.2,M,,0000*64 $GPGLL,2503.6319,N,12136.0099,E,053740.000,A,A*52 $GPGSA,A,3,24,07,17,11,28,08,20,04,,,,,2.0,1.1,1.7*35 $GPGSV,3,1,12,28,81,285,42,24,67,302,46,31,54,354,,20,51,077,46*73 $GPGSV,3,2,12,17,41,328,45,07,32,315,45,04,31,250,40,11,25,046,41*75 $GPGSV,3,3,12,08,22,214,38,27,08,190,16,19,05,092,33,23,04,127,*7B $GPRMC,053740.000,A,2503.6319,N,12136.0099,E,2.69,79.65,100106,,,A*53 $GPVTG,79.65,T,,M,2.69,N,5.0,K,A*38

In Topic: UTF8 Encoding

13 June 2011 - 10:54 PM

Are you receiving NMEA sentences (that can only contain ASCII characters, start with '$' and end with CR LF)?

@Chris Walker @CW2 They are in fact NMEA messages that only contain ASCII characters. I will post some sample messages tommorow. (I don't have the gps/Netduino handy)

Thanks for the reply's

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.