15 #ifndef G_OMIT_GSETUPDDOWNLOADFILE
67 strcpy(node->name, name);
68 node->len = strlen(node->data);
71 head->tail->next = node;
81 if (node == 0)
return;
106 if (!(array_buf = malloc(
MAXARRAY)))
115 int len = strlen(element);
116 if ((len + node->index + 1) >=
MAXARRAY)
119 strcpy(node->data + node->index, element);
121 node->data[node->index++] =
'\r';
122 node->data[node->index] = 0;
123 node->len = node->index;
145 sprintf(command,
"DA %s[]", node->name);
150 sprintf(command,
"DM %s[%i]", node->name, node->elements);
165 if (head->count == 0)
170 size_t bytes_written;
172 int data_left = head->count;
175 if (!(file = fopen(file_path,
"wb")))
181 bytes = strlen(node->name);
182 bytes_written = fwrite(node->name, 1, bytes, file);
185 if (colcount != head->count)
187 bytes_written += fwrite(
",", 1, 1, file);
192 bytes_written += fwrite(
"\r", 1, 1, file);
196 if (bytes_written != bytes)
214 if (node->index != node->len)
216 while ((node->data[node->index] !=
'\r')
217 && (node->index < node->len))
219 if (node->data[node->index] !=
' ')
221 bytes_written += fwrite(node->data + node->index, 1, 1, file);
227 if (node->index == node->len)
234 if (colcount != head->count)
236 bytes_written += fwrite(
",", 1, 1, file);
241 bytes_written += fwrite(
"\r", 1, 1, file);
246 if (bytes_written != bytes)
271 char c = array_data[pos];
281 if (c ==
',' || c ==
'\r')
309 if ((c ==
',') || (c ==
'\r'))
318 if (node == 0) node = &head;
346 if (c > 31 && c < 127)
371 for (i = 0; i < arr_size; i++)
373 if ((
int)arr[i] == index)
385 if (!(file = fopen(file_path,
"rb")))
389 fseek(file, 0, SEEK_END);
390 int in_len = ftell(file);
394 char* in_buf = (
char*)malloc(
sizeof(
char) * in_len);
395 fread(in_buf,
sizeof(
char), in_len, file);
413 char array_names[1024];
427 bytes = strlen(strcpy(array_names, names));
431 if ((rc =
GCmdT(g,
"LA", array_names,
sizeof(array_names), 0)) !=
G_NO_ERROR)
434 bytes = strlen(array_names);
438 for (i = 0; i < bytes; i++)
445 if ((c !=
' ') && (c !=
'\r') && (c !=
'\n') && !bracket)
447 name[n++] = array_names[i];
450 if ((c ==
' ') || (c ==
'\r') || (i == bytes - 1))
475 #ifndef G_OMIT_GSETUPDDOWNLOADFILE
483 file = fopen(file_path,
"rb");
487 fseek(file, 0, SEEK_END);
488 in_len = ftell(file);
492 unsigned char* in_buf = (
unsigned char*)malloc(
sizeof(
unsigned char) * in_len);
493 fread(in_buf,
sizeof(
unsigned char), in_len, file);
498 uLong out_len = (
unsigned int)((in_buf[0] << 24) | (in_buf[1] << 16) | (in_buf[2] << 8) | (in_buf[3]));
499 unsigned char* out_buf = (
unsigned char*)malloc(
sizeof(
unsigned char) * out_len);
502 rc = uncompress(out_buf, &out_len, in_buf + 4, in_len - 4);
511 if (info != NULL && info_len > 0) {
519 for (i = 0; i < info_len; i++)
525 else if (i == (info_len - 1))
535 for (i = 1; i < 7; i++)
537 if (i == 1 || i == 3)
545 rc += (1 << (i - 1));
551 if (options & 0x8000)
557 int len = out_len - 1;
558 for (i = 0; i < len; i++)
560 sector = (
char*)out_buf + i + 1;
570 if (options & 0x0002)
576 if (options & 0x0008)
582 if (options & 0x0010)
588 if (options & 0x0020)
GReturn H_DownloadArraysFromList(GCon g, ArrayNode *head, int fail)
Walks through the array linked list, downloading each.
void H_InitArrayNode(ArrayNode *node)
Function to initialize the memory of a new node.
GReturn H_ArrayDownloadFromMemory(GCon g, const char *array_data, int fail)
Helper function to download a block of arrays to the controller.
void H_FreeArrays(ArrayNode *node)
Frees all memory downstream of node. After passing list head to this function, all memory is freed an...
GReturn H_WriteArrayCsv(ArrayNode *head, GCStringIn file_path)
After filling the array list, this function is called to write out the CSV.
GReturn H_CreateArrayNode(ArrayNode *head, char *name)
Creates a buffer on the heap to write data, and adds it to the linked list.
GReturn H_AddArray(ArrayNode *head, char *name, char *data)
Add an ArrayData node to the linked list.
char * H_FindSector(char *arr, int arr_size, int index)
Function that returns a pointer to the start of the specified sector in the GCB data.
GReturn H_DownloadData(GCon g, const char *data, int fail)
Helper function to send a string of commands to the controller, one at at time.
GReturn H_UploadArrayToList(GCon g, ArrayNode *head, char *name)
Uploads a particular array and adds it to the linked list.
GReturn H_ArrayAddElement(ArrayNode *node, GCStringIn element)
Adds an array element to an array node.
GCLIB_DLL_EXPORTED GReturn GCALL GCmdT(GCon g, GCStringIn command, GCStringOut trimmed_response, GSize response_len, GCStringOut *front)
Wrapper around GCommand that trims the response.
GReturn GCALL GArrayDownloadFile(GCon g, GCStringIn file_path)
Array download from file.
GReturn GCALL GArrayUploadFile(GCon g, GCStringIn file_path, GCStringIn names)
Array upload to file.
GReturn GCALL GSetupDownloadFile(GCon g, GCStringIn file_path, GOption options, GCStringOut info, GSize info_len)
Download a saved controller configuration from a file.
GCLIB_DLL_EXPORTED GReturn GCALL GArrayDownload(GCon g, const GCStringIn array_name, GOption first, GOption last, GCStringIn buffer)
Downloads array data to a pre-dimensioned array in the controller's array table.
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownload(GCon g, GCStringIn program, GCStringIn preprocessor)
Downloads a program to the controller's program buffer.
GCLIB_DLL_EXPORTED GReturn GCALL GCmd(GCon g, GCStringIn command)
Wrapper around GCommand for use when the return value is not desired.
GCLIB_DLL_EXPORTED GReturn GCALL GArrayUpload(GCon g, const GCStringIn array_name, GOption first, GOption last, GOption delim, GBufOut buffer, GSize buffer_len)
Uploads array data from the controller's array table.
#define G_BAD_RESPONSE_QUESTION_MARK
Operation received a ?, indicating controller has a TC error.
#define G_CR
For GArrayUpload(), use this value in the delim field to delimit with carriage returns.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
int GOption
Option integer for various formatting, etc.
#define G_NO_ERROR
Return value if function succeeded.
#define G_BOUNDS
For functions that take range options, e.g. GArrayUpload(), use this value for full range.
#define G_BAD_FULL_MEMORY
Not enough memory for an operation, e.g. all connections allowed for a process already taken.
unsigned int GSize
Size of buffers, etc.
#define GCALL
Specify calling convention for Windows.
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
#define G_BAD_FILE
Bad file path, bad file contents, or bad write.
char * GCStringOut
C-string output from the library. Implies null-termination.
const char * GCStringIn
C-string input to the library. Implies null-termination.
#define MAXARRAY
Maximum size for an array table upload.
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Structure to create a linked list for array data.