Skip to content

Commit

Permalink
Allow sequence numbering information to be requested from driver and …
Browse files Browse the repository at this point in the history
…report it through both front-ends.
  • Loading branch information
woutgg committed Apr 18, 2016
1 parent 86a2723 commit fe30053
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/drivers/AbstractDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ int32_t AbstractDriver::getMaxBufferSize() const {
return gcodeBuffer_.getMaxBufferSize();
}

/*
* Get metadata from the GCode buffer.
*/
const GCodeBuffer::MetaData* AbstractDriver::getMetaData() const {
return gcodeBuffer_.getMetaData();
}

AbstractDriver::STATE AbstractDriver::getState() const {
return state_;
}
Expand Down
1 change: 1 addition & 0 deletions src/drivers/AbstractDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class AbstractDriver {
virtual int32_t getTotalLines() const;
virtual int32_t getBufferSize() const;
virtual int32_t getMaxBufferSize() const;
virtual const GCodeBuffer::MetaData* getMetaData() const;

STATE getState() const;
static const std::string &getStateString(STATE state);
Expand Down
14 changes: 9 additions & 5 deletions src/frontends/cmdline/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ static int act_sendGcode(const char *gcode) {
static int act_printProgress() {
int32_t currentLine = INT32_MIN, bufferedLines = INT32_MIN, totalLines = INT32_MIN;
int32_t bufferSize = INT32_MIN, maxBufferSize = INT32_MIN;
int32_t sequenceNumber = INT32_MIN, sequenceTotal = INT32_MIN;

if (comm_getProgress(&currentLine, &bufferedLines, &totalLines, &bufferSize, &maxBufferSize) < 0) {
if (comm_getProgress(&currentLine, &bufferedLines, &totalLines,
&bufferSize, &maxBufferSize, &sequenceNumber, &sequenceTotal) < 0) {
printError(json_output, "could not get printing progress (%s)", comm_getError());
return 1;
}
Expand All @@ -230,11 +232,13 @@ static int act_printProgress() {

if (totalLines != 0) printf(" (%.1f%%)", (float)currentLine / totalLines * 100);

printf(", at capacity %d of %d bytes max (%.1f%%)\n",
bufferSize, maxBufferSize, (float)bufferSize / maxBufferSize * 100);
printf(", at capacity %d of %d bytes max (%.1f%%); sequence number/total: %d/%d\n",
bufferSize, maxBufferSize, (float)bufferSize / maxBufferSize * 100,
sequenceNumber, sequenceTotal);
} else {
printJsonOk("\"progress\": {\"current\": %d, \"total\": %d, \"buffered\": %d, \"buffer_size\": %d, \"max_buffer_size\": %d}",
currentLine, totalLines, bufferedLines, bufferSize, maxBufferSize);
printJsonOk("\"progress\": {\"current\": %d, \"total\": %d, \"buffered\": %d,"
" \"buffer_size\": %d, \"max_buffer_size\": %d, \"sequence_number\": %d, \"sequence_total\": %d}",
currentLine, totalLines, bufferedLines, bufferSize, maxBufferSize, sequenceNumber, sequenceTotal);
}

return 0;
Expand Down
8 changes: 6 additions & 2 deletions src/frontends/communicator.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,21 +520,25 @@ int comm_heatup(int temperature) {
return rv;
}

int comm_getProgress(int32_t *currentLine, int32_t *bufferedLines, int32_t *totalLines, int32_t *bufferSize, int32_t *maxBufferSize) {
int comm_getProgress(int32_t *currentLine, int32_t *bufferedLines, int32_t *totalLines,
int32_t *bufferSize, int32_t *maxBufferSize,
int32_t *seqNumber, int32_t *seqTotal) {
clearError();

int scmdlen, rcmdlen;
char *scmd = ipc_construct_cmd(&scmdlen, IPC_CMDQ_GET_PROGRESS, 0);
char *rcmd = sendAndReceiveData(scmd, scmdlen, &rcmdlen);

int rv = 0;
int result = handleBasicResponse(scmd, scmdlen, rcmd, rcmdlen, 5);
int result = handleBasicResponse(scmd, scmdlen, rcmd, rcmdlen, 7);
if (result >= 0) {
rv = ipc_cmd_get_long_arg(rcmd, rcmdlen, 0, currentLine);
if (rv > -1) rv = ipc_cmd_get_long_arg(rcmd, rcmdlen, 1, bufferedLines);
if (rv > -1) rv = ipc_cmd_get_long_arg(rcmd, rcmdlen, 2, totalLines);
if (rv > -1) rv = ipc_cmd_get_long_arg(rcmd, rcmdlen, 3, bufferSize);
if (rv > -1) rv = ipc_cmd_get_long_arg(rcmd, rcmdlen, 4, maxBufferSize);
if (rv > -1) rv = ipc_cmd_get_long_arg(rcmd, rcmdlen, 5, seqNumber);
if (rv > -1) rv = ipc_cmd_get_long_arg(rcmd, rcmdlen, 6, seqTotal);
} else {
rv = result;
}
Expand Down
4 changes: 3 additions & 1 deletion src/frontends/communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ int comm_sendGCodeData(const char *gcode, int32_t total_lines, ipc_gcode_metadat

int comm_getTemperature(int16_t *temperature, IPC_TEMPERATURE_PARAMETER which);
int comm_heatup(int temperature);
int comm_getProgress(int32_t *currentLine, int32_t *bufferedLines, int32_t *numLines, int32_t *bufferSize, int32_t *maxBufferSize);
int comm_getProgress(int32_t *currentLine, int32_t *bufferedLines, int32_t *numLines,
int32_t *bufferSize, int32_t *maxBufferSize,
int32_t *seqNumber, int32_t *seqTotal);
int comm_getState(char **state);

#endif /* COMMUNICATOR_H_SEEN */
14 changes: 10 additions & 4 deletions src/frontends/lua/fe_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,16 @@ static int l_heatup(lua_State *L) {
return initStackWithReturnStatus(L, rv);
}

//returns currentLine+bufferedLines+totalLines+bufferSize+maxBufferSize or nil+errmsg
//returns currentLine+bufferedLines+totalLines+bufferSize+maxBufferSize+sequenceNumber+sequenceTotal
//or nil+errmsg
static int l_getProgress(lua_State *L) {
if (initContext(L) != 0) return 2; //nil+msg already on stack

int32_t currentLine, bufferedLines, totalLines, bufferSize, maxBufferSize;
int rv = comm_getProgress(&currentLine, &bufferedLines, &totalLines, &bufferSize, &maxBufferSize);
int32_t currentLine, bufferedLines, totalLines;
int32_t bufferSize, maxBufferSize;
int32_t sequenceNumber, sequenceTotal;
int rv = comm_getProgress(&currentLine, &bufferedLines, &totalLines,
&bufferSize, &maxBufferSize, &sequenceNumber, &sequenceTotal);
comm_closeSocket();

//to the south is another hack
Expand All @@ -380,7 +384,9 @@ static int l_getProgress(lua_State *L) {
lua_pushnumber(L, totalLines);
lua_pushnumber(L, bufferSize);
lua_pushnumber(L, maxBufferSize);
return 5;
lua_pushnumber(L, sequenceNumber);
lua_pushnumber(L, sequenceTotal);
return 7;
} else {
return numElems;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ipc_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ipc_cmd_name_s IPC_COMMANDS[] = {
{ IPC_CMDQ_GCODE_STARTPRINT, "gcodeStartPrint", "", "" },
{ IPC_CMDQ_GCODE_STOPPRINT, "gcodeStopPrint", "x", "" }, //NOTE: accepts end g-code (ignored if 0 length)
{ IPC_CMDQ_HEATUP, "heatup", "w", "" }, //NOTE: accepts heatup target temperature
{ IPC_CMDQ_GET_PROGRESS, "getProgress", "", "WWWWW" }, //NOTE: returns currentLine, bufferedLines, totalLines, bufferSize and maxBufferSize
{ IPC_CMDQ_GET_PROGRESS, "getProgress", "", "WWWWWWW" }, //NOTE: returns currentLine, bufferedLines, totalLines, bufferSize, maxBufferSize, seqNumber and seqTotal
{ IPC_CMDQ_GET_STATE, "getState", "", "x" },

/* response commands send by server */
Expand Down
6 changes: 4 additions & 2 deletions src/server/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,12 @@ void CommandHandler::hnd_getProgress(Client& client, const char* buf, int buflen
int32_t totalLines = driver->getTotalLines();
int32_t bufferSize = driver->getBufferSize();
int32_t maxBufferSize = driver->getMaxBufferSize();
const GCodeBuffer::MetaData *md = driver->getMetaData();

int cmdlen;
char* cmd = ipc_construct_cmd(&cmdlen, IPC_CMDR_OK, "WWWWW",
currentLine, bufferedLines, totalLines, bufferSize, maxBufferSize);
char* cmd = ipc_construct_cmd(&cmdlen, IPC_CMDR_OK, "WWWWWWW",
currentLine, bufferedLines, totalLines, bufferSize, maxBufferSize,
md->seqNumber, md->seqTotal);
client.sendData(cmd, cmdlen);
free(cmd);
}
Expand Down

0 comments on commit fe30053

Please sign in to comment.