APPSCRIPT URL PARSING ISSUE - parsing

Ive been looking for a api to fetch if a vehicle has a open recall. I was able to find the url to pass the vin number to chrylser and receive the info I need using url fetch. I am having a issue parsing out the retreived data though.
the request is to this address:
https://www.mopar.com/moparsvc/recallInfo?vin=1C4RJKBG4M8122507&mrkt=ca&language=en_ca&campaign_status=All&campaign_type=A&callback=showVinInfo&_=1637770607999
the output data looks like this:
showVinInfo({"vin_recall":[{"vin_status":"success","campaign_status":"success","last_system_update_date":"2021-11-24","vehicle":{"vin":"1C4RJKBG4M8122507","niv":"","vehicle_desc":"JEEP GRAND CHEROKEE L LIMITED 4X4","model_year":"2021"},"recall_details":{"recall":[{"fca_campaign_number":"Y67","agency_campaign_number":"2021-576","campaign_desc":"2021 WL Radio Software Update","owner_letter_url":"/webselfservice/pdf/ca_en/Y67.pdf","type_of_campaign":"SAFETY","vin_live_date":"2021-09-23","vin_campaign_status":"REPAIRED","condition_and_risk":"Vehicles may fail to conform to Canada Motor Vehicle Safety Standard (CMVSS) 111 - Mirrors and Rear Visibility Systems. Suspect vehicles may not display the rear view image during a backing event. The vehicle operator will notice that the rearview image is not displayed if attempting to reference the image while backing. If this warning is not heeded, backing without verifying it is safe to do so could lead to an increased risk of injury to people outside the vehicle.","repair_description":"Your dealer will inspect and if necessary, update the radio software version","agency_report_date":"2021-09-21","repair_date":"2021-09-24"},{"fca_campaign_number":"Y79","agency_campaign_number":"2021-690","campaign_desc":"2021 WL & 2022 WS - ORC DTC/warning lamp","owner_letter_url":"/webselfservice/pdf/ca_en/Y79.pdf","type_of_campaign":"SAFETY","vin_live_date":"2021-11-19","vin_campaign_status":"Incomplete but repair parts are available","condition_and_risk":"The Occupant Restraint Control (ORC) module on your vehicle may have the incorrect software. The airbag warning indicator may not illuminate to notify the operator of possible compromised airbag system functionality. If specific ORC internal faults are active, then a diagnostic trouble code (DTC) will not be set and the airbag warning indicator may not illuminate. The internal faults will disable deployment of both the driver and passenger airbag squib (related to airbag venting post deployment) and knee airbags. Reduced occupant protection in the event of a crash may result in an increased risk of injury to motor vehicle occupants.","repair_description":"Your dealer will reprogram the ORC module with correct software. The estimated repair time is about a half hour.","agency_report_date":"2021-11-10","repair_date":"9999-01-01"}]}}]})
for some reason i am getting SyntaxError: Unexpected token s in JSON at position 0
*** HERE IS MY CODE WITH ATTEMPT TO FIX****
function pullOpenRecall() {
var vin = ("2C4RC1GG8LR137995");
var results = UrlFetchApp.fetch("https://www.mopar.com/moparsvc/recallInfo?vin="+vin+"&mrkt=us&language=en_us&campaign_status=All&campaign_type=A&callback=showVinInfo&_=1638229674507").getContentText();
const content = outputSample();
const json = JSON.parse(content.match(/^.+?\(({.*})\)$/)[1]);
console.log(json);
function outputSample() {
return `showVinInfo({"vin_recall":[{"vin_status":"success","campaign_status":"success","last_system_update_date":"2021-11-24","vehicle":{"vin":"1C4RJKBG4M8122507","niv":"","vehicle_desc":"JEEP GRAND CHEROKEE L LIMITED 4X4","model_year":"2021"},"recall_details":{"recall":[{"fca_campaign_number":"Y67","agency_campaign_number":"2021-576","campaign_desc":"2021 WL Radio Software Update","owner_letter_url":"/webselfservice/pdf/ca_en/Y67.pdf","type_of_campaign":"SAFETY","vin_live_date":"2021-09-23","vin_campaign_status":"REPAIRED","condition_and_risk":"Vehicles may fail to conform to Canada Motor Vehicle Safety Standard (CMVSS) 111 - Mirrors and Rear Visibility Systems. Suspect vehicles may not display the rear view image during a backing event. The vehicle operator will notice that the rearview image is not displayed if attempting to reference the image while backing. If this warning is not heeded, backing without verifying it is safe to do so could lead to an increased risk of injury to people outside the vehicle.","repair_description":"Your dealer will inspect and if necessary, update the radio software version","agency_report_date":"2021-09-21","repair_date":"2021-09-24"},{"fca_campaign_number":"Y79","agency_campaign_number":"2021-690","campaign_desc":"2021 WL & 2022 WS - ORC DTC/warning lamp","owner_letter_url":"/webselfservice/pdf/ca_en/Y79.pdf","type_of_campaign":"SAFETY","vin_live_date":"2021-11-19","vin_campaign_status":"Incomplete but repair parts are available","condition_and_risk":"The Occupant Restraint Control (ORC) module on your vehicle may have the incorrect software. The airbag warning indicator may not illuminate to notify the operator of possible compromised airbag system functionality. If specific ORC internal faults are active, then a diagnostic trouble code (DTC) will not be set and the airbag warning indicator may not illuminate. The internal faults will disable deployment of both the driver and passenger airbag squib (related to airbag venting post deployment) and knee airbags. Reduced occupant protection in the event of a crash may result in an increased risk of injury to motor vehicle occupants.","repair_description":"Your dealer will reprogram the ORC module with correct software. The estimated repair time is about a half hour.","agency_report_date":"2021-11-10","repair_date":"9999-01-01"}]}}]})`;
}
}
I probably should have been a little more clear on what Im attempting to do. Im building a google spreadsheet for my service dept. When they enter vehicles that need to be serviced to the spreadsheet I want the script to grab the vin from the spreadsheet and run the api call then return some of the values inside the response to the spreadsheet. I know currently my script has a variable set up for the vin but I figured I would add the code for pulling the vin from the spreadsheet after I could figure out how to even correctly parse the response to return certain values inside.
Currently the only way I know to parse then return specific values from a api call response is by code like this var foo = JSON.parse then accessing the it like (foo["Results"][0]["valueIwantToReturn"])
I know Im probably in over my head a little bit so I appreciate the help you are giving.

