Added functions to encode and decode the serial packets