fix a bug in ini write
This commit is contained in:
+14
-1
@@ -3,6 +3,8 @@
|
||||
//
|
||||
|
||||
#define GEX_H // to allow including other headers
|
||||
|
||||
#include <utils/payload_builder.h>
|
||||
#include "gex_settings.h"
|
||||
#include "gex_defines.h"
|
||||
#include "gex_internal.h"
|
||||
@@ -18,15 +20,26 @@ uint32_t GEX_IniRead(GexClient *gex, char *buffer, uint32_t maxlen)
|
||||
|
||||
uint32_t actuallyRead = GEX_BulkRead(GEX_SysUnit(gex), &br);
|
||||
|
||||
if (actuallyRead == maxlen) {
|
||||
actuallyRead--; // lose last char in favor of terminator
|
||||
}
|
||||
|
||||
buffer[actuallyRead] = 0; // terminate
|
||||
return actuallyRead;
|
||||
}
|
||||
|
||||
bool GEX_IniWrite(GexClient *gex, const char *buffer)
|
||||
{
|
||||
uint8_t buf[8];
|
||||
PayloadBuilder pb = pb_start(buf, 8, NULL);
|
||||
pb_u32(&pb, (uint32_t) strlen(buffer));
|
||||
|
||||
GexBulk bw = (GexBulk){
|
||||
.buffer = (uint8_t *) buffer,
|
||||
.len = (uint32_t) strlen(buffer),
|
||||
.req_cmd = MSG_INI_WRITE
|
||||
.req_cmd = MSG_INI_WRITE,
|
||||
.req_data = buf,
|
||||
.req_len = (uint32_t) pb_length(&pb),
|
||||
};
|
||||
|
||||
return GEX_BulkWrite(GEX_SysUnit(gex), &bw);
|
||||
|
||||
@@ -27,12 +27,18 @@ int main(void)
|
||||
gex = GEX_Init("/dev/ttyACM0", 200);
|
||||
if (!gex) exit(1);
|
||||
|
||||
#if 0
|
||||
// INI read example
|
||||
// char buffer[2000];
|
||||
// uint32_t len = GEX_IniRead(gex, buffer, 2000);
|
||||
// printf("%.*s", len, buffer);
|
||||
char buffer[2000];
|
||||
uint32_t len = GEX_IniRead(gex, buffer, 2000);
|
||||
printf("%s", buffer);
|
||||
|
||||
// DO example
|
||||
GEX_IniWrite(gex, buffer);
|
||||
printf("Written.\r\n");
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// DO example - there's a 10-LED bargraph connected to this unit
|
||||
GexUnit *bg = GEX_GetUnit(gex, "bargraph", "DO");
|
||||
|
||||
struct DO_Set {
|
||||
@@ -40,6 +46,8 @@ int main(void)
|
||||
} __attribute__((packed));
|
||||
|
||||
struct DO_Set cmd_set;
|
||||
|
||||
// animation on the bargraph
|
||||
for (int i = 0; i < 100; i++) {
|
||||
int n = i%20;
|
||||
if(n>=10) n=10-(n-10);
|
||||
@@ -51,6 +59,7 @@ int main(void)
|
||||
// all dark
|
||||
cmd_set.bits = 0x3FF;
|
||||
GEX_Send(bg, 0x00, (uint8_t *)&cmd_set, sizeof(cmd_set));
|
||||
#endif
|
||||
|
||||
GEX_DeInit(gex);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user