It is JSONP, not JSON. You could extract the 'JSON part' to parse it to json:
const content = 'showVinInfo({...})';
const json = JSON.parse(content.match(/^.+?\(({.*})\)$/)[1]);
const content = outputSample();
const json = JSON.parse(content.match(/^.+?\(({.*})\)$/)[1]);
console.log(json);
function outputSample() {
return `showVinInfo({"vin_recall":[{"vin_status":"success","campaign_status":"success","last_system_update_date":"2021-11-24","vehicle":{"vin":"1C4RJKBG4M8122507","niv":"","vehicle_desc":"JEEP GRAND CHEROKEE L LIMITED 4X4","model_year":"2021"},"recall_details":{"recall":[{"fca_campaign_number":"Y67","agency_campaign_number":"2021-576","campaign_desc":"2021 WL Radio Software Update","owner_letter_url":"/webselfservice/pdf/ca_en/Y67.pdf","type_of_campaign":"SAFETY","vin_live_date":"2021-09-23","vin_campaign_status":"REPAIRED","condition_and_risk":"Vehicles may fail to conform to Canada Motor Vehicle Safety Standard (CMVSS) 111 - Mirrors and Rear Visibility Systems. Suspect vehicles may not display the rear view image during a backing event. The vehicle operator will notice that the rearview image is not displayed if attempting to reference the image while backing. If this warning is not heeded, backing without verifying it is safe to do so could lead to an increased risk of injury to people outside the vehicle.","repair_description":"Your dealer will inspect and if necessary, update the radio software version","agency_report_date":"2021-09-21","repair_date":"2021-09-24"},{"fca_campaign_number":"Y79","agency_campaign_number":"2021-690","campaign_desc":"2021 WL & 2022 WS - ORC DTC/warning lamp","owner_letter_url":"/webselfservice/pdf/ca_en/Y79.pdf","type_of_campaign":"SAFETY","vin_live_date":"2021-11-19","vin_campaign_status":"Incomplete but repair parts are available","condition_and_risk":"The Occupant Restraint Control (ORC) module on your vehicle may have the incorrect software. The airbag warning indicator may not illuminate to notify the operator of possible compromised airbag system functionality. If specific ORC internal faults are active, then a diagnostic trouble code (DTC) will not be set and the airbag warning indicator may not illuminate. The internal faults will disable deployment of both the driver and passenger airbag squib (related to airbag venting post deployment) and knee airbags. Reduced occupant protection in the event of a crash may result in an increased risk of injury to motor vehicle occupants.","repair_description":"Your dealer will reprogram the ORC module with correct software. The estimated repair time is about a half hour.","agency_report_date":"2021-11-10","repair_date":"9999-01-01"}]}}]})`;
}

