Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:5060c8ea0ccd, committed 2020-06-18
- Comitter:
- thomashaine
- Date:
- Thu Jun 18 14:34:24 2020 +0000
- Parent:
- 0:e7352f4f3dcb
- Child:
- 2:53ca7bc14ed5
- Commit message:
- rev2
Changed in this revision
--- a/common_task.cpp Thu Jun 18 12:36:05 2020 +0000
+++ b/common_task.cpp Thu Jun 18 14:34:24 2020 +0000
@@ -91,20 +91,11 @@
}
-void CAPTURE_fall(){
- CAPTURE=0;
-}
-
-void CAPTURE_rise(){
- CAPTURE=1;
-}
-
void TASK_INIT(){
// Enable reset
RSTN=0; //0 => reset OK
wait_us(5000);
-
//DEFAULT SIGNAL OUTPUT
// Output enable
@@ -113,19 +104,10 @@
CAPTURE=0; //0 => no capture
wait_us(5000);
-
- // link interrupt
- // capture interrupt
- button_capture.enable_irq();
- button_capture.fall(&CAPTURE_fall);
- button_capture.rise(&CAPTURE_rise);
-
// Disable reset
RSTN=1;
wait_us(5000);
-
-
}
--- a/main.cpp Thu Jun 18 12:36:05 2020 +0000
+++ b/main.cpp Thu Jun 18 14:34:24 2020 +0000
@@ -33,6 +33,8 @@
int portnumber = 61477;
int portnumber_com = 61478;
char* commandbuffer;
+char* commandbuffertemp;
+
int MSG_LEN=64;
@@ -56,39 +58,13 @@
InterruptIn irq_cis(PA_11);
-// frame pointer and frame size
-char* FRAME_BUFFER;
-
-const int frame_size_8b =640*480*1; //640*480 pixels de 1 byte
-const int frame_size_QQVGA_8b =160*120*1; //160*120 pixels de 1 byte
-const int frame_size_10b =640*480*2; //640*480 pixels de 2 byte
-const int frame_size_QQVGA_10b =160*120*2; //160*120 pixels de 2 byte
-
//keep track fo the number of line and frame read
int line_read=0;
int frame_read=0;
int imSize=frame_size_10b;
-
-/* Private function prototypes -----------------------------------------------*/
-// functions for sending frame over ethernet
-void print_start_frame(void);
-void send_frame_ethernet(void);
-int send_frame_ethernet_nohandshake(void);
-
-
-// configuration functions
-static void MX_GPIO_Init(void);
-static void MX_DMA_Init(void);
-static void MX_DCMI_Init_8b(void);
-static void MX_DCMI_Init_10b(void);
-
-// capture functions
-void start_capture_10b();
-void start_video();
-void suspend_capture(void);
-void resume_capture(void);
-void stop_capture(void);
+// frame pointer and frame size
+char* FRAME_BUFFER;
@@ -120,84 +96,35 @@
}
}
-
-
-void send_frame_ethernet(){
+int send_frame_ethernet_nohandshake_while(){
- int status=0;
- char rbuffer[13]="Hello server";
- char sbuffer[13] = "Hello server";
- int scount = 0;
- int rcount = 0;
- int i=0;
- int byte_sent=0;
-
- sprintf(commandbuffer, "Sending frame via Ethernet \n");
- byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
-
- // Send a simple http request
- sprintf(commandbuffer, "Sending hello \n");
- byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
-
- scount = socket.send(sbuffer, sizeof sbuffer);
- if(scount>0)
- //printf("sent %d [%.*s]\r\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
+ int byte_chunk_sent=0;
+ int a=0;
+ int pixel_per_chunk=2048;
+ int bytes_per_pixel=2;
+ int bytes_per_chunk=pixel_per_chunk*bytes_per_pixel;
+ int byte_to_send=0;
+ int byte_per_image=imSize;
- // Recieve a simple http response and print out the response line
- // should receive hello socket
- sprintf(commandbuffer, "Receiveing hello \n");
- byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
-
- rcount = socket.recv(&rbuffer, sizeof rbuffer);
- if(rcount>0)
- //printf("recv %d [%.*s]\r\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
-
- // Send a simple frame
- sprintf(commandbuffer, "Sending frame\n");
- byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
-
- scount=0;
- for (i=0;i<9600;i++){
- //FRAME_BUFFER[i*32]=127;
- //FRAME_BUFFER[i*32+31]=255;
- scount+= socket.send(FRAME_BUFFER+i*32, 32*sizeof(char));
- }
- if(scount>0){
- sprintf(commandbuffer, "%i bytes sent\n", scount);
- byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
+
+ while (byte_chunk_sent<byte_per_image){
+ byte_to_send=min(byte_per_image - byte_chunk_sent, bytes_per_chunk);
+
+ //pointer are world align. hence the divided by 4
+ a = socket.send(FRAME_BUFFER+byte_chunk_sent/4 , byte_to_send);
+ if(a<0){
+ pc.printf("error byte -1/ %d / %d\r\n",a,byte_chunk_sent);
+ //return -1;
+ } else {
+ byte_chunk_sent += a;
+ //pc.printf("%d sent - total sent %d\r\n",a,byte_chunk_sent);
+ }
}
- // Close the socket to return its memory and bring down the network interface
- //socket.close();
-
-}
-
-
-int send_frame_ethernet_nohandshake(){
-
- int scount=0;
- int i=0;
- int pixel_per_chunk=1024;
- int byte_per_pixel=2;
- int byte_sent=0;
+ pc.printf("total of %d bytes sent\r\n",byte_chunk_sent);
- sprintf(commandbuffer, "%i bytes sen - chunk %d/%d - \n", scount,i,imSize/pixel_per_chunk);
- byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
-
- // Send a simple 10b frame
- scount=0;
- for (i=0;i<imSize/pixel_per_chunk;i++){
- // send nb pixel *size (=2byte) at addresse frame_buffer + nb chunk sent * size (=2byte)
- scount+= socket.send(FRAME_BUFFER+i*pixel_per_chunk*byte_per_pixel, pixel_per_chunk*byte_per_pixel*sizeof(char));
+ return byte_chunk_sent;
- sprintf(commandbuffer, "%i bytes sent - chunk %d/%d - \n", scount,i,imSize/pixel_per_chunk);
- byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
- }
-
- sprintf(commandbuffer, "%i bytes sent\n", scount);
- byte_sent=cs.send(commandbuffer, strlen(commandbuffer));
-
- return scount;
}
@@ -279,7 +206,7 @@
// override interrupt DCMI
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi){
- send_frame_ethernet_nohandshake();
+ send_frame_ethernet_nohandshake_while();
}
void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi){
frame_read++;
@@ -338,12 +265,16 @@
//*************************
// init pointer
//*************************
+ //
+ //!!!!!! attention : malloc is in num of words and not byte !!!!!!!!
+ //
//initialize frame buffer for 10b photo (malloc size en byte)
- FRAME_BUFFER=(char *)malloc(frame_size_10b*sizeof(char));
+ FRAME_BUFFER=(char *) malloc(frame_size_10b/4*sizeof(char));
//memset((void *)FRAME_BUFFER,0,(size_t) frame_size_10b/4);
//initialize commandbuffer pointer
commandbuffer=(char *) malloc((MSG_LEN+1)*sizeof(char));
+ commandbuffertemp=(char *) malloc((MSG_LEN+1)*sizeof(char));
//*************************
// init spi
@@ -440,7 +371,7 @@
}
//socket.set_blocking(false); // non blocking
- socket.set_timeout(1); // Timeout after (10)ms
+ //socket.set_timeout(1); // Timeout after (10)ms
@@ -510,7 +441,8 @@
add=atoi(pch);
TASK_SPI_WRITE(add,data);
- sprintf(commandbuffer, "done writing %d at %d", data, add);
+ sprintf(commandbuffertemp, "done writing %d at %d", data, add);
+ sprintf(commandbuffer,"%64s",commandbuffertemp);
byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
//pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
@@ -520,12 +452,13 @@
add=atoi(pch);
readvalue = TASK_SPI_READ(add);
- sprintf(commandbuffer, "%d/%d", readvalue,add);
- //sprintf(commandbuffer, "%64s", commandbuffer);
+ sprintf(commandbuffertemp, "%d/%d", readvalue,add);
+ sprintf(commandbuffer,"%64s",commandbuffertemp);
byte_sent=socket.send(commandbuffer,strlen(commandbuffer));
pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
- sprintf(commandbuffer, "done reading %d at %d", readvalue, add);
+ sprintf(commandbuffertemp, "done reading %d at %d", readvalue, add);
+ sprintf(commandbuffer,"%64s",commandbuffertemp);
byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
@@ -533,37 +466,42 @@
pch = strtok (NULL, " ");
pc.printf("[%s]\n\r",pch);
//imSize=atoi(pch);
- //sprintf(commandbuffer, "try to capture image of %d bytes", imSize);
- //byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
+ sprintf(commandbuffertemp, "try to capture image of %d bytes", imSize);
+ sprintf(commandbuffer,"%64s",commandbuffertemp);
+ byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
//TODO
- byte_sent=send_frame_ethernet_nohandshake();
+ pc.printf("hello0\n\r");
+ byte_sent=send_frame_ethernet_nohandshake_while();
+ pc.printf("hello4\n\r");
- sprintf(commandbuffer, "sent image of %d bytes/%d bytes", byte_sent,imSize);
+ sprintf(commandbuffertemp, "sent image of %d bytes/%d bytes", byte_sent,imSize);
+ sprintf(commandbuffer,"%64s",commandbuffertemp);
byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
//pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
}else if (strcmp (pch,"reset")==0 ||strcmp (pch,"RESET")==0){
TASK_RSTN();
- sprintf(commandbuffer, "done reseting chip");
+ sprintf(commandbuffertemp, "done reseting chip");
+ sprintf(commandbuffer,"%64s",commandbuffertemp);
byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
//pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
}else if (strcmp (pch,"exit")==0 ||strcmp (pch,"EXIT")==0){
- sprintf(commandbuffer, "close com and data sockets");
+ sprintf(commandbuffer, "%64s","close com and data sockets");
byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
//pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
status=socket.close();
status=cs.close();
}else{
- sprintf(commandbuffer, "command not recoginzed");
+ sprintf(commandbuffer, "%64s","command not recoginzed");
byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
//pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
}
} else{ //tok is null
- sprintf(commandbuffer, "empty tok");
+ sprintf(commandbuffer, "%64s","empty tok");
byte_sent=cs.send(commandbuffer,strlen(commandbuffer));
//pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent);
}
--- a/main.h Thu Jun 18 12:36:05 2020 +0000 +++ b/main.h Thu Jun 18 14:34:24 2020 +0000 @@ -43,8 +43,10 @@ /* Exported constants --------------------------------------------------------*/ /* USER CODE BEGIN EC */ - - +const int frame_size_8b =640*480*1; //640*480 pixels de 1 byte +const int frame_size_QQVGA_8b =160*120*1; //160*120 pixels de 1 byte +const int frame_size_10b =640*480*2; //640*480 pixels de 2 byte +const int frame_size_QQVGA_10b =160*120*2; //160*120 pixels de 2 byte /* USER CODE END EC */ @@ -59,6 +61,24 @@ /* USER CODE BEGIN EFP */ /* Private function prototypes -----------------------------------------------*/ +// functions for sending frame over ethernet +void print_start_frame(void); +void send_frame_ethernet(void); +int send_frame_ethernet_nohandshake_while(void); + + +// configuration functions +static void MX_GPIO_Init(void); +static void MX_DMA_Init(void); +static void MX_DCMI_Init_8b(void); +static void MX_DCMI_Init_10b(void); + +// capture functions +void start_capture_10b(); +void start_video(); +void suspend_capture(void); +void resume_capture(void); +void stop_capture(void); /* USER CODE END EFP */