Chat GPT and code translation
- my1987toyota
- Topic Author
- Away
- Platinum Member
- Posts: 821
- Thank you received: 334
has anyone used it to do code translation say from JAVA to C++? Or are their programs anyone has used that does that
already? If so how usable were the results?
And how does one appease our new Skynet overlord's. LOL just kidding
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
- Posts: 19407
- Thank you received: 6507
They have become a f@king black hole, sucking everything and killing it. Nokia and over 200 other companies.
I have never played with it, i got tired of creating accounts for every damn thing, so whenever i see "register" i run the other way.
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
- Posts: 10737
- Thank you received: 3540
But I had a conversation with it recently asking it to write an interrupt diven hardware stepping routine an ARM CPU. Then I asked if it would change if it it was using the PREEMPT_RT kernel and it came up with this
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/mman.h>
#include "arm_gic.h" // Include the appropriate GIC (Generic Interrupt Controller) file for your specific ARM CPU
#define GPIO_PIN_NUM 10 // The number of the GPIO pin to toggle
#define TIMER_INTERRUPT_ID 30 // The ID of the timer interrupt to use
#define CLOCK_FREQ_MHZ 100 // The frequency of the clock in MHz
#define STEPS_PER_MM 10 // Number of pulses to travel one millimeter
#define STEPS_PER_INCH 25.4 * STEPS_PER_MM // Number of pulses to travel one inch
enum MeasurementSystem {
MEASUREMENT_SYSTEM_MM,
MEASUREMENT_SYSTEM_INCH,
};
volatile uint32_t tick_count = 0;
volatile uint32_t step_length = 1; // The duration of the pulse in microseconds
volatile uint32_t pulse_count = 0; // The number of clock cycles the pulse has been active for
volatile enum MeasurementSystem measurement_system = MEASUREMENT_SYSTEM_MM;
void timer_interrupt_handler(int sig) {
tick_count++; // Increment tick count on every timer interrupt
if (pulse_count > 0) {
// Turn off the GPIO pin if the pulse duration has been reached
if (pulse_count == (CLOCK_FREQ_MHZ * step_length)) {
set_gpio_pin_state(GPIO_PIN_NUM, 0);
pulse_count = 0;
} else {
// Toggle the GPIO pin if the pulse is still active
toggle_gpio_pin(GPIO_PIN_NUM);
pulse_count++;
}
}
}
void set_step_length(uint32_t length_us) {
step_length = length_us;
}
double convert_speed_to_pulse_freq(double speed) {
double steps_per_device_unit;
if (measurement_system == MEASUREMENT_SYSTEM_MM) {
steps_per_device_unit = STEPS_PER_MM;
} else {
steps_per_device_unit = STEPS_PER_INCH;
}
double pulse_freq = (speed / steps_per_device_unit) * CLOCK_FREQ_MHZ;
return pulse_freq;
}
void* timer_thread(void* arg) {
int ret;
struct sigaction sa;
timer_t timer_id;
struct sigevent sev;
struct itimerspec its;
// Set up the signal handler for the timer interrupt
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = timer_interrupt_handler;
sigemptyset(&sa.sa_mask);
ret = sigaction(SIGRTMIN, &sa, NULL);
if (ret != 0) {
printf("Error setting up signal handler\n");
return NULL;
}
// Create the timer and specify that it will generate the SIGRTMIN signal
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGRTMIN;
sev.sigev_value.sival_ptr = &timer_id;
ret = timer_create(CLOCK_MONOTONIC, &sev, &timer_id);
if (ret != 0) {
printf("Error creating timer\n");
return NULL;
}
// Set the timer to expire at a fixed interval based on the clock frequency
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = 1000000000 / CLOCK_FREQ_MHZ;
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 1000000000 / CLOCK
// Arm the timer and start the main loop
ret = timer_settime(timer_id, 0, &its, NULL);
if (ret != 0) {
printf("Error arming timer\n");
return NULL;
}
while (1) {
// Wait for the next timer interrupt
pause();
}
return NULL;
}
int main() {
int ret;
pthread_t timer_tid;
void* timer_ret;
// Set the GPIO pin to output mode
set_gpio_pin_mode(GPIO_PIN_NUM, GPIO_PIN_MODE_OUTPUT);
// Increase the process scheduling priority to ensure the program has real-time capabilities
ret = mlockall(MCL_CURRENT | MCL_FUTURE);
if (ret != 0) {
printf("Error locking memory\n");
return -1;
}
struct sched_param sched_param = {
.sched_priority = 99,
};
ret = sched_setscheduler(0, SCHED_FIFO, &sched_param);
if (ret != 0) {
printf("Error setting scheduling priority\n");
return -1;
}
// Create a new thread to handle the timer interrupt
ret = pthread_create(&timer_tid, NULL, timer_thread, NULL);
if (ret != 0) {
printf("Error creating timer thread\n");
return -1;
}
// Set the speed in device units per second
double speed = 10.0; // 10 mm/s or 0.3937 inch/s
double pulse_freq = convert_speed_to_pulse_freq(speed);
while (1) {
// Set the pulse frequency based on the speed and step length
double freq = pulse_freq / step_length;
set_timer_interrupt_frequency(TIMER_INTERRUPT_ID, freq);
// Wait for user input to change the step length or measurement system
printf("Enter step length in microseconds: ");
fflush(stdout);
scanf("%u", &step_length);
int new_measurement_system;
printf("Enter measurement system (0 for mm, 1 for inch): ");
fflush(stdout);
scanf("%d", &new_measurement_system);
measurement_system = new_measurement_system;
// Update the pulse frequency based on the new speed and measurement system
pulse_freq = convert_speed_to_pulse_freq(speed);
}
// Join the timer thread (this will never be reached in this program)
pthread_join(timer_tid, &timer_ret);
return 0;
}
I'm not saying its right but its a good framework to work with for our purposes. I am envisaging this could be incorporated into a component that sets all the prarameters and linuxcnc would give it the desired veolcity in real time....
Please Log in or Create an account to join the conversation.
- Grotius
- Offline
- Platinum Member
- Posts: 2232
- Thank you received: 1949
It will not be free for ever i guess.
Please Log in or Create an account to join the conversation.
- my1987toyota
- Topic Author
- Away
- Platinum Member
- Posts: 821
- Thank you received: 334
sooner or later their will be an opensourse version that will work every bit as well if someone takes the time
to learn it and work with it.
Please Log in or Create an account to join the conversation.
- cakeslob
- Offline
- Platinum Member
- Posts: 785
- Thank you received: 230
text-divinci2 im pretty sure is just a net scraper and feeds results from github, so the more times you reload, you can get better results. This one is good for easy shit like homework, fakenews, and offensive fanfiction. I think this is the one the new media picked up on last month. I think it became free or open beta or something around then.
codex-divinci2 is still in beta but you need to register and apply with them to get access. This is the one that does actual code generation .It can do live coding, coding explanation, conversion, and all the other complicated coding shit because its using another or different part of the ai, but its not exactly free, but they cost noticeably more than text-divinci2 which is pennies.
give me a good prompt for something in codex and ill run it through if its not too expensive (expensive is a relative term). The prompts have a strong effect on the outcome but also a strong effect on the price, so the bigger the prompt is more money , same with the results. luckily if the prompt syntax is wrong it wont go through. says it works best with python.
platform.openai.com/docs/guides/code/introduction
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
- Posts: 10737
- Thank you received: 3540
I use it quite a bit to help me with various problems. But it never a one shot process. It is a conversation.
Today I used it to produce a product description from bullet points from the supplier for my website. It excels where I suck when writing the metadata description and keywords that are for Google's eyes only. I ask for a full product description and summary description and basically just cut and pasted te results. Here is what it came up with: www.vmn.com.au/efs-xcape-bar-to-suit-mit...o-sport-qf-2019.html
A couple of products that It has written for me that have been indexed by Google rank in the top 5 for relevant keywords after just a week or so. I also used it today to do examples of schema markup that I passed on to my developer to get done for the Google Gods... This was a subject I knew a bit about and it was very quick and efficient to get detail of a pretty complex topic in a couple of minutes.
One of the first days I was using it, I asked it to produce a 500 word paper outlining the difference between Bos Indicus and Bos Taurus cattle breeds and to summarise the suitability of each in the differing climate and soil types found in Queensland Australia just for fun. It did a pretty good job but the content was somewhat thin. It would have got a pass, but not a distinction! I was quite amazed really.
Please Log in or Create an account to join the conversation.
- cakeslob
- Offline
- Platinum Member
- Posts: 785
- Thank you received: 230
actually its easier if i ask divinvi3
explain the difference between chatgpt and codex in terms of coding
ChatGPT is an automated conversation engine powered by natural language processing (NLP) and machine learning (ML) algorithms. It enables developers to create conversational AI applications and services without the need for coding. It takes the complexity out of building conversational applications, allowing developers to focus on the user experience and content.
Codex is a code-based tool for building conversational applications. It enables developers to create chatbots and other conversational applications using coding. Developers can use Codex to create custom dialogues, build conversations with natural language processing, and integrate AI-powered components into their applications. Codex provides a library of components to help developers quickly build powerful conversational applications.
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
- Posts: 19407
- Thank you received: 6507
Poster was from Pakistan with a single post.
Please Log in or Create an account to join the conversation.
- my1987toyota
- Topic Author
- Away
- Platinum Member
- Posts: 821
- Thank you received: 334
Please Log in or Create an account to join the conversation.