-
Notifications
You must be signed in to change notification settings - Fork 17
Upload return len #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edvardxyz
wants to merge
5
commits into
master
Choose a base branch
from
upload_return_len
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5d9ca1f
vmem: return byte count even if not completed
edvardxyz 065035c
vmem: upload verbosity flag added, length is now input length pointer…
edvardxyz fd4dfab
return err on uncompleted upload
edvardxyz 3be70c4
err if addr is 64bit and version 1
edvardxyz 1a7219c
Redefine upload download api, introducing param_errs
edvardxyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
|
|
||
| #include <stdint.h> | ||
| #include <vmem/vmem.h> | ||
| #include <param/param_error.h> | ||
|
|
||
|
|
||
| #include "libparam.h" | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| #define PARAM_ERR_NONE 0 /**< No error */ | ||
| #define PARAM_ERR_NOMEM -400 /**< Not enough memory */ | ||
| #define PARAM_ERR_INVAL -401 /**< Invalid argument */ | ||
| #define PARAM_ERR_NOTSUP -402 /**< Operation not supported */ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,21 +5,31 @@ | |
| * Author: johan | ||
| */ | ||
|
|
||
| #include <stdint.h> | ||
| #include <stdio.h> | ||
| #include <csp/arch/csp_time.h> | ||
| #include <sys/types.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <vmem/vmem_client.h> | ||
| #include <param/param_error.h> | ||
| #include "csp/csp_error.h" | ||
|
|
||
| static int abort = 0; | ||
|
|
||
| void vmem_client_abort(void) { | ||
| abort = 1; | ||
| } | ||
|
|
||
| int vmem_download(int node, int timeout, uint64_t address, uint32_t length, char * dataout, int version, int use_rdp) | ||
| { | ||
| ssize_t vmem_download(uint16_t node, uint32_t timeout, uint64_t address, char * dataout, uint32_t length, int use_rdp, int version, int verbosity) { | ||
|
|
||
| if((address > UINT32_MAX) && version != 2){ | ||
| if(verbosity > 0){ | ||
| printf(" Error: Address out of range 64-bit addresses require version 2\n"); | ||
| } | ||
| return PARAM_ERR_INVAL; | ||
| } | ||
|
|
||
| uint32_t time_begin = csp_get_ms(); | ||
| abort = 0; | ||
|
|
||
|
|
@@ -29,12 +39,16 @@ int vmem_download(int node, int timeout, uint64_t address, uint32_t length, char | |
| opts |= CSP_O_RDP; | ||
| } | ||
| csp_conn_t * conn = csp_connect(CSP_PRIO_HIGH, node, VMEM_PORT_SERVER, timeout, opts); | ||
| if (conn == NULL) | ||
| return -1; | ||
| if (conn == NULL){ | ||
| if(verbosity > 0) { | ||
| printf(" Connection could not be established\n"); | ||
| } | ||
| return CSP_ERR_TIMEDOUT; | ||
| } | ||
|
|
||
| csp_packet_t * packet = csp_buffer_get(sizeof(vmem_request_t)); | ||
| if (packet == NULL) | ||
| return -1; | ||
| return CSP_ERR_NOMEM; | ||
|
|
||
| vmem_request_t * request = (void *) packet->data; | ||
| request->version = version; | ||
|
|
@@ -78,13 +92,15 @@ int vmem_download(int node, int timeout, uint64_t address, uint32_t length, char | |
| break; | ||
| } | ||
|
|
||
| if (dotcount % 32 == 0) | ||
| printf(" "); | ||
| printf("."); | ||
| fflush(stdout); | ||
| dotcount++; | ||
| if (dotcount % 32 == 0) | ||
| printf(" - %.0f K\n", (count / 1024.0)); | ||
| if(verbosity > 1) { | ||
| if (dotcount % 32 == 0) | ||
| printf(" "); | ||
| printf("."); | ||
| fflush(stdout); | ||
| dotcount++; | ||
| if (dotcount % 32 == 0) | ||
| printf(" - %.0f K\n", (count / 1024.0)); | ||
| } | ||
|
|
||
| /* Put data */ | ||
| memcpy((void *) ((intptr_t) dataout + count), packet->data, packet->length); | ||
|
|
@@ -95,33 +111,51 @@ int vmem_download(int node, int timeout, uint64_t address, uint32_t length, char | |
| csp_buffer_free(packet); | ||
| } | ||
|
|
||
| printf(" - %.0f K\n", (count / 1024.0)); | ||
| if(verbosity > 1) { | ||
| printf(" - %.0f K\n", (count / 1024.0)); | ||
| } | ||
|
|
||
| csp_close(conn); | ||
|
|
||
| uint32_t time_total = csp_get_ms() - time_begin; | ||
|
|
||
| printf(" Downloaded %u bytes in %.03f s at %u Bps\n", (unsigned int) count, time_total / 1000.0, (unsigned int) (count / ((float)time_total / 1000.0)) ); | ||
| if(verbosity > 0) { | ||
| printf(" Downloaded %u bytes in %.03f s at %u Bps\n", (unsigned int) count, time_total / 1000.0, (unsigned int) (count / ((float)time_total / 1000.0)) ); | ||
| } | ||
|
|
||
| return count; | ||
|
|
||
| } | ||
|
|
||
| int vmem_upload(int node, int timeout, uint64_t address, char * datain, uint32_t length, int version) { | ||
| ssize_t vmem_upload(uint16_t node, uint32_t timeout, uint64_t address, const char * datain, uint32_t length, int use_rdp, int version, int verbosity) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like for the |
||
|
|
||
| if((address > UINT32_MAX) && version != 2){ | ||
| if(verbosity > 0){ | ||
| printf(" Error: Address out of range 64-bit addresses require version 2\n"); | ||
| } | ||
| return PARAM_ERR_INVAL; | ||
| } | ||
|
|
||
| uint32_t time_begin = csp_get_ms(); | ||
| abort = 0; | ||
|
|
||
| /* Establish RDP connection */ | ||
| csp_conn_t * conn = csp_connect(CSP_PRIO_HIGH, node, VMEM_PORT_SERVER, timeout, CSP_O_RDP | CSP_O_CRC32); | ||
| uint32_t opts = CSP_O_CRC32; | ||
| if (use_rdp) { | ||
| opts |= CSP_O_RDP; | ||
| } | ||
| csp_conn_t * conn = csp_connect(CSP_PRIO_HIGH, node, VMEM_PORT_SERVER, timeout, opts); | ||
| if (conn == NULL) { | ||
| printf("Connection could not be established\n"); | ||
| return -1; | ||
| if(verbosity > 0) { | ||
| printf(" Connection could not be established\n"); | ||
| } | ||
| return CSP_ERR_TIMEDOUT; | ||
| } | ||
|
|
||
| csp_packet_t * packet = csp_buffer_get(sizeof(vmem_request_t)); | ||
| if (packet == NULL) | ||
| return -1; | ||
| csp_packet_t * packet = csp_buffer_get(0); | ||
| if (packet == NULL) { | ||
| return CSP_ERR_NOMEM; | ||
| } | ||
|
|
||
| vmem_request_t * request = (void *) packet->data; | ||
| request->version = version; | ||
|
|
@@ -144,20 +178,24 @@ int vmem_upload(int node, int timeout, uint64_t address, char * datain, uint32_t | |
| while((count < length) && csp_conn_is_active(conn)) { | ||
|
|
||
| if (abort) { | ||
| csp_buffer_free(packet); | ||
| break; | ||
| } | ||
|
|
||
| if (dotcount % 32 == 0) | ||
| printf(" "); | ||
| printf("."); | ||
| fflush(stdout); | ||
| dotcount++; | ||
| if (dotcount % 32 == 0) | ||
| printf(" - %.0f K\n", (count / 1024.0)); | ||
| if(verbosity > 1) { | ||
| if (dotcount % 32 == 0) | ||
| printf(" "); | ||
| printf("."); | ||
| fflush(stdout); | ||
| dotcount++; | ||
| if (dotcount % 32 == 0) | ||
| printf(" - %.0f K\n", (count / 1024.0)); | ||
| } | ||
|
|
||
| /* Prepare packet */ | ||
| csp_packet_t * packet = csp_buffer_get(VMEM_SERVER_MTU); | ||
| csp_packet_t * packet = csp_buffer_get(0); | ||
| if(packet == NULL) { | ||
| break; | ||
| } | ||
| packet->length = VMEM_MIN(VMEM_SERVER_MTU, length - count); | ||
|
|
||
| /* Copy data */ | ||
|
|
@@ -170,18 +208,15 @@ int vmem_upload(int node, int timeout, uint64_t address, char * datain, uint32_t | |
|
|
||
| } | ||
|
|
||
| printf(" - %.0f K\n", (count / 1024.0)); | ||
| if(verbosity > 1) { | ||
| printf(" - %.0f K\n", (count / 1024.0)); | ||
| } | ||
|
|
||
| csp_close(conn); | ||
|
|
||
| uint32_t time_total = csp_get_ms() - time_begin; | ||
|
|
||
| if(count != length){ | ||
| unsigned int window_size = 0; | ||
| csp_rdp_get_opt(&window_size, NULL, NULL, NULL, NULL, NULL); | ||
| printf("Upload didn't complete, suggested offset to resume: %"PRIu32"\n", count - ((window_size + 1) * VMEM_SERVER_MTU)); | ||
| return -1; | ||
| } else { | ||
| if(verbosity > 0) { | ||
| printf(" Uploaded %"PRIu32" bytes in %.03f s at %"PRIu32" Bps\n", count, time_total / 1000.0, (uint32_t)(count / ((float)time_total / 1000.0)) ); | ||
| } | ||
|
|
||
|
|
@@ -350,6 +385,11 @@ int vmem_client_calc_crc32(int node, int timeout, uint64_t address, uint32_t len | |
|
|
||
| int res = -1; | ||
|
|
||
| if((address > UINT32_MAX) && version != 2){ | ||
| printf(" Error: 64 bit address only supported in version 2\n"); | ||
| return res; | ||
| } | ||
|
|
||
| uint32_t time_begin = csp_get_ms(); | ||
|
|
||
| /* Establish connection */ | ||
|
|
@@ -395,4 +435,4 @@ int vmem_client_calc_crc32(int node, int timeout, uint64_t address, uint32_t len | |
| csp_close(conn); | ||
|
|
||
| return res; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are breaking the API signature :-) but if you do, why not implement the
verbosityargument as aconst? This might help the linker in leaving out theprintf()strings from the.constsection in FLASH when compiled for the modules and not CSH.