@@ -85,6 +85,8 @@ String __fastcall CNanoVNA1Comms::getSerialStateString(t_serial_state state)
8585 case SERIAL_STATE_FREQDATA_BIN: s = " freq_data_bin" ; break ;
8686 case SERIAL_STATE_FREQDATA_RAW: s = " freq_data_raw" ; break ;
8787 case SERIAL_STATE_SCREEN_CAPTURE: s = " screen_capture" ; break ;
88+ case SERIAL_STATE_SCREEN_FILL: s = " fill" ; break ;
89+ case SERIAL_STATE_SCREEN_BULK: s = " bulk" ; break ;
8890 case SERIAL_STATE_SD_LIST: s = " sd_list" ; break ;
8991 case SERIAL_STATE_SD_READFILE: s = " sd_readfile" ; break ;
9092 case SERIAL_STATE_MODE: s = " mode" ; break ;
@@ -2056,38 +2058,48 @@ void __fastcall CNanoVNA1Comms::processRxBlock()
20562058 break ;
20572059
20582060 case SERIAL_STATE_SCREEN_CAPTURE:
2061+ case SERIAL_STATE_SCREEN_FILL:
2062+ case SERIAL_STATE_SCREEN_BULK:
20592063 if (data_unit.m_vna_data .lcd_width >= 320 && data_unit.m_vna_data .lcd_height >= 240 && data_unit.m_vna_data .lcd_width <= 4096 && data_unit.m_vna_data .lcd_height <= 4096 )
20602064 {
2061- if (m_rx_block.bin_data_index == ( unsigned int )(data_unit. m_vna_data . lcd_width * data_unit. m_vna_data . lcd_height * 2 ) && m_rx_block. bin_data_index == m_rx_block.bin_data .size ())
2065+ if (m_rx_block.bin_data_index == m_rx_block.bin_data .size ())
20622066 {
2063- if (m_capture_bm == NULL )
2067+ if (m_capture_bm == NULL ) {
20642068 m_capture_bm = new Graphics::TBitmap ();
2065- if (m_capture_bm != NULL )
2066- {
20672069 m_capture_bm->Monochrome = false ;
20682070 m_capture_bm->Transparent = false ;
2069- m_capture_bm->PixelFormat = pf32bit;
2070- m_capture_bm->Width = data_unit.m_vna_data .lcd_width ;
2071- m_capture_bm->Height = data_unit.m_vna_data .lcd_height ;
2072-
2073- for (int i = 0 ; i < (int )m_rx_block.bin_data .size (); i += 2 )
2074- {
2075- const uint16_t pixel = ((uint16_t )m_rx_block.bin_data [i + 1 ] << 8 ) | ((uint16_t )m_rx_block.bin_data [i + 0 ] << 0 );
2076-
2077- const uint8_t red = (pixel >> 0 ) & 0xf8 ;
2078- const uint8_t grn = ((pixel << 5 ) & 0xe0 ) | ((pixel >> 11 ) & 0x1c );
2079- const uint8_t blu = (pixel >> 5 ) & 0xf8 ;
2080-
2081- const int y = (i / 2 ) / m_capture_bm->Width ;
2082- const int x = (i / 2 ) % m_capture_bm->Width ;
2083- if (y < m_capture_bm->Height && x < m_capture_bm->Width )
2084- {
2085- uint8_t *p = (uint8_t *)m_capture_bm->ScanLine [y] + (x * 4 );
2086- p[0 ] = blu;
2087- p[1 ] = grn;
2088- p[2 ] = red;
2089- p[3 ] = 255 ;
2090- }
2071+ m_capture_bm->PixelFormat = pf16bit;
2072+ }
2073+ if (m_capture_bm == NULL ) break ;
2074+ if (m_capture_bm->Width != data_unit.m_vna_data .lcd_width ) m_capture_bm->Width = data_unit.m_vna_data .lcd_width ;
2075+ if (m_capture_bm->Height != data_unit.m_vna_data .lcd_height ) m_capture_bm->Height = data_unit.m_vna_data .lcd_height ;
2076+ int16_t x0, x1, y0, y1;
2077+ uint16_t *data;
2078+ int step = 1 ;
2079+ if (m_rx_block.type == SERIAL_STATE_SCREEN_CAPTURE) {
2080+ x0 = 0 ; x1 = m_capture_bm->Width ;
2081+ y0 = 0 ; y1 = m_capture_bm->Height ;
2082+ data = (uint16_t *)&m_rx_block.bin_data [0 ];
2083+ }
2084+ else if (m_rx_block.type == SERIAL_STATE_SCREEN_BULK){
2085+ x0 = m_region.x ;
2086+ y0 = m_region.y ;
2087+ x1 = m_region.w + x0;
2088+ y1 = m_region.h + y0;
2089+ data = (uint16_t *)&m_rx_block.bin_data [8 ];
2090+ }
2091+ else {
2092+ x0 = m_region.x ;
2093+ y0 = m_region.y ;
2094+ x1 = m_region.w + x0;
2095+ y1 = m_region.h + y0;
2096+ data = (uint16_t *)&m_rx_block.bin_data [8 ];
2097+ step = 0 ;
2098+ }
2099+ for (int16_t y = y0; y < y1; y++) {
2100+ uint16_t *dst = (uint16_t *)m_capture_bm->ScanLine [y] + x0;
2101+ for (int16_t x = x0; x < x1; x++, data+=step){
2102+ *dst++ = (*data<<8 )|(*data>>8 );
20912103 }
20922104 }
20932105
@@ -2133,7 +2145,7 @@ bool __fastcall CNanoVNA1Comms::processRxLine()
21332145 if (m_rx_block.type != SERIAL_STATE_IDLE)
21342146 Form1->pushCommMessage (" rx: " + getSerialStateString (m_rx_block.type ).UpperCase () + " done" );
21352147 #endif
2136- Form1->pushCommMessage (" rx: " + m_rx_string);
2148+ // Form1->pushCommMessage("rx: " + m_rx_string);
21372149
21382150 m_rx_string = m_rx_string.SubString (pos + 3 , m_rx_string.Length ());
21392151
@@ -2146,7 +2158,8 @@ bool __fastcall CNanoVNA1Comms::processRxLine()
21462158 }
21472159 else
21482160 {
2149- Form1->pushCommMessage (" rx: " + m_rx_string.Trim ());
2161+ if (m_rx_string != " fill" && m_rx_string != " bulk" )
2162+ Form1->pushCommMessage (" rx: " + m_rx_string.Trim ());
21502163 }
21512164
21522165 if (m_rx_string.IsEmpty ())
@@ -2310,6 +2323,28 @@ bool __fastcall CNanoVNA1Comms::processRxLine()
23102323 }
23112324 }
23122325 else
2326+ if (cmd == " fill" )
2327+ {
2328+ if (data_unit.m_vna_data .lcd_width > 0 && data_unit.m_vna_data .lcd_height > 0 )
2329+ {
2330+ block_type = SERIAL_STATE_SCREEN_FILL;
2331+
2332+ m_rx_block.bin_data .resize (10 );
2333+ m_rx_block.bin_data_index = 0 ;
2334+ }
2335+ }
2336+ else
2337+ if (cmd == " bulk" )
2338+ {
2339+ if (data_unit.m_vna_data .lcd_width > 0 && data_unit.m_vna_data .lcd_height > 0 )
2340+ {
2341+ block_type = SERIAL_STATE_SCREEN_BULK;
2342+
2343+ m_rx_block.bin_data .resize (8 );
2344+ m_rx_block.bin_data_index = 0 ;
2345+ }
2346+ }
2347+ else
23132348 if (cmd == " scan" )
23142349 {
23152350 if (data_unit.m_vna_data .type != UNIT_TYPE_TINYSA)
@@ -2418,6 +2453,11 @@ bool __fastcall CNanoVNA1Comms::processRxLine()
24182453 }
24192454 }
24202455 else
2456+ if (cmd == " touch" || cmd == " release" || cmd == " refresh" )
2457+ {
2458+ return true ;
2459+ }
2460+ else
24212461 if (cmd == " sd_list" )
24222462 {
24232463 // block_type = SERIAL_STATE_SD_LIST;
@@ -2466,11 +2506,69 @@ int __fastcall CNanoVNA1Comms::processRx(t_serial_buffer &serial_buffer)
24662506 // add the received bytes into the correct rx buffer for processing
24672507
24682508 unsigned int k = 0 ;
2469-
24702509 while (k < serial_buffer.buffer_wr )
24712510 {
24722511 switch (m_rx_block.type )
24732512 {
2513+ case SERIAL_STATE_SCREEN_BULK:
2514+ case SERIAL_STATE_SCREEN_FILL:
2515+ {
2516+ const uint8_t b = serial_buffer.buffer [k];
2517+ #if 0
2518+ if (m_rx_block.bin_data_index == 0)
2519+ {
2520+ if (b == '\r' || b == '\n') { // drop any initial carriage return and line feed characters
2521+ k++;
2522+ break;
2523+ }
2524+ }
2525+ #endif
2526+ if (m_rx_block.bin_data_index < 8 )
2527+ {
2528+ m_rx_block.bin_data [m_rx_block.bin_data_index ++] = b;
2529+ k++;
2530+ if (m_rx_block.bin_data_index >= 8 )
2531+ {
2532+ int i = 0 ;
2533+ m_region.x = ((uint16_t )m_rx_block.bin_data [1 ] << 8 ) | (m_rx_block.bin_data [0 ] << 0 );
2534+ m_region.y = ((uint16_t )m_rx_block.bin_data [3 ] << 8 ) | (m_rx_block.bin_data [2 ] << 0 );
2535+ m_region.w = ((uint16_t )m_rx_block.bin_data [5 ] << 8 ) | (m_rx_block.bin_data [4 ] << 0 );
2536+ m_region.h = ((uint16_t )m_rx_block.bin_data [7 ] << 8 ) | (m_rx_block.bin_data [6 ] << 0 );
2537+ if (m_region.w *m_region.h *2 <= 2048 && m_region.x >= 0 && m_region.x < 480 && m_region.y >= 0 && m_region.y < 320 )
2538+ {
2539+ if (m_rx_block.type == SERIAL_STATE_SCREEN_BULK)
2540+ m_rx_block.bin_data .resize (8 + m_region.w *m_region.h *2 ); // make room for the following data
2541+ else
2542+ m_rx_block.bin_data .resize (8 + 2 ); // make room for the following data
2543+ }
2544+ }
2545+ } else {
2546+ int available_bytes = serial_buffer.buffer_wr - k;
2547+ int available_space = (int )m_rx_block.bin_data .size () - (int )m_rx_block.bin_data_index ;
2548+ if (available_bytes > available_space)
2549+ available_bytes = available_space;
2550+ if (available_bytes > 0 )
2551+ { // copy the rx'ed data into the rx binary buffer
2552+ memcpy (&m_rx_block.bin_data [m_rx_block.bin_data_index ], &serial_buffer.buffer [k], available_bytes);
2553+ m_rx_block.bin_data_index += available_bytes;
2554+ k += available_bytes;
2555+ }
2556+
2557+ if (m_rx_block.bin_data_index >= m_rx_block.bin_data .size ())
2558+ { // done
2559+ if (k > 0 )
2560+ { // remove used data from the rx serial buffer
2561+ if (k < serial_buffer.buffer_wr )
2562+ memmove (&serial_buffer.buffer [0 ], &serial_buffer.buffer [k], serial_buffer.buffer_wr - k);
2563+ serial_buffer.buffer_wr -= k;
2564+ k = 0 ;
2565+ }
2566+ processRxBlock ();
2567+ }
2568+ }
2569+ break ;
2570+
2571+ }
24742572 case SERIAL_STATE_SD_READFILE:
24752573 case SERIAL_STATE_SCREEN_CAPTURE:
24762574 case SERIAL_STATE_FREQDATA_RAW:
@@ -2663,6 +2761,8 @@ int __fastcall CNanoVNA1Comms::processRx(t_serial_buffer &serial_buffer)
26632761
26642762 if ( m_rx_block.type == SERIAL_STATE_SD_READFILE ||
26652763 m_rx_block.type == SERIAL_STATE_SCREEN_CAPTURE ||
2764+ m_rx_block.type == SERIAL_STATE_SCREEN_FILL ||
2765+ m_rx_block.type == SERIAL_STATE_SCREEN_BULK ||
26662766 m_rx_block.type == SERIAL_STATE_FREQDATA_BIN ||
26672767 m_rx_block.type == SERIAL_STATE_FREQDATA_RAW)
26682768 { // currently receiving binary data
0 commit comments