I began work on this mostly for myself and beck, given our recent work on a lot of networked applications (TI-Trek, VPM/BPM, etc), but decided to release it for others. So far, only the outbound has been tested, and only on cemu; I will be testing inbound either later today or tomorrow.

This library contains a number of functions to help with forming and sending data in a standardized packet format so that end users don't have to worry about cross-compatibility. Right now, the lib maintains compatibility with the serial hardware as well as CEmu's pipe mode.

Here's a short overview of the API:

bool pl_InitSubsystem(uint8_t subsys, uint8_t *buf, size_t buf_size, size_t ms_delay);
This initializes the given subsystem (current options are serial device or CEmu pipes). Passes the given buffer of buffer size. The provided delay in milliseconds specifies a timeout after which to return an error. If other libs like TCP/IP are provided, they can be added as subsystems here as well.

size_t pl_JoinPacketSegments(uint8_t pid, ps_t *ps, uint8_t arr_len, uint8_t *packet);
This takes a packet id, an array of given length of pointer/len pairs, and a pointer to a buffer to write the packet to. This is a helper function.

size_t pl_SendPacket(uint8_t *data, size_t len);
This sends the given packet over the initialized subsystem. Depending on the size of the buffer, the function may not actually send all of `len`. It will only ever send the lesser of the length, or 3 less than half the buffer size initialized and that number is returned, making it possible to loop calls to send a full packet in frames. Each packet is prefixed with a header consisting of a 3-byte size word.

Code:

#example of how to loop sendpacket for a multi-frame packet
for(size_t l = 0; l < packet_len;)
      l += pl_SendPacket(&addr[l], packet_len - l);


void pl_SetReadTimeout(size_t ms_delay);
Alters the timeout for the ReadPacket function (below). By default, the timeout is 0 for a non-blocking read. By specifying a non-zero timeout value, in milliseconds, it will become a blocking read that waits that time before returning an error.

size_t pl_ReadPacket(uint8_t *dest, size_t read_size);
Attempts to read the given size from the subsystem to the given pointed buffer. Returns the size read on success, or 0 on fail. Fails if the given size is not available.

Here's the current build with sending only tested: https://github.com/acagliano/packetlib
I'm a bit confused about what ti-trek is. Can you explain it to me?
arusher999 wrote:
I'm a bit confused about what ti-trek is. Can you explain it to me?
TI-Trek is a multiplayer space combat game based on Star Trek. It uses the serial/usb devices on the calculator as well as a serial to TCP bridge on the computer to communicate with a server me and beck have written and I host. At present it doesn't do much more than login/registration, and chatting, but we're working how to store map data at present so we can work out how to render stuff.
ACagliano wrote:
arusher999 wrote:
I'm a bit confused about what ti-trek is. Can you explain it to me?
TI-Trek is a multiplayer space combat game based on Star Trek. It uses the serial/usb devices on the calculator as well as a serial to TCP bridge on the computer to communicate with a server me and beck have written and I host. At present it doesn't do much more than login/registration, and chatting, but we're working how to store map data at present so we can work out how to render stuff.



Ah, es muy interesante. So you have to be connected to a pc to play, right? This sounds super cool!
arusher999 wrote:
Ah, es muy interesante. So you have to be connected to a pc to play, right? This sounds super cool!

For now, yes.
This is pretty neat- I particularly like that you included some fairly simple examples to demonstrate how to use the library.

You might want to add .DS_Store to a .gitignore file in the base of your project to ignore pesky MacOS files.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement