X-Git-Url: https://git.ao2.it/libam7xxx.git/blobdiff_plain/c4cda76c6f02bc04d31761a54470434d8e1d60b8..5e7d217e7f1d40fbfb6bc6375421a21bd5572788:/src/serialize.c diff --git a/src/serialize.c b/src/serialize.c new file mode 100644 index 0000000..be300ea --- /dev/null +++ b/src/serialize.c @@ -0,0 +1,61 @@ +/* am7xxx - communication with AM7xxx based USB Pico Projectors and DPFs + * + * Copyright (C) 2012 Antonio Ospite + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "serialize.h" + +uint8_t get_8(uint8_t **bufferp) +{ + uint8_t tmp; + + tmp = *bufferp[0]; + *bufferp += 1; + + return tmp; +} + +uint32_t get_le32(uint8_t **bufferp) +{ + uint32_t tmp; + + memcpy(&tmp, *bufferp, sizeof (tmp)); + *bufferp += sizeof (tmp); + + return le32toh(tmp); +} + +uint8_t *put_8(uint8_t value, uint8_t **bufferp) +{ + *bufferp[0] = value; + *bufferp += 1; + + return *bufferp; +} + +uint8_t *put_le32(uint32_t value, uint8_t **bufferp) +{ + uint32_t tmp; + + tmp = htole32(value); + memcpy(*bufferp, &tmp, sizeof (tmp)); + *bufferp += sizeof (tmp); + + return *bufferp; +}