How to implement simple API message format using STK600

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
Currently i am working on a project with the aim to implement simple API message format on SKT600 with ATmega2560. Below are the API message format detail. But I am looking for a format that I can modify it according to my own requirement, any link or idea or suggestions are appreciated.

The API message format is as follows:

STX | Message Header | Message Type | Message ID | Data Size | Data | CRC.
An example of API Message - API_MAX_UART_SPEED that reads the maximum UART Speed of your board is:

| 0xF1 | 0x40 | 0x05 | 0x80 | 0x00 | 0x1A | 0x34 |

Meaning: 0xF1 - Start Character

0x40 - API Message Request

0x50 - API_MAX_UART_SPEED

0x80 - Message ID

0x00 - Data Size

0x8F61 - CRC

And the response (sent from your board ):

| 0xF1 | 0x48 | 0x05 | 0x80 | 0x01 | 0x03 | 0x86 | 0x04 |

Meaning: 0xF1 - Start Character

0x48 - API Message Response

0x50 - API_MAX_UART_SPEED

0x80 - Message ID

0x01 - Data Size

0x03 - Data (Baud rate : 38400 )

0x8604 - CRC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The API is entirely up to you. You decide what each value means.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is API the correct acronym? It's not really an Application Programming Interface is it? I'd just call it a "protocol".

Like Steve I agree it's completely up to you how it operates. The only important thing is that both ends agree.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Agreed API is the wrong term. What ever protocol is decided upon could be accessed ( in different languages ) using different APIs.

That being said, modifications to the protocol should be fairly easy to make once you have identified what works about the current version and what does not. Once you have figured out the changes, simply write a new specification. Implementing it is a different matter again. Many ways to do it, though for a simple protocol like that a hand-written parser should be easy enough to write.

Martin Jay McKee

As with most things in engineering, the answer is an unabashed, "It depends."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes API is Application Programming Interface; a protocol. The main idea of API implementation is to make an agreement between two sensor boards in order to make them able to communicate. A kind of request and response messages.
I know it depends on me to set and define API message format according to my project requirement.
Now I need an example code which gives me an idea to write my own API message format.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No you are misunderstanding / misusing the term API. It's the definition of a function interface implemented by a library. Nothing to do with the format of bytes/packets/messages passed over a UART interface.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did not get your point.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

API defines a set of functions that access or control the operation of a block of software.

The kind of message that you outline is in a broad general group that is colloquially called "a packet" (eg, "envelope"), There are framing characters that define the beginning and end of the packet. Plus, defined sections of the message with specific purposes.

YOU define the meaning of each character in the message. It is up to you to specify the rules for each character in the packet. You can use STX for the start, others might use 0xFe or some other unique character. Some would end with the same character. You can use any character you want. It is nice to use something that will never appear within the message or learn how to "escape" characters.

Designing a protocol (set of rules) for the packet is fairly easy. What is far more challenging is to come up with an algorithm to parse messages and generate the actions or responses.

There is very little sample code for such things. People just do it.

By the way, use of an STK600 is quite irrelevant for such a thing. A protocol like this can be and should be platform independent.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I did not get your point.

not to labour the point but what do you think "API" stands for/means?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe OP is being confused by
http://en.wikipedia.org/wiki/App...

"An application programming interface (API) is a protocol intended to be used as an interface by software components to communicate with each other"

...whereas OP is trying to create a protocol between hardware components?