|
|
@ -2,38 +2,56 @@ |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <signal.h> |
|
|
|
#include <signal.h> |
|
|
|
#include <assert.h> |
|
|
|
#include <assert.h> |
|
|
|
|
|
|
|
#include <utils/payload_builder.h> |
|
|
|
#include <unistd.h> |
|
|
|
#include <unistd.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "gex.h" |
|
|
|
#include "gex.h" |
|
|
|
#include "utils/hexdump.h" |
|
|
|
//#include "utils/hexdump.h"
|
|
|
|
#include "utils/payload_builder.h" |
|
|
|
//#include "utils/payload_builder.h"
|
|
|
|
|
|
|
|
//#include "utils/payload_parser.h"
|
|
|
|
|
|
|
|
|
|
|
|
static GexClient *gex; |
|
|
|
// some examples of usage, for more details see the header files
|
|
|
|
|
|
|
|
|
|
|
|
/** ^C handler to close it gracefully */ |
|
|
|
static GexClient *gex; |
|
|
|
static void sigintHandler(int sig) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
(void)sig; |
|
|
|
|
|
|
|
if (gex != NULL) GEX_DeInit(gex); |
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Main function - test the library */ |
|
|
|
/** Main function - test the library */ |
|
|
|
int main(void) |
|
|
|
int main(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Bind ^C handler for safe shutdown - need to release the port
|
|
|
|
gex = GEX_Init("/dev/ttyACM0", 200); |
|
|
|
signal(SIGINT, sigintHandler); |
|
|
|
if (!gex) exit(1); |
|
|
|
|
|
|
|
|
|
|
|
gex = GEX_Init("/dev/ttyACM0", 200); |
|
|
|
GexUnit *bus = GEX_GetUnit(gex, "i2c", "I2C"); |
|
|
|
if (!gex) exit(1); |
|
|
|
assert(NULL != bus); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sleep(2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
GexUnit *adc = GEX_GetUnit(gex, "adc", "ADC"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GexMsg msg = GEX_Query(adc, 10, NULL, 0); |
|
|
|
|
|
|
|
hexDump("Resp1", msg.payload, msg.len); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "Channels: "); |
|
|
|
|
|
|
|
for(uint32_t i = 0; i < msg.len; i++) fprintf(stderr, "%d, ", msg.payload[i]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msg = GEX_Query(adc, 11, NULL, 0); |
|
|
|
|
|
|
|
hexDump("Resp2", msg.payload, msg.len); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PayloadParser pp = pp_start(msg.payload, msg.len, NULL); |
|
|
|
|
|
|
|
uint32_t fconf = pp_u32(&pp); |
|
|
|
|
|
|
|
float freal = pp_float(&pp); |
|
|
|
|
|
|
|
fprintf(stderr, "Freq configured %d Hz, real freq %f Hz", fconf, freal); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
#if 0 |
|
|
|
// INI read example
|
|
|
|
// INI read example
|
|
|
|
char buffer[2000]; |
|
|
|
char buffer[2000]; |
|
|
|
uint32_t len = GEX_IniRead(gex, buffer, 2000); |
|
|
|
uint32_t len = GEX_IniRead(gex, buffer, 2000); |
|
|
|
printf("%s", buffer); |
|
|
|
printf("%s", buffer); |
|
|
|
|
|
|
|
|
|
|
|
GEX_IniWrite(gex, buffer); |
|
|
|
GEX_IniWrite(gex, buffer); |
|
|
|
printf("Written.\r\n"); |
|
|
|
printf("Written.\r\n"); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
@ -61,6 +79,6 @@ int main(void) |
|
|
|
GEX_Send(bg, 0x00, (uint8_t *)&cmd_set, sizeof(cmd_set)); |
|
|
|
GEX_Send(bg, 0x00, (uint8_t *)&cmd_set, sizeof(cmd_set)); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
GEX_DeInit(gex); |
|
|
|
GEX_DeInit(gex); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|