In micropython you convert from mp_obj_t to int using mp_obj_get_int
How can I convert from mp_obj to uint8_t?
Related
I'm trying to make an application that gets the size of an Ethernet chunk and stores it in a vector of ints. To get the chunk length I'm using the function provided by inet: chunk->getChunkLength(). Is there a way to convert the type inet::b to int?
To obtain the size of a chunk in bits use this code:
int bitSize = b(chunk->getChunkLength()).get();
If you want to obtain the size in bytes use this way:
int byteSize = B(chunk->getChunkLength()).get();
I am trying to use libpng1.6.35 library to decode image data from the given input buffer and return back the decode buffer to the renderer. I want the image with a transparent background.
Below is the image which I am trying to render:
#include "png.h"
#include <stdlib.h>
#include <stdio.h>
extern unsigned char g_image[0x00080000];
unsigned char * PngFileToRGBA(unsigned int *width,
unsigned int *height)
{
png_image image;
memset(&image, 0, (sizeof image));
image.version = PNG_IMAGE_VERSION;
png_image_begin_read_from_memory(&image,
png_const_voidp(g_image), sizeof(g_image)); /*g_image contains the
input image buffer to
decode*/
png_bytep buffer1; /*buffer1 is output
decoded image buffer.*/
image.format = PNG_FORMAT_BGRA;
buffer1 = (png_bytep)malloc(PNG_IMAGE_SIZE(image));
if (buffer1 != NULL &&
png_image_finish_read(&image, NULL/*background*/, buffer1,
0/*row_stride*/, NULL/*colormap*/) != 0)
{
return buffer1;
}
}
If I use image format as BGR, I get the correct output image using buffer1, but with image format as BGRA, the output image is washed out. Please guide what I am missing here.
Output rendered images with BGR and BGR format:
with image format as BGRA:
It behaves the same even if I use image format as RGB/RGBA.
I'm using a w32 library to allow me to do Windowing with the Go language. I'm not quite sure what to do with an unsafe.Pointer that will allow me to start setting pixel values in the pixel buffer.
I use an unsafe.Pointer, because that's what the w32 library expects me to pass in the CreateDIBSection function.
var p unsafe.Pointer
bitmap := w32.CreateDIBSection( srcDC, &bmi, w32.DIB_RGB_COLORS, &p, w32.HANDLE(0), 0 )
That code succeeds and gives me a pointer to the memory location where the DIBBits are stored. How can I use that to write values?
p[idx] = 0xff
will give me an error type unsafe.Pointer does not allow indexing. I've read the relevant docs on the unsafe.Pointer, but can't figure out how to treat it as a byte buffer that I can write into.
I'm new to Go and have worked through a lot of the examples at gobyexample.com, but cannot figure this out.
It's just a matter of casting the unsafe.Pointer back to an array (which is indexable) in the proper way.
After trying various casts, this is the one that worked (assuming wid and hgt are each declare as const):
pixels := (*[wid*hgt*4]uint8)(ptr)
then I was able to change them with:
pixels[(y*wid+x)*4+0] = 0x00 // Blue
pixels[(y*wid+x)*4+1] = 0x00 // Green
pixels[(y*wid+x)*4+2] = 0x00 // Red
I'm running a number of SNMP queries to a Hytera dmr repeater. However, the SNMP object definition looks like this:
rptVswr OBJECT-TYPE
SYNTAX OCTET STRING(SIZE(4))
MAX-ACCESS read-only
STATUS mandatory
DESCRIPTION
"The VSWR.
It should be changed to float format. "
-- 1.3.6.1.4.1.40297.1.2.1.2.4
::= { rptDataInfo 4 }
After running the query, I got an result like this:
Name/OID: rptVswr.0;
Value (OctetString): 0x76 D5 8B 3F
Does anyone have an idea how to convert that string into a readable format?
It should be something like this : 1.15 or 2.15
Many thanks for your help,
BR - Nils
Here is pretty simple C++ app that decodes hex data and converts it to float:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
unsigned char ptr[] = {0x76, 0xD5, 0x8B, 0x3F};
reverse(ptr, ptr + 4);
float f = *reinterpret_cast<float*>(ptr);
cout << f << endl;
return 0;
}
The result is 2.16559e+33
My experience with RF devices is that the SNMP replies are either in decimal or hex format and represent power in mW. If you take your get response 0x76 D5 8B 3F, and convert hex to decimal, you get 1,993,706,303 mW. This translates to 1.9937 kW. For VSWR, this is an accurate and acceptable measurement if your forward power is 2+ MW.
header 8 bytes:
unsigned short unk0; // version?
unsigned short size; // data size
unsigned short unk1; //
unsigned short unk2; //
data:
AMF3 correct data: 0x0a 0x0b 0x01 ...
It's not standart AMF: http://en.wikipedia.org/wiki/Action_Message_Format
What is the AMF format?
Flex use AMF to remote call, it transport on HTTP, and you can use HTTP monitor tool like Charles or Fiddler(with FiddlerAmfParser) to see more AMF data.