Skip to content

Commit

Permalink
Add KSNRF_Application_IAP 01/11
Browse files Browse the repository at this point in the history
  • Loading branch information
Hom-Wang committed Jan 11, 2018
1 parent b1eba41 commit 8f1e29a
Show file tree
Hide file tree
Showing 449 changed files with 262,185 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
92 changes: 92 additions & 0 deletions firmwareNRF52/KSNRF_Application_IAP/BINSender/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <Windows.h>

#include "rs232.h"

#define BUF_SIZE 4096
#define FILE_NAME "KSNRF_Application_IAP_GPIO_200.bin"

int com_port = 3 - 1; /* COM3 */
int baudrate = 115200; /* 115200 */
char mode[] = {'8', 'N', '1', 0};

int main()
{
FILE *fs;

uint8_t i;

uint8_t fileInfo[16] = {0};
uint8_t fileBuff[BUF_SIZE] = {0};

uint32_t *fileSize = &fileInfo[4];
uint32_t *recvLens = &fileInfo[8];
uint32_t *sendCRC = &fileInfo[12];

uint32_t quotient = 0;
uint32_t remainder = 0;

uint32_t count = 0;
uint32_t offset = 0;

fileInfo[0] = 'K';
fileInfo[1] = 'S';
fileInfo[2] = 'U';
fileInfo[3] = 'L';
*recvLens = 64;

/* Open Binary File */
fs = fopen(FILE_NAME, "rb");
if (fs == NULL) {
printf("Open File Error\n\n");
return 1;
}
else {
printf("Open File Success\n\n");
fseek(fs, 0, SEEK_END);
*fileSize = ftell(fs);
rewind(fs);
fread(fileBuff, *fileSize, 1, fs);

*sendCRC = 0;
for (i = 0; i < 12; i++) {
*sendCRC += fileInfo[i];
}
quotient = *fileSize / *recvLens;
remainder = *fileSize % *recvLens;

printf("file size = %d bytes\n", *fileSize);
printf("\n");
while (count <= *fileSize) {
printf(" %02X", fileBuff[count++]);
if ((count % 16) == 0) {
printf("\n");
}
}
printf("\n\n");
}
fclose(fs);

/* Open COM Port */
if (!RS232_OpenComport(com_port, baudrate, mode)) {
printf("Open COM Port Success\n\n");

RS232_SendBuf(com_port, fileInfo, 16);
Sleep(100);

while (quotient--) {
printf("[offset] = %d\n", offset);
RS232_SendBuf(com_port, fileBuff + offset, *recvLens);
offset += *recvLens;
Sleep(100);
}
printf("[offset] = %d\n", offset);
RS232_SendBuf(com_port, fileBuff + offset, remainder);
}
RS232_CloseComport(com_port);
printf("\n\nClose COM Port\n");

return(0);
}
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 8f1e29a

Please sign in to comment.