add hacky support for raw bulk, to test ini reading

master
Ondřej Hruška 6 years ago
parent 0903b82ac8
commit 414f8859eb
  1. 2
      CMakeLists.txt
  2. 15
      gex/gex_bulk.c
  3. 27
      gex/gex_client.c
  4. 2
      gex/gex_client.h
  5. 4
      gex/gex_internal.h
  6. 4
      gex/gex_message_types.h
  7. 2
      gex/gex_unit.c
  8. 47
      main.c

@ -3,7 +3,7 @@ project(gex_client)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -Wno-unused")
set(SOURCE_FILES
main.c

@ -16,7 +16,7 @@
/**
* Bulk read from a unit, synchronous
*
* @param unit - the unit to target
* @param unit - the unit to target. If system_unit is used, a raw query will be sent (no unit preamble and cmd is TYPE)
* @param bulk - the bulk transport info struct
* @return actual number of bytes received.
*/
@ -24,7 +24,10 @@ uint32_t GEX_BulkRead(GexUnit *unit, GexBulk *bulk)
{
// fprintf(stderr, "Ask to read:\n");
// We ask for the transfer. This is unit specific and can contain information that determines the transferred data
GexMsg resp0 = GEX_Query(unit, bulk->req_cmd, bulk->req_data, bulk->req_len);
// if unit callsign is 0, it's the system unit and we'll use raw query without the unit prefix
GexMsg resp0 = GEX_QueryEx(unit, bulk->req_cmd, bulk->req_data, bulk->req_len, 0, false, unit->callsign == 0);
// GEX_Query(unit, bulk->req_cmd, bulk->req_data, bulk->req_len);
if (resp0.type == MSG_ERROR) {
fprintf(stderr, "Bulk read rejected! %.*s\n", resp0.len, (char*)resp0.payload);
@ -83,7 +86,7 @@ uint32_t GEX_BulkRead(GexUnit *unit, GexBulk *bulk)
/**
* Bulk write to a unit, synchronous
*
* @param unit - the unit to target
* @param unit - the unit to target. If system_unit is used, raw query with cmd as TYPE will be sent.
* @param bulk - the bulk transport info struct
* @return true on success
*/
@ -92,7 +95,11 @@ bool GEX_BulkWrite(GexUnit *unit, GexBulk *bulk)
// fprintf(stderr, "Asking for bulk write...\n");
// We ask for the transfer. This is unit specific
GexMsg resp0 = GEX_Query(unit, bulk->req_cmd, bulk->req_data, bulk->req_len);
// GexMsg resp0 = GEX_Query(unit, bulk->req_cmd, bulk->req_data, bulk->req_len);
GexMsg resp0 = GEX_QueryEx(unit,
bulk->req_cmd, bulk->req_data, bulk->req_len,
0, false,
unit->callsign == 0);
if (resp0.type == MSG_ERROR) {
fprintf(stderr, "Bulk write rejected! %.*s\n", resp0.len, (char*)resp0.payload);

@ -19,6 +19,11 @@
#include "gex_helpers.h"
#include "utils/payload_parser.h"
GexUnit *GEX_SystemUnit(GexClient *gex)
{
return &gex->system_unit;
}
/** Callback for ping */
static TF_Result connectivity_check_lst(TinyFrame *tf, TF_Msg *msg)
{
@ -40,21 +45,11 @@ static TF_Result unit_report_lst(TinyFrame *tf, TF_Msg *msg)
struct gex_unit *lu = gex_find_unit_by_callsign(gex, callsign);
// NULL object pattern - we use a fake unit if no unit matched.
GexUnit fbu = {
.callsign = 0,
.report_handler = NULL,
.type = "NONE",
.name = "FALLBACK",
.gex = gex, // gex must be available here - this is why we can't have this static or const.
.next = NULL,
};
GexMsg gexMsg = {
.payload = (uint8_t *) (msg->data + 2),
.len = (uint32_t) (msg->len - 2),
.type = rpt_type,
.unit = (lu == NULL) ? &fbu : lu,
.unit = (lu == NULL) ? &gex->system_unit : lu,
};
if (lu && lu->report_handler) {
@ -139,6 +134,16 @@ GexClient *GEX_Init(const char *device, uint32_t timeout_ms)
GexClient *gex = calloc(1, sizeof(GexClient));
assert(gex != NULL);
// Init the dummy system unit
gex->system_unit = (GexUnit){
.name = "SYSTEM",
.type = "SYSTEM",
.callsign = 0,
.gex = gex,
.next = NULL,
.report_handler = NULL
};
// --- Open the device ---
gex->acm_device = device;
gex->ser_timeout = timeout_ms;

@ -28,6 +28,8 @@ void GEX_OnReport(GexClient *gex, GexUnit *unit, GexEventListener lst);
TinyFrame *GEX_GetTF(GexClient *gex);
GexUnit *GEX_SystemUnit(GexClient *gex);
/**
* Get a unit, or NULL
*

@ -30,7 +30,9 @@ struct gex_client {
GexEventListener fallback_report_handler;
struct gex_unit *ulu_head; //!< Units look-up linked list
GexUnit *ulu_head; //!< Units look-up linked list
GexUnit system_unit; //!< System unit, used as dummy for raw queries
};
#endif //GEX_CLIENT_GEX_CLIENT_INTERNAL_H

@ -31,7 +31,9 @@ enum TF_Types_ {
MSG_UNIT_REPORT = 0x11, //!< Spontaneous report from a unit
// System messages
MSG_LIST_UNITS = 0x20, //!< Get all unit call-signs and names
MSG_LIST_UNITS = 0x20, //!< Get all unit call-signs and names
MSG_INI_READ = 0x21, //!< Read the ini file via bulk
MSG_INI_WRITE = 0x22, //!< Write the ini file via bulk
};
#endif //GEX_CLIENT_GEX_MESSAGE_TYPES_H

@ -18,7 +18,7 @@
* Low level query
*
* @param unit - GEX unit to address. The unit is available in userdata1 of the response message, if any
* @param cmd - command byte
* @param cmd - command byte, or TYPE if raw query is used
* @param payload - payload buffer
* @param len - payload length
* @param lst - TF listener to handle the response, can be NULL

@ -42,7 +42,33 @@ const char *longtext = "A sharper perspective on this matter is particularly imp
"the system of domination, as if people did not participate in their own\r\n"
"submission. To reduce domination to a simple relation of doer and done-to\r\n"
"is to substitute moral outrage for analysis.\r\n"
"\t\t-- Jessica Benjamin, \"The Bonds of Love\"";
"\t\t-- Jessica Benjamin, \"The Bonds of Love\""
"A sharper perspective on this matter is particularly important to feminist\r\n"
"thought today, because a major tendency in feminism has constructed the\r\n"
"problem of domination as a drama of female vulnerability victimized by male\r\n"
"aggression. Even the more sophisticated feminist thinkers frequently shy\r\n"
"away from the analysis of submission, for fear that in admitting woman's\r\n"
"participation in the relationship of domination, the onus of responsibility\r\n"
"will appear to shift from men to women, and the moral victory from women to\r\n"
"men. More generally, this has been a weakness of radical politics: to\r\n"
"idealize the oppressed, as if their politics and culture were untouched by\r\n"
"the system of domination, as if people did not participate in their own\r\n"
"submission. To reduce domination to a simple relation of doer and done-to\r\n"
"is to substitute moral outrage for analysis.\r\n"
"\t\t-- Jessica Benjamin, \"The Bonds of Love\""
"A sharper perspective on this matter is particularly important to feminist\r\n"
"thought today, because a major tendency in feminism has constructed the\r\n"
"problem of domination as a drama of female vulnerability victimized by male\r\n"
"aggression. Even the more sophisticated feminist thinkers frequently shy\r\n"
"away from the analysis of submission, for fear that in admitting woman's\r\n"
"participation in the relationship of domination, the onus of responsibility\r\n"
"will appear to shift from men to women, and the moral victory from women to\r\n"
"men. More generally, this has been a weakness of radical politics: to\r\n"
"idealize the oppressed, as if their politics and culture were untouched by\r\n"
"the system of domination, as if people did not participate in their own\r\n"
"submission. To reduce domination to a simple relation of doer and done-to\r\n"
"is to substitute moral outrage for analysis.\r\n"
"\t\t-- Jessica Benjamin, \"The Bonds of Love\" \r\nEND OF TEXT";
int main(void)
{
@ -72,6 +98,21 @@ int main(void)
fprintf(stderr, "Cmd \"PING\" OK\n");
#endif
#if 1
// Read the communist manifesto via bulk transfer
uint8_t inifile[10000];
br = (GexBulk){
.buffer = inifile,
.capacity = 10000,
.req_cmd = MSG_INI_READ,
.req_data = NULL,
.req_len = 0,
};
uint32_t actuallyRead = GEX_BulkRead(GEX_SystemUnit(gex), &br);
fprintf(stderr, "Read %d bytes of INI:\n", actuallyRead);
fprintf(stderr, "%.*s", actuallyRead, inifile);
#endif
#if 0
// Test a echo command that returns back what was sent to it as useful payload
const char *s = "I am \r\nreturning this otherwise good typing paper to you because someone "
@ -85,7 +126,7 @@ int main(void)
#if 0
// Read the communist manifesto via bulk transfer
uint8_t buffr[10000];
br = {
br = (GexBulk){
.buffer = buffr,
.capacity = 10000,
.req_cmd = 2,
@ -97,7 +138,7 @@ int main(void)
fprintf(stderr, "%.*s", actuallyRead, buffr);
#endif
#if 1
#if 0
// Read the communist manifesto via bulk transfer
br = (GexBulk){
.buffer = (uint8_t *) longtext,

Loading…
Cancel
Save