Related

Using HERE in Forth for temporary space

I'm writing a game in Forth (for learning purposes).
The game is played on a "10 cell board". I'm trying new stuff so I did
here 10 [char] - fill
to set up the space for the board.
Then, to play 'X' in position 3
[char] X here 3 + c!
This has been working fine, but raises the question
Is this OK?
What if the board was a million cells wide?
Thanks
The described approach has the certain environmental dependencies, so your program just have to match the environmental restriction on programs of your Forth system (i.e. that you use).
1. Size of the data space
The word UNUSED returns "the amount of space remaining in the region addressed by HERE". So, a program can check the available space.
Also, according to the subsection 4.1.3 Other system documentation of the Forth Standard:
A system shall provide the following information:
[...]
program data space available, in address units;
So, you have just to check whether your Forth system provides enough data space for you program, and how the available data space can be configured (if any).
2. Transient regions
In the general case, it is not safe for a portable program to use the data space without reserving it.
According to the section 3.3.3.6 Other transient regions of the Forth Standard, the contents of the data space regions identified by PAD, WORD, and #> may become invalid after the data space is allocated. Сonsequently, the contents of the region identified by HERE may become invalid after the contents of the regions identified by PAD, WORD, and #> are changed.
See also A.3.3.3.6 Other transient regions:
In many existing Forth systems, these areas are at HERE or just beyond it, hence the many restrictions.
Moreover, some Forth systems may use the region identified by HERE in internal purposes during translation. E.g. Gforth 0.7.9 uses this region when decoding escaped strings.
The phrase:
s\" test\-passed" cr here over type cr type cr
outputs:
test-passed
test-passed
So, you have to check the restrictions of your Forth system whether you may use the region identified by HERE without reserving the space (and in what conditions).

Roscpp data time value

I am working in roscpp and publishing odometry data to a ros node. Two classes are responsible for publishing this data. For safety reasons, it is sometimes necessary to call the destructor on the primary class and post still data (an odometry pose that uses the same values to let ros know the robot is standing still) from the other class. I have already confirmed the secondary class posts the correct pose on the correct anchor.
Most of the time after the switch to the secondary class, I am running into a check failed stemming from the data time not being greater than the previous data's time.
The error message I get is this:
F0402 08:12:25.187301 9044 map_by_time.h:43] Check failed: data.time > std::prev(trajectory.end())->first (636898039451158060 vs. 636898039451158060)
As you can see it thinks the data time is equal to the previous data time. I have confirmed that the timestamp being published from my code is in the area of 1554227809034068 (in microseconds since epoch), which is accurate to the time I collected the data. After the switch the time stamp is still correct, a value close to and slightly higher than the previous value.
I am trying to figure out why this error message has such a large number for time, and why it does not match the posted timestamp.

Writing BLE to Cycling Control Point - Adding Resistance

I have bee working with BLE for a while now, but primarily for reading and notifying characteristics.
The devices specifically are Virtual cycle trainers that support GATTS Cycling Power Service - 0x1818 link
I know that it's possible to increase resistance on this trainer, but I have read the documentation on Cycling Power Control Point - 0x2A66 [link][2] which is the only one with Mandatory write functions, but non of the documentation seem to be make sense.
Trainer: Cycleops Magnus
Reading and writing characteristic
// Reads all characteristics
var characteristics = service.characteristics;
for(BluetoothCharacteristic c in characteristics) {
List<int> value = await device.readCharacteristic(c);
print(value);
}
// Writes to a characteristic
await device.writeCharacteristic(c, [0x12, 0x34])
Reading and writing descriptors
// Reads all descriptors
var descriptors = characteristic.descriptors;
for(BluetoothDescriptor d in descriptors) {
List<int> value = await device.readDescriptor(d);
print(value);
}
// Writes to a descriptor
await device.writeDescriptor(d, [0x12, 0x34])
The closest I can see is setting the crank length, or chain weight but at this stage I am only guessing and am looking for some guidance.
The questions is this..
What characteristic or descriptor should I use to adjust Virtual Power
trainer resistance and what is the best way to do this?
Any coding Language is fine, I can transpose it.
Screenshot of services available for device
[2]: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.cycling_power_control_point.xml
I think you're using the wrong Bluetooth service for this. The Cycling Power Service is for collecting data from cycling power meters like this one: https://www.cyclist.co.uk/reviews/6705/long-term-review-fsa-powerbox-carbon-power-cranks
For your requirements, I believe you should be using the Fitness Machine Service (0x1826) which includes the Indoor Bike Data characteristic (0x2AD2) and most importantly for you, the Fitness Machine Control Point characteristic. Take a look at section 4.16.1 of the Fitness Machine Service specification and you'll see details of operations which the control point supports, including a reference to 4.16.2.5 Set Target Resistance Level Procedure. I think this is what you need.
You cannot use cycling control point(CPP) for adding resistance. CPP can only be used to copy data like wheel Revolution from old peripheral to new one or if you want to reset data on peripheral you can use cpp.
If you want to add resistance you need to check for fitness machine i am using elite and elite have Fitness Machine Control point you can write resistance and other things like inclination, elevation etc using FTCP.
Few of the vendor support fitness machine and other have given their api or source code you can use that to add resistance and other stuff like that.
Indoor trainers have a few services:
Cycling Power Service (ANT+ or BT also have)
ANT+FEC (ANT only)
BTLE Fitness control (FTMS)
TACX ANT+ FEC. over Bluetooth (https://blog.lazerwalker.com/2019/02/15/bike-game-part-2.html)
Wahoo's Extension to the Cycling Power Service (to be able to set Target power for instance)
To Add Resistance to the trainer to #1, you need to check if it also has the #5 service as well. (this is the UUID used - A026E005-0A7D-4AB3-97FA-F1500F9FEB8B)
#4 is actually a protocol which Tacx came up w/ before FTMS was a standard and some trainers still use this.

STM32 Current Flash Vector Address

I'm working on a dual OS system with STM32F103, I have two separate program that programmed on different FLASH locations. if both of the programs are the same, the only way to know which of them running is just by its start vector address.
But How I Can Read The Current Program Start Vector Address in STM32 ???
After reading the comments, it sounds like what you have/want is a bootloader. If your goal here is to have two different applications, one to do your main processing and real time handling and the other to just program new firmware, then you want to make a bootloader in your default boot flash space.
Bootloaders fundamentally do a few things, everything else is extra.
Check itself using some type of data integrity check like a CRC.
Checks the application
Jumps to the application.
Bootloaders will also program applications in the app space and verify they are programmed correctly before jumping as well. Colin gave some good advice about appending a CRC to the hex file before it is programmed in flash space to verify the applications.
There are a few things to look out for. The first would be the linker script and this is extremely important. A linker script will be used to map input objects to output objects and then determine based upon that script, what memory space they go into. For both of your applications, you need to create a memory map of how you want both programs to sit inside of the flash space. From this point, you can then make linker scripts for both programs so that a hex file can be generated within the parameters of what you deem acceptable flash space for the program. Each project you have will have its own linker script. An example would look something like this:
LR_IROM1 0x08000000 0x00010000 { ; load region size_region
ER_IROM1 0x08000000 0x00010000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00018000 { ; RW data
.ANY (+RW +ZI)
}
}
This will give RAM for the application to use as well as a starting point for the application.
After that, you can start the bootloader and give it information about where the application space lies for jumping and programming. Once again this is all determined by you from your memory map and both applications' linker scripts. You are going to need to add a separate entry inside of the linker for your CRC and length for a comparison of the calculated versus stored as well. Whatever tool you use to append the CRC to the hex file and have it programmed to flash space, remember to note the location and make it known to the linker script so you can reference those addresses to check integrity later.
After you check everything and it is determined that it is okay to go to the application, you can use some ARM assembly to jump to the starting application address. Before jumping, make sure to disable all peripherals and interrupts that were enabled in the bootloader. As Colin mentioned, these will share RAM, so it is important you de-initialize all used, otherwise, you'll end up with a hard fault.
At this point, the program used another hex file laid out by a linker script, so it should begin executing as planned, as long as you have the correct vector table offset, which gets into your question fully.
As far as your question on the "Flash vector address", I think what your really mean is your interrupt vector table address. An interrupt vector table is a data structure in memory that maps interrupt requests to the addresses of interrupt handlers. This is where the PC register grabs the next available instruction address upon hardware interrupt triggers, for example. You can see this by keeping track of the ARM pipeline in a few lines of assembly code. Each entry of this table is a handler's address. This offset must be aligned with your application, otherwise you will never go into the main function and the program will sit in the application space, but have nothing to do since all handlers addresses are unknown. This is what the SCB->VTOR is for. It is a vector interrupt table offset address register. In this case, there are a few things you can do. Luckily, these are hard-coded inside of STM generated files inside of the file "system_stm32(xx)xx.c" (xx is your microcontroller variant). There is a define for something called VECT_TAB_OFFSET which is the offset in the memory map of the vector table and is assigned to the SCB->VTOR register with the value that is chosen. Your interrupt vector table will always lie at the starting address of your main application, so for the bootloader it can be 0x00, but for the application, it will be the subtraction of the starting address of the application space, and the first addressable flash address of the microcontroller.
/************************* Miscellaneous Configuration ************************/
/*!< Uncomment the following line if you need to relocate your vector Table in
Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
/******************************************************************************/
Make sure you understand what is expected from the micro side using STM documentation before programming things. Vector tables in this chip can only be in multiples of 0x200. But to answer your question, this address can be determined by a few things. Your memory map, and eventually, you will have a hard-coded reference to it as a define. You can figure it out from there.
Hope this helps and good luck to you on your application.

Set printer driver specific data

We have an application that prints 2 invoice copies - 1 on white (for the cust) and 1 on blue (for us).
We print a LOT of these so we are getting a printer with 3 big trays. One tray (tray 5) holds 4000 sheets and the other two (trays 3 and 4) are a tandem set holding 1600 and 2000 sheets. The application automatically generates the invoice and sends one document to the tray with the white paper and one to the tray with the blue paper.
The user has no input in this process.
Now, my problem is this - if I specifically send the blue copy to tray 3 and there is no paper in tray 3, the job will go on hold until someone loads it up even though tray 4 has 2000 more sheets ready to go. On the other hand, if I tell the printer to print on Blue 8 1/2x11" paper, it is smart enough to know that that type of paper is in both trays and to pull from either one until they are both empty. So, I want to change our application to select a paper type/size and color instead of a specific tray.
The program is written in Delphi and I have been looking at the DEVMODE structure returned by TPrinter.GetPrinter. The DEVMODE structure has a memory size in dmDriverExtra that indicates how much extra data the print driver is adding to the structure for its own storage.
Does anyone know of anyway to access this data and make changes to it? If you have examples in other languages, I can probably adapt it to Delphi so anything will help.
There are actually two different items in the questions:
How to set the pater size and type:
PaperSize would be stored in dmPaperSize (value DMPAPER_LETTER)
PaperType is a bit more difficult. I'd guess that it's in dmMediaType (use DeviceCapabilities to retrieve available media types and their names)
How to access / edit "DriverExtra" data:
In short: don't!
A bit longer: dmDriverExtra is described as "Contains the number of bytes of private driver-data that follow this structure". So this data is private to the driver (which means that you need very good documentation for the driver to actually know the format and content of this data. It's not guaranteed that different versions of the driver use the same format).
So the only thing you can do is to use a print dialog, retrieve the DevMode structure and store it for further use (however as I said: If the driver changes, this data may become invalid...)

Resources